[PYTHON] How to install Cascade detector and how to use it

This time, I would like to introduce how to install the Cascade detector used for face detection.

Execution environment

MacOS, Python3.6(anaconda), VSCode

Cascade detector installation procedure

① 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)

Impressions of implementing

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.

How to surround your face with a square

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 **.

Summary

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

How to install Cascade detector and how to use it
How to install and use Tesseract-OCR
How to install and use Graphviz
How to install and use pandas_datareader [Python]
How to use Decorator in Django and how to make it
How to use .bash_profile and .bashrc
How to install CUDA and nvidia-driver
python: How to use locals () and globals ()
How to use Python zip and enumerate
How to use is and == in Python
How to use pandas Timestamp and date_range
How to install fabric and basic usage
How to install OpenCV on Cloud9 and run it in Python
How to use xml.etree.ElementTree
How to use Python-shell
How to use lists, tuples, dictionaries, and sets
How to use tf.data
How to use virtualenv
How to use image-match
How to use shogun
Introducing Sinatra-style frameworks and how to use them
How to install Python
How to use Pandas 2
How to install pip
How to use Virtualenv
How to use numpy.vectorize
How to install archlinux
How to use pytest_report_header
How to install python
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to install BayesOpt
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use venv
How to use dictionary {}
[Python] How to use hash function and tuple.
How to use Pyenv
How to use list []
How to use python-kabusapi
How to install Nbextensions
How to use OptParse
How to use return
How to install Prover9
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
How to install Fast.ai on Alibaba Cloud GPU and run it on Jupyter notebook
[Python] [Django] How to use ChoiceField and how to add options
Beginners! Basic Linux commands and how to use them!
How to install Git GUI and Gitk on CentOS
How to use the grep command and frequent samples
Julia Quick Note [01] How to use variables and constants
How to use argparse and the difference between optparse