Search code examples
pythonopencv

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


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?


Solution

  • Windows will treat OBS Virtual Camera as if it were a regular camera. The integer argument for cv2.VideoCapture is the index of the camera. Thus, you can simply increment that number repeatedly until the program uses the OBS Virtual Camera.