Python. Simple image Face Detection using OpenCV
I'm noobe in OpenCV and looking for simple python face detecting script. I've find one here http://suksant.com/2013/04/03/simple-face-detection-using-opencv/
But there is no rect. on face when script stops.
#!/usr/bin/python
import cv2
img = cv2.imread("Lenna.png")
hc = cv2.CascadeClassifier("haarcascade_frontalface_alt2.xml")
faces = hc.detectMultiScale(img)
for face in faces:
cv2.rectangle(img, (face[0], face[1]), (face[0] + face[2], face[0] + face[3]), (255, 0, 0), 3)
cv2.imshow("Lenna's face", img)
if cv2.waitKey(5000) == 27:
cv2.destroyWindow("Lenna's face")
cv2.imwrite("LennaFace.png", img)
That should be
cv2.rectangle(img, (face[0], face[1]), (face[0] + face[2], face[1] + face[3]), (255, 0, 0), 3)
-- notface[0] + face[3]
face[0] + face[3]
at line 8 should beface[1] + face[3]
. It also makes sense to iterate over tuples of(x, y, w, h)
and set points to(x, y)
and(x + w, y + h)
.