[Memorandum] A story about trying OpenCV tutorial (face recognition) in a Windows environment

There is a consultation about whether you can search the full text of the drawing in the search system consultation. I tried an OpenCV tutorial to verify the realization accuracy.

The following is a memorandum of procedure I took

** Premise ** OS:   Windows10 64bit

Python:  Python3.7(Anaconda3)

Target From building an OpenCV environment to conducting a simple tutorial (I want to do face recognition for the time being)

Preparation

Installation of anaconda

https://www.anaconda.com/products/individual

image.png

Download OpenCV whl

https://opencv.org/releases/

・ Click RELEASES from the tab above. · OpenCV – Click Sources in 4.2.0 -Unzip the zip and take out opencv_python- 4.2.0-cp37-cp37m-win_amd64.whl

Create an OpenCV environment in the Anaconda navigator

image.png

image.png

Install numpy and matplotlib

conda install numpy
pip install matplotlib

image.png

★ Articles referred to so far Articles referred to when building the foundation https://qiita.com/FukuharaYohei/items/5d49938ffd33d198f0c0

Articles referred to for countermeasures against Cascade Classifier errors http://sh0122.hatenadiary.jp/entry/2017/10/30/210411

tutorial

I'll try it on a trial basis, so I'll try face recognition first. Once you understand the basics, all you have to do is customize the basics.

Get cascading files

It is an xml file that has already learned the features required for classification and recognition. This time, "haarcascade_frontalface_default.xml" is used for face recognition. https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_default.xml

Photo used for face recognition

The photo used this time is my own photo that was cutely processed with SNOW. Can you recognize this ...? image.png

Write the python code Write the following process with the name test.py

import cv2

#Classifier
cascadeFile = "C:\imagepy\haarcascade_frontalface_default.xml"

#Classifier settings
cascade = cv2.CascadeClassifier(cascadeFile)

#Input file
imageImput ="C:\imagepy\myface.jpg "

#Read input file
image = cv2.imread(imageImput)

#Make it grayscale
imageGray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

#Output file
imageOutput = "C:\imagepy\out.jpg "

#Recognize face
facerect = cascade.detectMultiScale(imageGray, scaleFactor=1.1, minNeighbors=2, minSize=(30, 30))

#Processing when a face can be detected
if len(facerect) > 0:

    #Put a frame on the face
    for rect in facerect:
        cv2.rectangle(image, tuple(rect[0:2]),tuple(rect[0:2]+rect[2:4]), (255, 255, 255), thickness=2)

    #Save the result as an image
    cv2.imwrite(imageOutput, image)

Try running test.py

image.png

It seems that even my own photo processed cutely with SNOW is recognized as a face

image.png

We have completed the tutorial, which is our goal. Next time, I would like to recognize the symbols and objects on the drawing and make full-text search possible.

I can't test with the drawings used at work, so I wonder if I should aim for a state where full-text search is possible by recognizing the symbols in the map. .. ..

Recommended Posts

[Memorandum] A story about trying OpenCV tutorial (face recognition) in a Windows environment
A story about how Windows 10 users created an environment to use OpenCV3 with Python 3.5
A story about trying to implement a private variable in Python.
A story about trying to run JavaScripthon on Windows and giving up.
A story about building an IDE environment with WinPython on an old Windows OS.
Escape from Python's virtual environment ~ A story about being trapped in a virtual environment I created ~
Think about building a Python 3 environment in a Mac environment
A story about trying to introduce Linter in the middle of a Python (Flask) project
A story about making 3D space recognition with Python
A story about trying a (Golang +) Python monorepo with Bazel
A story about reflecting Discord activity in Slack Status
A story about a Linux beginner passing LPIC101 in a week
A story about a Linux beginner putting Linux on a Windows tablet
A memorandum about matplotlib
A memorandum about Nan.
virtualenvwrapper in windows environment
A story about PHP that was okay in the development environment but buggy in the production environment LEVEL 1-3 + 1
[Note] A story about trying to override a class method with two underscores in Python 3 series.
A story about trying to use cron on a Raspberry Pi and getting stuck in space
[Django] A story about getting stuck in a swamp trying to validate a zip with form [TDD]
I tried the super-resolution algorithm "PULSE" in a Windows environment
A story about how to specify a relative path in python.
A story about competing with a friend in Othello AI Preparation
A story that stumbled when using pip in a proxy environment
A note on touching Microsoft's face recognition API in Python
A story about a tragedy happening by exchanging commands in chat
Face recognition with Python's OpenCV
Collaborate in a remote environment
A memorandum about correlation [Python]
A memorandum about Python mock
Face recognition / cutting with OpenCV
A story about trying to automate a chot when cooking for yourself
How about Anaconda for building a machine learning environment in Python?
A story about a build error in a shared library that references libusb
A story about trying to run multiple python versions (Mac edition)
A story about trying to improve the testing process of a system written in C language for 20 years