This time, I would like to introduce how to install the Cascade detector used for face detection.
MacOS, Python3.6(anaconda), VSCode
① Select the required Cascade file in Github repository ② Open the file and click on Raw ③ On the opened screen, right-click and save it in your favorite location.
This is the procedure.
Here is the article that I referred to this time. Face detection and pupil detection with Python, OpenCV (face recognition, pupil recognition)
xml_path_list = ["./haarcascade_frontalface_default.xml",
"./haarcascade_frontalface_alt.xml",
"./haarcascade_frontalface_alt_tree.xml",
"./haarcascade_frontalface_alt2.xml"]
This time, I thought I would use these four, but I used the remaining three because the file size of ** "./haarcascade_frontalface_alt_tree.xml" ** was too large to install.
I think that default was the most accurate. I had the impression that alt sometimes recognized extra parts that were not faces, and that alt2 sometimes did not recognize even though it was a face.
This time, I made a square around the place where the face was detected, so I will also describe how to do it.
if len(face_points) == 0:
quit()
for x, y, width, height in face_points: #Get the coordinate points of the face area
color = (0, 0, 100)
pen_w = 9
cv2.rectangle(img, (x, y), (x+width, y+height), color, thickness = pen_w)
cv2.imwrite('mosaic' + str(mosaic_num) + str(cnt) + '.jpg', img) #Save image
First, use the if statement to determine if the face can be detected with ** detectMultiScale **. If not, it ends there.
And the code enclosed in a square is in the for statement. Specify what kind of line to enclose with ** cv2.rectangle **.
This time, I explained how to install Cascade detector. It's convenient because it automatically detects it without you having to write the face detection code yourself. I also used this for the first implementation.
In addition, we could implement it by enclosing it in a square. This is convenient because you can judge at a glance whether the face can be detected properly. I found it fun because I could see the result of the image processing as soon as I executed it.
Recommended Posts