我是Python opencv的新手。任何人都可以請幫我理清錯誤通過Python中的程序捕獲圖像時出錯
import cv
cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 1
capture = cv.CaptureFromCAM(camera_index)
def repeat():
global capture #declare as globals since we are assigning to them now global camera_index
frame = cv.QueryFrame(capture)
cv.ShowImage("w1", frame)
c = cv.WaitKey(100)
if(c=="n"): #in "n" key is pressed while the popup window is in focus
camera_index += 1 #try the next camera index
capture = cv.CaptureFromCAM(camera_index)
if not capture: #if the next camera index didn't work, reset to 0.
camera_index =1
capture = cv.CaptureFromCAM(camera_index)
while True:
repeat()
這是我得到的錯誤 -
OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat, file /home/paraste/OpenCV-2.3.1/modules/core/src/array.cpp, line 2382
Traceback (most recent call last):
File "dualcamara.py", line 10, in <module>
img = cv.GetMat(cv.QueryFrame(capture), 500)
cv2.error: NULL array pointer is passed
你好,謝謝你的回覆。 CaptureFromCAM函數返回一些十六進制值,但QueryFrame函數不返回任何值。我認爲相機不是這樣的,我用奶酪命令手動切換它,但返回值沒有變化。請讓我知道如何使用內置功能打開相機。即使我嘗試使用函數cv2.VideoCapture.open ,但它以下列錯誤結束:AttributeError:'builtin_function_or_method'對象沒有屬性'打開' – parastenitk22f