Face Detection using Haar - OpenCV python -


i trying python code snippet:

import numpy np import cv2  face_cascade = cv2.cascadeclassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2.cascadeclassifier('haarcascade_eye.xml')  img = cv2.imread('img.jpg') gray = cv2.cvtcolor(img, cv2.color_bgr2gray)  faces = face_cascade.detectmultiscale(gray, 1.3, 3) (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)     (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() 

but error:

traceback (most recent call last):   file "test.py", line 14, in <module>     roi_color = img[y:y+h, x:x+w] typeerror: 'nonetype' object has no attribute '__getitem__' 

i found program here.

if sure image path right , still problem persist try doing this:

from line

img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)  

remove img =, let

cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) 

this worked me.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -