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 /
avatar image
0
Question by marcoprof · Feb 15, 2021 at 11:06 AM · webcamtexture

two webcams into a single rawimage side-by-side,How to have two webcams in the same rawimage side by side

Hello. I've been able to capture streams of different webcams simultaneously using the code found here https://github.com/Chamuth/unity-webcam/blob/master/MobileCam.cs and simply creating two rawimages, each one with attached a similar script. However I would need to have the two streams in just a single rawimage, side-by-side, for 3D purposes. I was thinking to copy the two rawimages in one but I don't think this is efficient and, beside, I'm new to Unity so not sure how to do it. Any suggestion?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by highpockets · Feb 13, 2021 at 05:27 PM

Why can’t the WCTs be in 2 raw images right next to each other??


If you really need them to be displayed as one raw image, I think you will have to create that single texture2D at runtime every frame, but this seems like a very strange use case. Anyhow, this is untested, but I think more or less what you are trying to do:

 Texture2D texture;
 
 WebCamTexture wctOne;
 WebCamTexture wctTwo;
 
 RawImage rawCamImage;
 
 void Start()
 {
     rawCamImage = GetComponent<RawImage>();
     wctOne = new WebCamTexture( WebCamTexture.devices[0].name, Screen.width / 2, Screen.height, 30 );
     wctTwo = new WebCamTexture( WebCamTexture.devices[1].name, Screen.width / 2, Screen.height, 30 );
     StartCoroutine( StartCams() );
 }
 IEnumerator StartCams()
 {
     wctOne.Play();
     wctTwo.Play();


     while( wctOne.width < 100 || wctTwo.width < 100 )
                 yield return null;
 
     texture = new Texture2D( wctOne.width + wctTwo.width, wctOne.height, TextureFormat.RGB24, false );

     rawCamImage.texture = texture;
     rawCamImage.material.mainTexture = texture;
    
     while(true)
     {
         texture.SetPixels(0,0,wctOne.width,wctOne.height,wctOne.GetPixels());
         texture.SetPixels(wctOne.width,0,wctTwo.width,wctTwo.height,wctTwo.GetPixels());
         texture.Apply();
        
         yield return null;
     }
 }

 
Comment
Add comment · Show 11 · Share
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
avatar image marcoprof · Feb 18, 2021 at 04:46 PM 0
Share

@highpockets Thank you: I will give it a try. I need the two side by side to be rendered in a single rawimage in order to exploit a Leia component that will automatically handle it to show it 3D in their 3D screens (Lume Pad for example). Normally any side-by-side image in their texture2D becomes 3D

avatar image marcoprof · Feb 18, 2021 at 07:17 PM 0
Share

Anyway there is something wrong (even if you comment the part about the second cam to get a single webcam working, the rawImage is empty)

avatar image highpockets marcoprof · Feb 18, 2021 at 09:23 PM 0
Share

I forgot to call Play().. Sorry, it was untested. I'll edit my code above

avatar image marcoprof highpockets · Feb 19, 2021 at 11:17 AM 0
Share

Just tested on a tablet (so there are for sure two cameras) but apparently it is not working. Even commenting the part for the second camera and testing on my pc (that has just one camera) I see the led of the camera on, but the rawImage is empty. I have tried to do as I had made in the past (assigning directly the webcam texture to the rawImage texture) and in this case of course it works. I don't know if I could have made errors since I have never used coroutines: in fact I have packed your code inside a C# script with some additional instructions to assign the rawImage and check the number of available cameras, the code I'm testing now is like that: (and attached to the rawImage, where I have also assigned the public property):

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class RenderOnRawImage : MonoBehaviour { Texture2D texture;

 WebCamTexture wctOne;
 WebCamTexture wctTwo;
 public int numofcameras;

 public RawImage rawCamImage;

 void Start()
 {
     
     WebCamDevice[] devices = WebCamTexture.devices;
     numofcameras = devices.Length;
     GameObject.Find("Label1").GetComponentInChildren<Text>().text = "Number of cameras " + numofcameras;
     wctOne = new WebCamTexture(WebCamTexture.devices[0].name, Screen.width/2, Screen.height);
     wctTwo = new WebCamTexture(WebCamTexture.devices[1].name, Screen.width / 2, Screen.height, 30);
     
     StartCoroutine(StartCams());
     
 }
 IEnumerator StartCams()
 {
     wctOne.Play();
     wctTwo.Play();
     while (wctOne.width < 100 || wctTwo.width < 100)
         yield return null;

     texture = new Texture2D(wctOne.width + wctTwo.width, wctOne.height, TextureFormat.RGB24, false);
     rawCamImage.texture = texture;
     rawCamImage.material.mainTexture = texture;

     while (true)
     {
         texture.SetPixels(0, 0, wctOne.width, wctOne.height, wctOne.GetPixels());
         texture.SetPixels(wctOne.width, 0, wctTwo.width, wctTwo.height, wctTwo.GetPixels());

         yield return null;
     }
 }

}

Show more comments

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

111 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

Related Questions

how to check if webcam is used by another application 0 Answers

WebCamTexture does not stop 2 Answers

WebCamTexture problem 1 Answer

How do I properly use Unity's WebCamTexture? IOS 2 Answers

How can I have the background for the main camera in a scene display the feed from a web cam/camera on a phone? 1 Answer


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