How could I connect the webcam?
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.
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:
- Declare a
WebCamTexture
field (nearby the originally declaredVideoPlayer
):
private WebCamTexture webcamTexture;
- In the
SetupInput()
function start the camera:
webcamTexture = new WebCamTexture();
webcamTexture.Play();
- In the
ExecuteML()
function blit thewebcamTexture
instead of thevideo.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.