我正在运行以下代码,以便同时在我正在从事的项目的MacBook Air上运行两个Logitech网络摄像头。这是我创建的程序:
import cv2
import numpy as np
import math
cams_test = 500
for i in range(0, cams_test):
cap = cv2.VideoCapture(i)
test, frame = cap.read()
if test:
print("i : "+str(i)+" /// result: "+str(test))
capL = cv2.VideoCapture(0)
capR = cv2.VideoCapture(1)
##capM = cv2.VideoCapture(2)
if not capL.isOpened():
print("Cannot open camera L")
exit()
if not capR.isOpened():
print("Cannot open camera R")
exit()
##if not capM.isOpened():
## print("Cannot open camera R")
## exit()
while True:
# Capture frame-by-frame
retL, frameL = capL.read()
retR, frameR = capR.read()
##retM, frameM = capM.read()
# if frame is read correctly ret is True
if not retL:
print("Can't receive frame L (stream end?). Exiting ...")
break
if not retR:
print("Can't receive frame R (stream end?). Exiting ...")
break
##if not retM:
## print("Can't receive frame M (stream end?). Exiting ...")
## break
# Our operations on the frame come here
grayL = cv2.cvtColor(frameL, cv2.COLOR_BGR2GRAY)
grayR = cv2.cvtColor(frameR, cv2.COLOR_BGR2GRAY)
##grayM = cv2.cvtColor(frameM, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frameL', grayL)
cv2.imshow('frameR', grayR)
##cv2.imshow('frameM', grayM)
if cv2.waitKey(1) == ord('q'):
break
if cv2.waitKey(1) == ord('c'):
cv2.imwrite('L.png',grayL)
cv2.imwrite('R.png',grayR)
##cv2.imwrite('M.png',grayM)
break
# When everything done, release the capture
capL.release()
capR.release()
##capM.release()
cv2.destroyAllWindows()
我包括了“ cams_test”部分,因为我试图解决计算机无法同时显示两个网络摄像头的问题。 下面是程序的输出:
i : 0 /// result: True
OpenCV: out device of bound (0-2): 3
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 4
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 5
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 6
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 7
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 8
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 9
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 10
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 11
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 12
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 13
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 14
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 15
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 16
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 17
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 18
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 19
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 20
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 21
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 22
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 23
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 24
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 25
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 26
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 27
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 28
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 29
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 30
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 31
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 32
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 33
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 34
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 35
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 36
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 37
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 38
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 39
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 40
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 41
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 42
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 43
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 44
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 45
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 46
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 47
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 48
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 49
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 50
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 51
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 52
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 53
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 54
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 55
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 56
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 57
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 58
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 59
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 60
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 61
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 62
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 63
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 64
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 65
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 66
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 67
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 68
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 69
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 70
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 71
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 72
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 73
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 74
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 75
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 76
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 77
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 78
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 79
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 80
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 81
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 82
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 83
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 84
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 85
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 86
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 87
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 88
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 89
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 90
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 91
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 92
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 93
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 94
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 95
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 96
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 97
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 98
OpenCV: camera failed to properly initialize!
OpenCV: out device of bound (0-2): 99
OpenCV: camera failed to properly initialize!
我环顾了stackoverflow和其他论坛,但找不到任何可以帮助我解决此问题的东西。而且,我还没有看到有人遇到此错误。我将不胜感激任何帮助。谢谢。