下午好,我现在有一些代码,可以使用haar cascades检测眼睛和脸部,我很好奇是否有人知道如何让程序识别头部的运动,例如。点头或移动眼睛,例如眨眼
以下是我目前拥有的:
import cv2
import numpy as np
"""
Created on Mon Mar 2 11:38:49 2020
@author: bradl
"""
# Open Camera
camera = cv2.VideoCapture(0)
camera.set(10, 200)
face_cascade = cv2.CascadeClassifier('haarcascades/face.xml')
##smile = cv2.CascadeClassifier('haarcascades/smile.xml')
eye_cascade = cv2.CascadeClassifier('haarcascades/eye.xml')
while True:
ret, img = camera.read()
## converts to gray
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
## determines what a face is and how it is found
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
## Determines the starting and ending co-ordinates for a blue rectangle to be drawn around the face
cv2.rectangle (img, (x,y), (x+w, y+h), (255,0,0), 2)
## Declares the region of the image where the eyes will be
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
## Determines what an eye is based on the eye haar cascade xml file
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eyes:
##Draws green rectangles around the co-ordintates for eyes
cv2.rectangle(roi_color, (ex, ey),(ex+ew,ey+eh), (0,255,0),2)
##Displays camera
cv2.imshow('Image',img)
##Requires the user to press escape to exit the program
k = cv2.waitKey(40)
if k == 27:
break
有人有什么想法让程序识别头部或眼球运动吗
检测眨眼的方法有很多种
另一种方法是使用像DLIB这样的库进行人脸地标检测
相关问题 更多 >
编程相关推荐