Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by sondow97 · Jun 01 at 09:18 PM · webcamtexturecapturephoto

How do you take multiple photos using Webcamtexture and rotate it to show it as smartphone rotation?

Hi, good evening.

I was trying to make an app to take 5 photos with a counter for Android. But it closes by itself without errors taking a photo. And it shows the camera tilted 90º. I tried use this that I found on the documentation, but it doesn't work

 transform.rotation = baseRotation * Quaternion.AngleAxis(webcamTexture.videoRotationAngle, Vector3.up);

It would be like this for my code, but it doesn't work

 imageObj.rotation = baseRotation * Quaternion.AngleAxis(webcamTexture.videoRotationAngle, Vector3.up);

I'm not understanding how the webcam works, it freezes and then tries to take another one, but it freezes and closes, but there's a saved photo.

I have this code:

 public class MultiShot : MonoBehaviour
 {
     public Button SwitchBtn;
     public Button CaptureBtn;
     public Dropdown CounterDpd;
     public Text CounterTxt;
     private float seconds = 3;
     private float counter = 3;
     private bool started = false;
     private bool[] counters = {false,false,false,false, false};
     private int cCounter = 0;
     public GameObject imageObj;
     private WebCamTexture webcamTexture;
     private WebCamDevice[] devices;
     private Resolution[] resolutions;
     private int device = 0;
     private System.DateTime now;
     private string capName = "Photo";
 
     IEnumerator Start()
     {
         yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
         if (Application.HasUserAuthorization(UserAuthorization.WebCam))
         {
             devices = WebCamTexture.devices;
             SwitchBtn.onClick.AddListener(SwitchCamera);
             CaptureBtn.onClick.AddListener(CaptureCamera);
             resolutions = devices[device].availableResolutions;
             webcamTexture = new WebCamTexture(devices[device].name, resolutions[0].width, resolutions[0].height, resolutions[0].refreshRate);
             webcamTexture.Play();
             imageObj.GetComponent<RawImage>().texture = webcamTexture;
         }
         else
         {
             Application.Quit();
         }
     }
     void SwitchCamera()
     {
         if ((device+1) < devices.Length)
         {
             device++;
         }
         else
         {
             device = 0;
         }
         webcamTexture.Stop();
         webcamTexture = new WebCamTexture(devices[device].name, resolutions[0].width, resolutions[0].height, resolutions[0].refreshRate);
         if (webcamTexture != null)
         {
             webcamTexture.Play();
             imageObj.GetComponent<RawImage>().texture = webcamTexture;
         }
     }
     void CaptureCamera()
     {
         switch(CounterDpd.value)
         {
             case 0:
                 seconds = 3;
                 break;
             case 1:
                 seconds = 5;
                 break;
             case 2:
                 seconds = 10;
                 break;
             case 3:
                 seconds = 15;
                 break;
         }
         started = true;
         cCounter = 0;
         counters[cCounter] = true;
         counter = seconds;
         CounterTxt.gameObject.SetActive(true);
         CounterTxt.text = Mathf.RoundToInt(counter).ToString();
         now = System.DateTime.Now;
     }
 IEnumerator TakeSnapshot(string name)
     {
         yield return new WaitForEndOfFrame();
 
         Texture2D snap = new Texture2D(webcamTexture.width, webcamTexture.height);
         snap.SetPixels(webcamTexture.GetPixels());
         snap.Apply();
         string date = now.Year.ToString() + now.Day.ToString() + now.Month.ToString() + now.Hour.ToString() + now.Minute.ToString() + now.Second.ToString();
         captured[cCounter] = Application.persistentDataPath + "/" + name + cCounter.ToString() + date + ".png";
         File.WriteAllBytes(captured[cCounter], snap.EncodeToPNG());
         }
     }
     void Update()
     {
         if(started && cCounter < counters.Length && counters[cCounter])
         {
             if (counter > 0f)
             {
                 counter -= Time.deltaTime;
                 CounterTxt.text = Mathf.RoundToInt(counter).ToString();
             }
             else
             {
                 counters[cCounter] = false;
                 StartCoroutine(TakeSnapshot(capName));
                 cCounter++;
                 if (cCounter < counters.Length)
                 {
                     counters[cCounter] = true;
                     counter = seconds;
                     CounterTxt.text = Mathf.RoundToInt(counter).ToString();
                 }
                 else
                 {
                     started = false;
                     CounterTxt.gameObject.SetActive(false);
                 }
             }
         }
     }
 }

I tried using void instead IEnumerator, and make it wait 2 seconds, if webcamtexture is playing, but it doesn't work. Have a nice day

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

185 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Microsoft HoloLens Emulator - Callback for PhotoCapture.CreateAsync not being called 1 Answer

Flag capture with spawning and destroying gameObject 0 Answers

How to Mirror Flip Raw Image? 0 Answers

How to change some pixels in webcamtexture in real time? 0 Answers

Screen recorder that supports microphone input 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges