[PYTHON] Check the operation of OpenCV3 installed by Anaconda

Operation check, before that

There is no haarcascades file! Since it may cause an error, I think it is a good idea to create a haarcascades directory in the same hierarchy as the py file and copy the entire cascade file.

haarcascade_eye.xml haarcascade_frontalface_default.xml

It works even if you pick up two of them and copy them.

checkcv.py


import cv2

face_cascade = cv2.CascadeClassifier('./haarcascades/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('./haarcascades/haarcascade_eye.xml')


img = cv2.imread('./images/img.jpg')
gray_scale = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray_scale)
for (x,y,w,h) in faces:
    cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    r_gray = gray_scale[y:y+h, x:x+w]
    r_color = img[y:y+h, x:x+w]
    eyes = eye_cascade.detectMultiScale(r_gray)
    for (ex,ey,ew,eh) in eyes:
        cv2.rectangle(r_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

cv2.imshow('img',img)


cv2.waitKey(0)

Execution result

スクリーンショット 2017-07-04 15.53.18.jpg

I have to study more.

Recommended Posts

Check the operation of OpenCV3 installed by Anaconda
Optical Flow, the dynamics of images captured by OpenCV
[Python] Check the installed libraries
Check the operation of Python for .NET in each environment
List of packages installed by conda
The first artificial intelligence. How to check the version of Tensorflow installed.
I want to check the position of my face with OpenCV!
Check the behavior of destructor in Python
I checked the options of copyMakeBorder of OpenCV
How to check the version of Django
Check the existence of the file with python
[OpenCV] About the array returned by imread
The result of installing python in Anaconda
Check the path of the Python imported module
Pandas of the beginner, by the beginner, for the beginner [Python]
[python] Check the elements of the list all, any
Check the type of the variable you are using
Sort the elements of the array by specifying the conditions
[2020July] Check the UDID of the iPad on Linux
Check the date of the flag duty with Python
Minimize the number of polishings by combinatorial optimization
Judging the finish of mahjong by combinatorial optimization
Code for checking the operation of Python Matplotlib
Search by the value of the instance in the list
I tried using the image filter of OpenCV
Check the status of your data using pandas_profiling
[Python + OpenCV] Whiten the transparent part of the image
Broadcast operation by raising the dimension with np.newaxis
Installation of Anaconda3
Solved the problem that MacVim installed by Homebrew was not built by python of pyenv
The avi file output by OpenCV cannot be played
Easy way to check the source of Python modules
A story that reduces the effort of operation / maintenance
Gradually display the output of the command executed by subprocess.Popen
The story of Hash Sum mismatch caused by gcrypto20
Get the image of "Suzu Hirose" by Google image search.
○○ Solving problems in the Department of Mathematics by optimization
I compared the identity of the images by Hu moment
[Statistics] Understand the mechanism of Q-Q plot by animation.
Find out the location of packages installed with pip
How to check the Java version used by Maven
Check for the existence of BigQuery tables in Java
Get the operation status of JR West with Python
Visualize the appreciation status of art works with OpenCV
Personal notes about the integration of vscode and anaconda
Play music by hitting the unofficial API of Google Play Music
Check the type and version of your Linux distribution
Check the asymptotic nature of the probability distribution in Python
The copy method of pandas.DataFrame is deep copy by default
How to check if the contents of the dictionary are the same in Python by hash value