[英]Open CV Python Face Detection
I am looking it to using haar cascades for face detection, so I tried following the tutorial here: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_objdetect/py_face_detection/py_face_detection.html 我正在寻找使用haar级联进行人脸检测,所以我尝试按照这里的教程: http : //opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_objdetect/py_face_detection/py_face_detection.html
When I run it though, the image window populates, but the rectangles are not drawn. 当我运行它时,图像窗口会填充,但不会绘制矩形。 I checked over the code and everything makes sense to me or if maybe I was using a function that was obsolete, but everything seemed alright.
我检查了代码,一切对我来说都是有意义的,或者我是否正在使用一个过时的功能,但一切似乎都没问题。
I am not sure why I cannot get this working. 我不知道为什么我不能让这个工作。 Any suggestions as to what might be wrong?
有什么可能是错的建议吗? I am using Python 2.7.3.
我使用的是Python 2.7.3。
import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
img = cv2.imread('searchin2.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
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()
I try to run this script and I got faces: 0
too. 我尝试运行这个脚本,我得到了
faces: 0
也是。
So I try to find out where is the problem. 所以我试着找出问题所在。
I found out that I have no XML files on my disk. 我发现我的磁盘上没有XML文件。
There is no info in tutorials that you have to download it seperately and where to get this files. 教程中没有信息你必须单独下载它以及从哪里获取这些文件。
But I downloaded OpenCV source code ZIP file, I found haarcascade_frontalface_default.xml
in this file and I put it directly in folder with script. 但是我下载了OpenCV源代码 ZIP文件,我在这个文件中找到了
haarcascade_frontalface_default.xml
,我把它直接放在带脚本的文件夹中。 Now I have faces: 2
:) 现在我有
faces: 2
:)
But now I have also error: 但现在我也有错误:
cv2.Rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
AttributeError: 'module' object has no attribute 'Rectangle'
I'm still working on it. 我还在努力。
EDIT: It has to be lowercase - rectangle
:) Now it works for me :) 编辑:它必须是小写 -
rectangle
:)现在它适用于我:)
oryginal image source: wikimedia ? 原始图像来源: 维基媒体?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.