How could I connect the webcam?

#15
by srsrgio - opened

I'd like to connect the webcam to process its feed. I've tried to process images rather than a video and it worked, but I struggle with the connection of the webcam, I'm not that familiar with Unity or Sentis.

Unity Technologies org

Hello srsrgio.

If you want to process input from the camera instead of processing a video clip, you can achieve this by making the following minimal changes to the provided script:

  1. Declare a WebCamTexture field (nearby the originally declared VideoPlayer):
private WebCamTexture webcamTexture;
  1. In the SetupInput() function start the camera:
webcamTexture = new WebCamTexture();
webcamTexture.Play();
  1. In the ExecuteML() function blit the webcamTexture instead of the video.texture:
Graphics.Blit(webcamTexture, targetRT, new Vector2(1f / aspect, 1), new Vector2(0, 0));

Now when you start the game the camera input should appear instead of the previously displayed video clip (assuming that Unity has sufficient permissions set in the operating system to access the camera).

Your need to confirm your account before you can post a new comment.

Sign up or log in to comment