Ihsan Ahmed K
Ihsan Ahmed K

Reputation: 159

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?

Upvotes: 1

Views: 10947

Answers (2)

Seth
Seth

Reputation: 2369

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.

Upvotes: 4

Ghost
Ghost

Reputation: 1523

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

Upvotes: 4

Related Questions