I'm trying with the code from link below to blur faces in images:
How to use opencv (python) to blur faces?
image = cv2.imread('45.jpg')
result_image = image.copy()
# Specify the trained cascade classifier
face_cascade_name = "C:/Users/User/Desktop/haarcascade_frontalface_alt.xml"
# Create a cascade classifier
face_cascade = cv2.CascadeClassifier()
# Load the specified classifier
face_cascade.load(face_cascade_name)
#Preprocess the image
grayimg = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
grayimg = cv2.equalizeHist(grayimg)
#Run the classifiers
faces = face_cascade.detectMultiScale(grayimg, 1.1, 2, 0|cv2.cv.CV_HAAR_SCALE_IMAGE, (30, 30))
print ("Faces detected")
But i got a Traceback error as follows. Please help. Thanks.
Traceback (most recent call last):
File "<ipython-input-70-d20c79f10494>", line 15, in <module>
grayimg = cv2.equalizeHist(grayimg)
error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\imgproc\src\histogram.cpp:3334: error: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::equalizeHist'
You need to convert to grey:
COLOR_BGR2GRAY
the error is telling you that your image is not an 8-bit grayscale image
change this line:
grayimg = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
to
grayimg = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
In the linked question you can see that the OP had used that for conversion
Regarding your latest error see related: Attribute error while using opencv for face recognition
basically it's moved to:
cv2.CASCADE_SCALE_IMAGE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With