简体   繁体   English

Python OpenCV 人脸检测

[英]Python OpenCV face detection

How can I check for the location of an eye for example.例如,我如何检查眼睛的位置。

Its in this function?它在这个功能?

eyes = eye_cascade.detectMultiScale(gray, 1.4, 7)眼睛 = eye_cascade.detectMultiScale(gray, 1.4, 7)

How to read the input of this?如何读取this的输入?

i would like to calculate in a face detection program if on the picture for example a nose or an eye is the place as should be, in a human.我想在人脸检测程序中计算图片上的鼻子或眼睛是否应该是人类的位置。

OpenCV-Python Tutorials's documentation has a good example for face detection. OpenCV-Python 教程的文档有一个很好的人脸检测示例。

import numpy as np
import cv2

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

img = cv2.imread('sachin.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
    img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
    eyes = eye_cascade.detectMultiScale(roi_gray)
    for (ex,ey,ew,eh) in eyes:
        cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM