import cv2
cam = cv2.VideoCapture(0)
s, img = cam.read()
winName = "Movement Indicator"
cv2.namedWindow(winName, cv2.CV_WINDOW_AUTOSIZE)
while s:
cv2.imshow( winName,img )
s, img = cam.read()
hc = cv2.CascadeClassifier("foo.xml") #xml file for detection
faces = hc.detectMultiScale(img)
for face in faces:
cv2.rectangle(
img, (face[0], face[1]), (face[0] + face[2], face[0] + face[3]),
(255, 0, 0), 3
)
key = cv2.waitKey(10)
if key == 27:
cv2.destroyWindow(winName)
break
答案 0 :(得分:0)
文档在这里:http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html
您可以尝试两种简单的方法来加速检测(两者都以较低的准确性为代价):
答案 1 :(得分:0)
那真的是你的所有代码吗? iirc,它只适用于灰度
尝试交易速度以获得准确性,并使用lbpcascade而不是haar one
cv2.imwrite(“myface.png”,img [face [1]:face [1] + face [3],face [0]:face [0] + face [2]]);应该保存面对roi