【问题标题】:How to recognize head movement in open CV?如何识别openCV中的头部运动?
【发布时间】:2020-06-16 23:05:21
【问题描述】:

下午好,我目前有一些使用 haar 级联检测眼睛和面部的代码,我很想知道是否有人知道如何让程序识别头部的运动。点头或眼睛的运动,例如眨。

这是我目前拥有的:

   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

有没有人有任何想法让程序识别头部或眼球运动?

【问题讨论】:

  • 嗨,代码可以完美地检测面部和眼睛,我只是在努力思考如何添加运动功能,例如如果您眨眼,程序可以检测到它,并可能在屏幕上打印“检测到眨眼”字样
  • 头部向上、向下或任何运动的光流。

标签: python opencv spyder haar-classifier


【解决方案1】:

有多种方法可以检测眨眼。

  • 在眼睛的 ROI 中应用白色检测。
  • 在此蒙版周围绘制轮廓,如果轮廓区域高于阈值,您可以解释眼睛是睁开的,只要轮廓区域发生突然变化,即眨眼点。 如果您靠近或远离相机,此方法将失败。

另一种方法是使用 DLIB 之类的库进行面部特征检测。

【讨论】:

  • 我有这个,但它不能正常工作,它说眼睛总是闭着?如果眼睛 == (255,255,255): cv2.putText(img,"眼睛睁开", (50,50), cv2.FONT_HERSHEY_SIMPLEX, 2, 2) 否则: cv2.putText(img,"眼睛闭上", (50,50 ), cv2.FONT_HERSHEY_SIMPLEX, 2, 2)
  • eyes==(255,255,255) 将不起作用。您需要先执行阈值处理。之后,您需要绘制轮廓,然后计算轮廓的面积。如果该区域高于阈值,则表示眼睛是睁着的,否则是闭着的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-06
  • 2013-06-23
相关资源
最近更新 更多