【发布时间】:2017-03-19 22:23:35
【问题描述】:
import cv2
import sys
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=2.0,
minNeighbors=5,A minSize=(30, 30),
flags = 0
#flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
# Write frame in file
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imwrite('only_face.jpg')
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
上面的代码是从相机的实时馈送中检测人脸并只保存一张人脸的图像。我想保存从提要中检测到的多个面孔的图像。它只保存一张脸的图像
【问题讨论】:
-
您应该包含一个 for 循环以在每次保存新图像时增加图像
-
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S3') dtype('S3') dtype('S3') 它显示了这个错误
标签: python opencv face-detection