How do I input OBS virtual cam in my python code using opencv?

Question:

I am trying to write a code for detecting the color green from a live video. I want to make a detector so that whenever the color green pops up in the screen, a counter starts counting how many times the color appears.

So for the video source, I am using the OBS Virtual Camera. But I have no idea how to input it as the source. I have seen codes inputting web cams as the source as shown below:

import numpy as np 
import cv2 
  
  
# Capturing video through webcam 
webcam = cv2.VideoCapture(0) 

Anyone have any idea how I can input the OBS virtual cam? Or does anyone know any alternative like switching to another language to do said task?

Asked By: Ihsan Ahmed K

||

Answers:

Windows will treat OBS Virtual Camera as a regular camera. The argument for cv2.VideoCapture is camera number. So up that number by 1 over and over again until the program uses the OBS Virtual Camera. And there you go.

Answered By: Seth

Keep in mind that there is a bug currently reported that opencv is not parsing the stream from OBS virtual cam and just showing a black background.

https://github.com/obsproject/obs-studio/issues/3635

Answered By: Ghost
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.