Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take photo using webcam is giving black output[Unity3D]

Tags:

c#

unity3d

I used the code given by @Bart in the Stackoverflow question Can I take a photo in Unity using the device's camera? with some modification. But the result is coming out to be a completely black photo.

I would like to add that the script is attached to a cube which has a renderer. Also renderer was deprecated hence I had to use GetComponents() for the same.

like image 820
Keymaker Avatar asked Dec 03 '15 07:12

Keymaker


People also ask

How do I turn off my WebCam in unity?

You have to explicitly call WebCamTexture. Stop (); to stop it. The right place to do this is in the Disable() function.

How do I change the camera in unity?

We first start by deciding on the condition we use to change the camera. For now we'll use Input buttons 1, 2 and 3 to switch between cameras. We go into Project Settings -> Input Manager and add three new items to the list, which we'll label Switch1, Switch2, and Switch3. Each correspond to the button on the keyboard.

What is main camera in unity?

Whatever kind of experience you're developing, the Main Camera is always the primary stereo rendering component attached to your device's head-mounted display. It'll be easier to lay out your app if you imagine the starting position of the user as (X: 0, Y: 0, Z: 0).


1 Answers

I would think at the moment you take the shot, the rendering is not done since rendering happens late in the frame.

You should most likely use a coroutine and wait for the end of the frame

yield return new WaitForEndOfFrame();

or use the callback OnPostRender from the camera that is rendering the process.

like image 90
Everts Avatar answered Sep 29 '22 08:09

Everts