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).

Hi Alex, thanks for such a quick reply.

I've tried what you mentioned, as you can see in my code, but I get a screen view rather than the webcam view, as if I was screen recording rather than getting the feed from my webcam, even so, the small led next to my webcam turns on...

I couldn't attach the whole code so I uploaded to drive: https://drive.google.com/file/d/1o4iwqOXz7gjKVjeCUtHMxok5qTkyEHu5/view?usp=sharing

Thanks in advance.

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

Sign up or log in to comment