I am trying to build a face detection application in python using opencv.
Please see below for my code snippets:
# Loading the Haar Cascade Classifier
c
From your error understand that you are trying to read the shape
. But shape is the attribute of numpy.ndarray
. You are trying to read the shape from the result of face detection. But that will only return the position only. Look at the types. Here img
is an image and faces
is the result of face detection. I hope you got the problem.
Updated with full code. For more clarification
In [1]: import cv2
In [2]: cap = cv2.VideoCapture(0)
In [3]: ret,img = cap.read()
In [4]: cascadePath = "/home/bikz05/Desktop/SNA_work/opencv-2.4.9/data/haarcascades/haarcascade_frontalface_default.xml"
In [5]: faceCascade = cv2.CascadeClassifier(cascadePath)
In [6]: faces = faceCascade.detectMultiScale(img)
In [7]: type(img)
Out[1]: numpy.ndarray
In [8]: type(faces)
Out[2]: tuple
Look at the diffrence.
In [9]: img.shape
Out[3]: (480, 640, 3)
In [10]: faces.shape
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
----> 1 faces.shape
AttributeError: 'tuple' object has no attribute 'shape'
If you want the number of faces. It's in the form of list of tuple. You can find the number of faces using len
like len(faces)