Python face recognition self-service fruit shop based on OpenCV (source code & deployment video)

Python face recognition self-service fruit shop based on OpenCV (source code & deployment video & 4D technical documentation)

1. Module function introduction

Realize face recognition module, face login and registration functions, store display and user balance page display functions

Use GUl graphical interface to realize (pyqt) language python windows software pycharm
1. User login module: face login
2. Registration module: take photos, capture and align uploaded face information, record and edit the user’s balance and number
3. After successful login, Enter the store page
4. When the user enters the store, there is a balance and store product prices
. Registration and entry: face capture and alignment (opencv+dlib):
use opencv or dlib to detect and capture the face of the video. and enter the number and balance.

2. Video demonstration

[Project sharing] Face recognition self-service store based on OpenCV (source code & deployment video)_哔哩哔哩_bilibili

3. Effect display

3.png
2.png

3.png

4. Installation of third-party packages

To install opencv, enter: pip install opencv-python.

Note: numpy and OpenCV are bound and installed, no need to enter the command yourself.

To install pillow, enter: pip install pillow

Note: pillow is an image processing package.

For contrib installation, enter: pip instal opencv-contrib-python

5. The principle of OpenCV face recognition:

You might be wondering how this tutorial is different from the one I wrote about face recognition with dlib a few months ago?
Well, keep in mind that the dlib face recognition post depends on two important external libraries:
(1) dlib (obviously)
(2) face_recognition (which is an easy-to-use set of face recognition utilities included with dlib)
though We use OpenCV for face recognition, but OpenCV itself is not responsible for recognizing faces.
In today's tutorial, we will learn how to apply deep learning with OpenCV (no other library except scikit-learn):
(1) detect faces
(2) compute 128-dimensional face embeddings to quantify faces
(3 ) Training a Support Vector Machine (SVM) on top of the embeddings
(4) Recognizing faces in images and video streams
All these tasks will be done by OpenCV, allowing us to get a "pure" OpenCV face recognition pipeline.
To build our OpenCV face recognition pipeline, we will apply deep learning in two key steps:

Applying face detection, which detects the presence and location of a face in an image, but does not recognize it,
extracts a 128-dimensional feature vector (called an "embedding") that quantifies each face in the image.
I have discussed before that OpenCV's face detection is How it works, so if you haven't detected faces before, please refer to:
5.png

6. Realization of face and name recognition code:

import numpy as np
import cv2

# 人脸识别分类器
faceCascade = cv2.CascadeClassifier(r'C:\python3.7\Lib\site-packages\cv2\data\haarcascade_frontalface_default.xml')

# 识别眼睛的分类器
eyeCascade = cv2.CascadeClassifier(r'C:\python3.7\Lib\site-packages\cv2\data\haarcascade_eye.xml')

# 开启摄像头
cap = cv2.VideoCapture(0)
ok = True

while ok:
    # 读取摄像头中的图像,ok为是否读取成功的判断参数
    ok, img = cap.read()
    # 转换成灰度图像
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # 人脸检测
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.2,
        minNeighbors=5,
        minSize=(32, 32)
    )

    # 在检测人脸的基础上检测眼睛
    for (x, y, w, h) in faces:
        fac_gray = gray[y: (y+h), x: (x+w)]
        result = []
        eyes = eyeCascade.detectMultiScale(fac_gray, 1.3, 2)

        # 眼睛坐标的换算,将相对位置换成绝对位置
        for (ex, ey, ew, eh) in eyes:
            result.append((x+ex, y+ey, ew, eh))

    # 画矩形
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)

    for (ex, ey, ew, eh) in result:
        cv2.rectangle(img, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2)

    cv2.imshow('video', img)

    k = cv2.waitKey(1)
    if k == 27:    # press 'ESC' to quit
        break

cap.release()
cv2.destroyAllWindows()

7. Relevant research on facial recognition shopping:

Technical principle: facial feature template recognition

Alipay's face recognition technology adopts the regional feature analysis algorithm widely used in this field, which integrates computer image processing technology and biostatistics principles, uses computer image processing technology to extract portrait feature points from videos, and uses biostatistics Based on the principle of analysis, a mathematical model is established, that is, the face feature template. Using the completed face feature template and the face image of the subject to perform feature analysis, a similarity value is given according to the analysis result. This value can be used to determine whether it is the same person.

To put it more technically, the technical principle shown in the materials provided by Alibaba is: all aspects of face recognition in this system are based on deep neural network technology (CNN), through face detection, key point positioning, feature extraction and feature comparison Peer-to-peer technical means, discovering from images or videos, locating a face and then identifying the identity of the person to whom the face belongs.

It is said that the system has processed a total of 1 billion face image data.

Alipay face recognition operation process:

Face photos are uploaded by users to the Alipay system, after system analysis and authentication, they are then "bound" to their payment accounts. For each payment, after placing an order and purchasing, let the payment system scan the user's face and confirm the identity, and the payment can be completed.

Why choose face payment instead of fingerprint recognition, which is more widely used now? The answer given by Alipay is that because the operation method is contactless, it is more conducive to dispelling users' concerns about personal privacy than payment such as fingerprints.

Future application: No need to carry cash and bank cards, you can pay with your face within 1 second after passing through the cash register

Ma Yun's "face-swiping payment" has brought a new revolution to the payment method of future life. According to the prospect of Alibaba's application of this technology, with the face-scanning payment system, people do not need to carry cash and bank cards, and do not need to memorize various passwords or Account, the user only needs to take photos with the front camera of the mobile phone and upload them to the multi-core processing system to complete the registration. The system extracts facial features and processes them to successfully register. When shopping offline, users only need to walk to the cash register to realize face recognition and complete payment within 1 second.

In fact, similar facial recognition technology is not uncommon in global technology research and development. Last year, a Finnish company called Uniqul started the practical application of "face recognition payment" in Helsinki, and charged different prices for the use of services according to the service coverage area. The Biometrics and Security Technology Research Center of the Chinese Academy of Sciences is also researching payment methods based on face recognition. In fact, this recognition technology has been used in the 2008 Beijing Olympic Games.

8. Complete source code & environment deployment video tutorial & custom UI interface & operation guide & 4D technical documentation:

Python face recognition self-service fruit shop based on OpenCV (source code & deployment video) (mianbaoduo.com)

9. Integration of the complete project:

The above model has been trained, but for us, its function is to know that its accuracy is not bad. In fact, the most important purpose of deep learning is application. It is time to use the above model to do some custom parts, background image You can choose by yourself, avoiding the appearance of the Internet celebrity UI interface (avoiding the collision of shirts when framing). Can you use the above model to identify the emotions you express? It is better to make a system to call the camera to recognize the expressions in the real-time screen and display the recognition results. It can not only visually detect the practical performance of the model, but also make the whole project lively and interesting to stimulate your own creativity. When you introduce your project to others It also looks tall. Here we use PyQt5 for design, first look at the final renderings, the complete project is as follows:
1.png

10. References

**1.[Journal Papers]** Design and Implementation of Face Recognition System Based on CNN and SVM

Journal: "Computer and Digital Engineering" | Issue 002, 2021

**Abstract:**Aiming at the problems of posture changes, expressions, and occlusions in face recognition in practical applications, the convolutional neural network (CNN) face recognition algorithm combined with support vector machine (SVM) classification is studied, designed and implemented. A face recognition system was developed. The system first uses CNN to extract face feature vectors, and then classifies the feature vectors through SVM. The test results show that the system is effective in face posture changes, expressions, occlusions, etc. when the training samples are sufficient. Good performance, the recognition rate is above 95%, which can meet the general face recognition needs.

**Keywords:** face recognition; convolutional neural network; support vector machine; deep learning


**2.[Journal Papers]** Implementation of Video Surveillance Face Recognition System Based on Python Language

Journal: "Integrated Circuit Applications" | Issue 001, 2021

**Abstract:**Based on calling the face recognition interface to realize the identification function, it has the characteristics of easy use and high recognition rate. It expounds the calling method of Baidu and Questyle face recognition interface, and uses the Python language to test and verify, so as to achieve better results. practical value.

**Keywords:** face recognition; interface; liveness detection; Python


**3.[Journal Papers]** Effect of Image Noise Reduction and Enhancement on the Recognition Performance of Face Recognition System

Journal: Criminal Technology | Issue 001, 2021

**Abstract: **Objective To study the influence of image noise reduction and image enhancement methods on the recognition performance of face recognition system, in order to provide theoretical guidance and technical solutions for the selection of image processing methods in the application process of face recognition system. Methods Collect 33 portraits Identify face image materials in actual cases in the field, study the effect of image noise reduction technology represented by Gaussian filter and wavelet transform, and single-frame image super-resolution enhancement technology with edge preservation and wavelet transform characteristics on the recognition performance of face recognition system The effects of different image processing methods on the performance of face recognition were quantitatively compared and analyzed. Results The image denoising technology studied in this paper has significantly improved the recognition accuracy of the face recognition system, while the image enhancement technology has improved the recognition accuracy of the face recognition system. image display effect, but it has no positive effect on the recognition performance of the face recognition system. In addition, although the image noise reduction method of Gaussian blur image processing is simple, compared with other methods studied in this paper, it has no positive effect on the recognition performance of the face recognition system. The effect of improvement is the most significant. Conclusion The face image quality has a significant impact on the recognition performance of the face recognition system, and image processing technology can be used to improve the face image quality and then improve the recognition accuracy of the face recognition system. Among them, image noise reduction processing It can significantly improve the recognition performance of the face recognition system, and is more suitable for the recognition performance enhancement of the face recognition system in the actual portrait identification application than the image enhancement technology.

**Keywords:** portrait identification; face recognition; image noise reduction; image enhancement; face recognition system


**4.[Journal Papers]**RGB-D anti-counterfeiting face recognition system design

Journal: "Digital Technology and Application" | Issue 002, 2021

**Abstract:** In order to solve the common defects of face recognition technology based on ordinary visible light images, such as weak ability to resist counterfeit face attacks such as photos and videos, and unsatisfactory lighting (such as weak light, side strong light) ), the resulting RGB image quality is poor, the recognition object does not match, and the recognition posture is not ideal, so this project designs an RGB-D anti-counterfeit face recognition system based on this, and the system data is based on the RGB-D face recognition of the depth map , and use the cloud server for data processing, which can solve the problem of recognition failure caused by insufficient lighting conditions, and has better recognition accuracy.

**Keywords:**RGB-D; anti-counterfeiting; face recognition


**5.[Journal Papers]**Design and Implementation of Java-Based Library Face Recognition System

Journal: "Technology Innovation and Application" | Issue 007, 2021

**Abstract:** This article proposes a 24-bit face recognition method based on color images. The main part of image processing occupies a very important position in the software, and image quality directly affects position determination and recognition accuracy. Through backlight compensation, Gaussian Smooth and binary discrimination. Before the discrimination, the image is processed through complementary light, and then the rough face is obtained through the skin color. Finally, the face is judged according to the symmetry of the inherent eyes of the face, which improves the positioning and discrimination accuracy. Finally, the system is applied With the library face recognition, and have a good effect

**Keywords:**Java; MySQL; face recognition system


Guess you like

Origin blog.csdn.net/cheng2333333/article/details/126695369