Items with no label
3335 Discussions

SR300 camera video in Unity

MMoha17
Novice
2,298 Views

Hi,

I would like to view the SR300 video in my GUI while using gesture in the camera preview. In other words, when the user is using the SR300 to control something via a GUI, I would like to add the video of themselves in the GUI so that they can see themselves in the GUI. I think a plane can be added and a script can be added to that plane to show the video as shown in the attachment below. However, I have tried to input a script in but it is too complicated and has errors. May I know if there are simpler ways to get camera video attached to the GUI?

Thank you.

0 Kudos
12 Replies
idata
Employee
684 Views

Hi Supermomo90,

 

 

Thank you for contacting us.

 

 

To be honest, I don't have experience with Unity, but I'll investigate more about it, and I'll let you when we have updates.

 

 

Have a nice day.

 

 

Regards,

 

Leonardo R.
0 Kudos
MMoha17
Novice
684 Views

Hi Leonardo,

Thanks for the reply.

0 Kudos
MartyG
Honored Contributor III
684 Views

The instruction for putting a webcam feed on the surface of an object in Unity is WebCamTexture

0 Kudos
MMoha17
Novice
684 Views

Hi MartyG,

This script uses an external webcam or the video stream from the SR300 directly?

Thank you.

0 Kudos
MartyG
Honored Contributor III
684 Views

You can specify which webcam (or 'device') is used to provide the feed - either your SR300 or another cam.

I knew that I'd used WebCamTexture on a previous project. I used to keep detailed step by step making-of diaries of my projects, and managed to locate in my archives the diary entry relating to this function. I found a link in that diary to the Unity documentation for the Play sub-function of WebCamTexture. Place the code on ths page inside a script within the object that you want to display the webcam feed on the surface of.

https://docs.unity3d.com/ScriptReference/WebCamTexture.Play.html Unity - Scripting API: WebCamTexture.Play

0 Kudos
MMoha17
Novice
684 Views

Hi MartyG,

I created an Image object from the UI section and then assigned the script to that object as you mentioned, however, there seems to be no image formed.

Thank you.

0 Kudos
MartyG
Honored Contributor III
684 Views

This link suggests using RawImage instead of Image in your script for displaying the webcam on a UI component.

http://answers.unity3d.com/questions/909967/getting-a-web-cam-to-play-on-ui-texture-image.html Getting A Web Cam to Play on UI Texture Image - Unity Answers

0 Kudos
MMoha17
Novice
684 Views

Hi MartyG,

I am getting a black screen with the settings shown below.

Thank you.

0 Kudos
MartyG
Honored Contributor III
684 Views

I experimented with the script in my own project and managed to get it working. Here's what I did.

STEP ONE

Add this line to the header of your script. It tells Unity how to handle a UI RawImage.

using UnityEngine.UI;

STEP TWO

If you look at the picture in that linked article that had the script, it shows a component called a RawImage being used to display the webcam feed, instead of the usual Image component.

Go to the object with your webcam feed script in and remove the Image component (as you can only have one image-related component in a UI object, Unity says if you try to add a RawImage whilst an Image component is already there).

Then add a RawImage component with Component > UI > Raw Image

STEP THREE

Go to your webcam feed script in the Inspector and look for the option called 'Rawimage'. Left-click on the little icon next to it to bring up the image selector, and select 'Image', which should be the only one in the list, so you can't miss it.

STEP FOUR

Run your program. The webcam feed should now display on the UI.

0 Kudos
MMoha17
Novice
684 Views

Hi MartyG,

It works. Thank you very much. However, how do I make unity receive the video from the SR300 instead?

Thank you.

0 Kudos
MartyG
Honored Contributor III
684 Views

This script allows you to change between cameras by clicking an on-screen button. It doesn't look like it would be difficult to adapt it for your script.

http://answers.unity3d.com/questions/821409/switch-device-camera.html Switch device camera. - Unity Answers

0 Kudos
MMoha17
Novice
684 Views

Hi MartyG,

Thank you very much.

0 Kudos
Reply