Struggling to get usb webcam to display what it sees on OpenCV

My built in camera for my Windows computer doesn’t work. So I bought an Emeet webcam that is plugged in to the usb port of my computer. The webcam itself works in the camera app and on zoom, however, when I try to display it in OpenCV, it just gives me a black screen, which is the same as my built in camera since that doesn’t work. Here is my code:

import numpy as np
import cv2

video_capture_0 = cv2.VideoCapture(0, cv2.CAP_DSHOW)
#the line below is for my usb webcam
video_capture_1 = cv2.VideoCapture(2, cv2.CAP_DSHOW)

while True:
    # Capture frame-by-frame
    ret0, frame0 = video_capture_0.read()
    ret1, frame1 = video_capture_1.read()

    if (ret0):
        # Display the resulting frame
        cv2.imshow('Cam 0', frame0)

    if (ret1):
        # Display the resulting frame
        cv2.imshow('Cam 1', frame1)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture_0.release()
video_capture_1.release()
cv2.destroyAllWindows()

Both windows open up (one for my built in camera and the other for my usb webcam) but both show black screens. For my built in camera, that is expected since it doesn’t work, but I would expect my usb webcam to actually show an image. Any suggestions on why the usb webcam doesn’t work in opencv?

get ffmpeg

then enumerate device modes

Thanks for your response!

I installed ffmpeg and put it in my paths on my system environment variables:


However, I’m still getting an error when I type “ffmpeg -version” in command prompt:
‘ffmpeg’ is not recognized as an internal or external command,
operable program or batch file.

How should I resolve this?

just open a prompt in that directory. don’t mess with environment variables for now. I could tell you how environment variables propagate through the process tree (they don’t) but that won’t help.