Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

windows - Second camera not detected by opencv in python

I have 2 identical ELP USB 3.0 cameras. I'm trying to get both working with opencv/python on Windows 10, but only one of the connected cameras ever returns an image. Specifically, using code like the following:

cam = cv2.VideoCapture(1)

while True:
    ret, img = cam.read()
    if not ret:
        print('Capture failed')
        break
    cv2.imshow('test', img)
    k = cv2.waitKey(1)
    if k == ord('k'):
        break
    
cam.release()

only shows a video if I use 1 in cv2.VideoCapture(1). Looping through different camera numbers (0-500) and printing the return value of a camera.read() only shows True on camera number 1. In other words, opencv does not seem to see the second camera at all. I tested the cameras individually using the Windows "Camera" program, and can successfully swap between the two cameras there, so both work. Also, I've tested the cameras previously on a different Linux machine, and they also both worked with opencv (though not simultaneously, which is a totally different issue) as cameras 0 and 1. Does anyone know what might be wrong?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...