识别视频人脸

import cv2
# cap = cv2.VideoCapture(0)#打开内置摄像头
cap=cv2.VideoCapture("C:\\Users\\Administrator\\Desktop\\1.mp4")
# Create the haar cascade
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
while(True):
	# Capture frame-by-frame
	ret, frame = cap.read()
    if ret==True:
		# Our operations on the frame come here
		gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
	
		# Detect faces in the image
		faces = faceCascade.detectMultiScale(
			gray,
			scaleFactor=1.1,
			minNeighbors=5,
			minSize=(30, 30),
			flags=cv2.CASCADE_SCALE_IMAGE
		)
	
		print("Found {0} faces!".format(len(faces)))
	
		# 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('facesFound', frame)
		if cv2.waitKey(1) & 0xFF == ord('q'):
			break
        # When everything done, release the capture
   else:
      break
cap.release()
cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/liaoqingjian/article/details/108648320
今日推荐