current position:Home>Python has been hidden for ten years, and once image recognition is heard all over the world

Python has been hidden for ten years, and once image recognition is heard all over the world

2022-01-30 16:49:51 Java architects Alliance



Face processing is a hot topic in artificial intelligence , Face processing can automatically extract a large amount of information from the face using computer vision algorithms , For example, identity 、 Intention and emotion . Face plays an important role in visual communication , This is because the face contains a lot of nonverbal information , Therefore, face processing has always been a very interesting topic for computer vision learners , Because it involves different professional fields , For example, object detection 、 Feature point detection and object tracking . In this paper , We will first introduce the common face processing libraries , Then it explains how to use these databases for face detection , Lay a foundation for further related processing .\


Introduction to face processing

In order to focus on face processing related topics , We will use OpenCV library , as well as dlib、face_recognition and cvlib etc. Python package . meanwhile , This paper will use different methods in face processing , To introduce different methods to solve specific face processing tasks , The introduction of different methods will help you choose different methods according to different application needs . The following figure shows the related topics of face processing , And the available Python package :\


As shown in the figure above , Face processing mainly includes the following topics :

Face detection : A special case of object detection , Its task is to find the position and size of all faces in the image . Facial feature point detection : A special case of feature point detection , Its task is to locate the main feature points in the face . Face tracking : A special case of object tracking , Its task is to use the additional information extracted in the continuous frames of the video , Find the location and size of all moving faces in the video . Face recognition : A special case of target recognition , Its task is to recognize or verify a person from an image or video using the information extracted from the face : Face recognition (1:N): Find the closest match to the detected face in the known face set, face verification (1:1): Check whether the detected face is the person it claims, as described above , Face processing mainly includes : Face detection 、 Facial feature point detection 、 Face tracking and Face recognition , And in the daily recognition process , Use the most OpenCV、dlib、face_recognition and cvlib Database for face detection , And today we'll talk about opencv Application , This is also the simplest way , Because many algorithm modules have been encapsulated

Other face processing topics will be introduced in a subsequent series .

Okay , Don't talk much , On the subject


setup script


First step : install opencv modular

use pip When the management tool installs library files , Default to use foreign source files , Therefore, the download speed in China will be relatively slow , Maybe it's just 50KB/s. fortunately , Some top scientific research institutions in China have prepared various images for us , Download up to 2MB/s

Can be used in pip When , Add parameters -i Image and address ( Such as,

for example :

pip install -i opencv-contrib-python

After installation , The following content will appear in your installation path \


These are the opencv Its own algorithm model , Can be called directly

The following is the code implementation of the call

Start with the simple , First recognize the face in the picture \

# opencvimport cv2
face_detector = cv2.CascadeClassifier('./haarcascade_frontalface_alt.xml')
img = cv2.imread('./image.jpeg')
face_zones = face_detector.detectMultiScale(img)
for x,y,w,h in face_zones:,center=(x+w//2,y+h//2),radius=w//2,color=[0,0,255],thickness=2)
 Copy code 


Execution results , Just change the address of the picture

When the picture is linked , What is formed is the recognition effect of video \

Code up \

''' Turn on the camera '''

import numpy as np
import cv2

face_detector = cv2.CascadeClassifier('./haarcascade_frontalface_alt.xml')
video = cv2.VideoCapture(0)# Turn on the camera 
while True:
    flag,frame =
    if flag == False:
    gray = cv2.cvtColor(frame,code = cv2.COLOR_BGR2GRAY)
    face_zones = face_detector.detectMultiScale(gray)
    for x,y,w,h in face_zones:,center = (x+w//2,y+h//2),radius = w//2,color = [0,0,255],thickness = 2)
    key = cv2.waitKey(41)
    if key == ord('q'):# Exit conditions 
 Copy code 

Much of this is a dead cycle , Continuously update the obtained picture information in a circular way , Finally, integrate , Is the content of a video


And the acquisition of test images , You can see the crawler tutorial I wrote to you before , Code directly , Can pay attention to :Java After the alliance of architects , The background to reply 【 Reptiles 】 Get oh

copyright notice
author[Java architects Alliance],Please bring the original link to reprint, thank you.

Random recommended