preface
Face processing is a hot topic in artificial intelligence. It can use computer vision algorithms to automatically extract large amounts of information from a face, such as identity, intention and emotion. Face plays an important role in visual communication because it contains a lot of non-verbal information, so face processing has always been a very interesting topic for computer vision learners, because it involves different professional fields, such as object detection, feature point detection and object tracking. In this paper, will first introduce the common face processing library, and then through the actual combat to explain how to use these libraries for face detection, for further related processing to lay the foundation. \
Introduction to Face Processing
To focus on the topic of face processing, we will use the OpenCV library, as well as Python packages such as Dlib, face_recognition, and cvlib. At the same time, this article will use different methods in face processing, in order 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 Python packages available: \
As shown in the figure above, face processing mainly includes the following topics:
Face detection: A special case of object detection whose task is to find the positions and sizes of all faces in an image. Facial feature point detection: A special case of feature point detection whose task is to locate the main feature points in a human face. Face tracking: A special case of object tracking in which the task is to find the positions and sizes of all moving faces in the video using additional information extracted from successive frames of the video. Face recognition: A special case of target recognition, whose task is to identify or verify a person from an image or video using information extracted from a face: Face recognition (1:N) : Find the closest match to the detected face in the known set of faces face verification (1:1) : Check whether the detected face is the person it claims to be, as mentioned above, face processing mainly includes: Face detection, facial feature point detection, face tracking and face recognition, and in the daily recognition process, the use of the most OpenCV, Dlib, FACE_recognition and CVlib libraries for face detection, and today we will explain the application of OpenCV, This is also the easiest way to do it, because there are so many algorithm modules encapsulated in it
Other face processing topics will be covered in subsequent series.
All right, let’s cut to the chase
The installation process
Step 1: Install the OpencV module
When using PIP management tool to install library files, the default is to use foreign source files, so the download speed in China will be slow, maybe only 50KB/s. Fortunately, some of the top domestic scientific research institutions have prepared a variety of images for us, the download speed can reach 2MB/s
PIP can be used with the -i parameter and the mirror address (e.g
Pypi.tuna.tsinghua.edu.cn/simple),
Such as:
pip install -i pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python
After the installation is complete, the following contents \ will appear in your installation path
These are opencV own algorithm model, can be directly called
Here is the code implementation of the call
Let’s start with something simple: 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: Cv2. Circle (img, center = (x + w / / 2, y + h / / 2), the radius = w / / 2, color =,0,255 [0], thickness = 2) cv2, imshow (' face 'img) cv2.waitKey(0)cv2.destroyAllWindows()Copy the code
Execute the result, just need to change the address of the picture
When the picture linkage, the formation is the video recognition effect \
The code \
Import numpy as NP import Cv2 face_Detector = cv2.CascadeClassifier('./ haarCascade_frontalface_alt.xml ') Video = cv2.videocapture (0)# Open camera while True: flag,frame = video.read() if flag == False: break gray = cv2.cvtColor(frame,code = cv2.COLOR_BGR2GRAY) face_zones = face_detector.detectMultiScale(gray) for x,y,w,h in face_zones: Circle (frame,center = (x+w//2,y+h//2),radius = w//2,color = [0,0,255],thickness = 2) cv2.imshow(' TTNK ',frame) key = Cv2.waitkey (41) if key == ord('q'):# break cv2.DestroyallWindows () video.release()Copy the code
Much of this is to carry out an endless loop, constantly update the picture information obtained, and finally integrate, is the content of a video
And test picture acquisition, we can see before I give you to write the crawler tutorial, direct code, you can pay attention to: Java architect alliance, background reply [crawler] get oh