This block of code (in views.py) is triggered by a URL.No problem in importing cv2.(Same thing tried with virtualenvwrapper shows same result (after adding all required libraries) Camera initializes and ....
def caminit(request):
cam.open(0)
img=cam.read()
cv2.imwrite("snap"+".jpg",img[1])
cam.release() #takes the instant pic
faceCascade =cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
When checked for print type(faceCascade)
gives <type 'cv2.CascadeClassifier'>
.The object is created.
moving on further in same caminit
image = cv2.imread("snap.jpg")
# when checked with image.dtype it shows correct uint8 also image.shape shows correct data {Eg: (480, 640, 3)}
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in the image
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
now THE crucial part "Finding the no. of faces"
print "Found {0} faces!".format(len(faces))
OUTPUT in TERMINAL:
Found 0 faces!
Why is this happening?
I have tried debugging by printing in terminal.I have mentioned them in comments.Camera being used is My laptop (HP envy) camera which gives snap with resolution 640x480.
I suspect something needs to be tweaked in faceCascade.detectMultiScale(..)
block.(The parameters).I tried with scalefactor = 1.000001
and minNeighbors = 3
to no avail.
cv2.CascadeClassifier
cannot find the requested xml file, it will return an emptycv2.CascadeClassifier
object. To test if you cascade classifier is correctly loaded, can you try printingfaceCascade.empty()
? – Roband