我試圖在ubuntu上使用opencv python在網絡攝像頭中檢測臉部。我得到了這個在線代碼,並試圖運行這個程序,我得到了作爲NULL數組指針通過,我想它不能捕捉攝像頭的視頻,但具有相同的代碼(只有捕獲相機)我拿到了相機,它捕獲了視頻。這裏是我的代碼:return _cv.cvHaarDetectObjects(* args)
import cv
from opencv import highgui
HAAR_CASCADE_PATH = "/home/OpenCV-2.3.1/data/haarcascades/haarcascade_frontalface_default.xml"
CAMERA_INDEX = 0
def detect_faces(image):
faces = []
detected = cv.HaarDetectObjects(image, cascade, storage, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING, (100,100))
if detected:
for (x,y,w,h),n in detected:
faces.append((x,y,w,h))
return faces
if __name__ == "__main__":
cv.NamedWindow("Video", cv.CV_WINDOW_AUTOSIZE)
capture = cv.CaptureFromCAM(0)
storage = cv.CreateMemStorage()
cascade = cv.Load(HAAR_CASCADE_PATH)
print cascade
faces = []
i = 0
c = -1
while (c == -1):
image = cv.QueryFrame(capture)
# Only run the Detection algorithm every 5 frames to improve performance
#if i%5==0:
faces = detect_faces(image)
#print image
for (x,y,w,h) in faces:
cv.Rectangle(image, (x,y), (x+w,y+h), 255)
cv.ShowImage("w1", image)
i += 1
而且我得到的錯誤是:
Traceback (most recent call last):
File "/home/OpenCV-2.3.1/webcam_try.py", line 38, in <module>
faces = detect_faces(frame)
File "/home/OpenCV-2.3.1/webcam_try.py", line 13, in detect_faces
detected = cv.cvHaarDetectObjects(frame, cascade, storage, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING,(100,100))
File "/usr/lib/pymodules/python2.7/opencv/cv.py", line 1626, in cvHaarDetectObjects
return _cv.cvHaarDetectObjects(*args)
NotImplementedError: Wrong number of arguments for overloaded function 'cvHaarDetectObjects'.
Possible C/C++ prototypes are:
cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *,double,int,int,CvSize)
cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *,double,int,int)
cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *,double,int)
cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *,double)
cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *)
非常感謝,它不適用於我的系統。錯誤如下:函數cvGetMat中無法識別或不支持的數組類型。在安裝opencv2.4.3之前,我想知道,它是否適用於Ubuntu 11.10系統和Python 2.7。因爲我在使用opencv2.3.1時遇到了很多問題,所以只想確認一下。謝謝。 – shreya
嗨,我已經升級到Opencv-2.4.3。運行代碼後,它給我一個錯誤,如下所示:Traceback(最近一次調用最後一次): 文件「/home/vidula/OpenCV-2.3.1/draft_1.py」,第25行,在 flags = cv。 CV_HAAR_DO_CANNY_PRUNING) 錯誤:/home/vidula/OpenCV-2.4.3/modules/core/src/array.cpp:2482:error:(-206)函數cvGetMat中無法識別或不支持的數組類型這是什麼意思? –
shreya
這意味着你傳遞給imshow()的數組有問題。在閱讀我對您的其他問題的回答後再試一次。 –