In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to realize the face recognition unlocking application with raspberry pi code. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
I. Overview of the case
1. Background
Help a friend to achieve a face recognition to unlock the function, used in his real-life game business. Over the past few months, the operation has been stable and the experience is good. Take this time to sort out the implementation process of this application.
Generally speaking, the description of requirements is simple, but because of the many constraints, some efforts have been made in architecture and type selection. two。 Deployment effect because the game is still in online service, the video of the specific operation is not released here. The deployment effect is shown in the following figure:
After players find out and enter the space, they see a real-time picture of themselves in the current scene on the display screen.
When the player takes a closer look, capture the current frame for face recognition, and the watermark subtitle "in authentication" appears in the real-time screen.
When face authentication fails, the watermark subtitle of the real-time screen is changed to "authentication failure", and the subtitle disappears after 2 seconds, and the initial state is restored. Players continue to look for clues to the game and re-authenticate.
When the face authentication is successful, the watermark subtitle of the real-time screen is changed to "authentication successful" and the safe door is popped open. Enter the follow-up game.
Second, product requirements 1. Requirement description
When the requirement is put forward, it is relatively clear, and the core logic is not complex.
Face recognition: authentication through face recognition.
Unlock management: open the box door through authentication, and keep it locked if you fail to pass.
Feedback Tip: real-time video feedback is required with clear guidelines to facilitate the optimization of player experience.
two。 Constraint description
After all, it is a business, so in business, there are high requirements for practicality and cost, the key is not to affect the game process, while ensuring the player experience.
Low cost: low construction cost and low maintenance cost are required.
Easy to maintain: the technical level of maintenance personnel is low, when there is a software and hardware failure, any shop assistant can recover quickly.
High reliability: high recognition accuracy, strong fault tolerance, low failure rate in continuous operation of the system.
Limited space: after removing the display screen, electromagnetic lock and safe, the implementation space of other structures can not exceed the volume of 20cm*15cm*15cm.
Lack of daylighting: small real scene space, top light without side light, long exposure time.
Universal power supply: only 5V and 12V DC interfaces are provided.
Parallel processing: the authentication process and the feedback process are parallel. In the authentication process, the feedback system can not be interrupted, blocked and other conditions, so that players have obvious interruption and stuck experience.
Weak network environment: due to the room partition, network sharing, so the network speed is limited, there is a sudden delay.
3. Function design
There are a variety of possible architectural options (the comparison between different solutions is carried out at the end of the article). Let's explain the solution that will eventually go live.
(1) setting process
For the process and effect, please refer to the previous section of "player experience".
(2) Configurable content
a. Tencent Cloud key pair
Modify the configuration file to adapt to the Tencent Cloud account switching feature (test account / official account).
b. Personnel library ID
Modify the configuration file to specify a different staff library (test library / formal library).
c. Watermark prompt
Change the corresponding picture to replace the watermark. The reason for using picture management instead of text configuration is that the picture configuration mode does not need font support, does not need to configure the display size, and is easy to embed patterns. Because of WYSIWYG, there are low requirements for maintenance personnel.
d. Shutdown option
Can be configured after the completion of the task, whether to automatically shut down. It is used for reset preparation of game environment and reduces reset workload.
(3) Operation and maintenance
a. System operation and management
When the scene starts, power on uniformly. After passing the certification, the machine will be shut down automatically and reset will be completed.
b. Fault handling
Software and hardware failures: unable to boot, bootable without display, bootable display system abnormal, boot unknown anomalies, etc., replace raspberry pie or other hardware. Network failure: normal operation, unable to authenticate, you can check the network + check cloud logs to solve network problems; cloud product exception: run for 4 months, has not occurred, can be ignored, if it occurs, contact cloud after sale
(4) cost analysis
Hardware cost: 500,600 yuan.
Spare parts cost: according to 1:1 spare parts, 50000yuan.
Operating cost: 0 yuan in the cloud, free quota for use; electricity and network charges, ignored.
Second, technical realization 1. System architecture
(1) hardware composition
Raspberry pie: terminal master camera: video input sensor: ultrasonic ranging display: video output relay: control electromagnetic lock: control safe door
(2) key characteristics
Picture recognition: use picture recognition instead of video streams to reduce network bandwidth requirements. Low recognition requirements: underexposed photos also have a high recognition rate. Trigger recognition: the player has been active for a long time in the scene, and the trigger mode avoids high-frequency authentication and mistakenly unlocking the lock, while reducing the authentication cost. Ranging selection: ultrasonic sensor technology is mature, low cost (3 yuan); laser sensor cost is high (30 yuan) multi-process: video processing and monitoring authentication are realized by two processes, avoiding blocking and other situations, while using inter-process communication to achieve reliable interaction.
two。 System building
(1) Tencent Cloud configuration
a. Registered account
Follow the documentation guidelines to obtain the API key
b. Configure face recognition
Visit the console of the official website and establish the authentication foundation through "New personnel Library-> create personnel-> upload photos". The "personnel library ID" used is the key information, which is used to specify the staff library that the authentication action matches when identifying the subsequent API calls. Note: since only one person is identified in this case, there is no need to match the person ID, so there is no need to specify the person ID.
(2) Raspberry pie configuration
a. The installation system accesses http://www.raspberrypi.org to get the image and install it. Note that the desktop version must be installed, otherwise the HDMI output needs to be managed separately.
b. Configure the network to enter the command line, execute "raspi-config", select "Network Options" and configure the WiFi access point. To fix the IP, edit the / etc/dhcpcd.conf file and add configuration information.
# Please refer to your local network planning interface wlan0static ip_address=192.168.0.xx/24static routers=192.168.0.1static domain_name_servers=192.168.0.1 192.168.0.2 for details
c. Install Tencent Cloud SDK
Refer to the guidance document to install the dependent library that calls Tencent Cloud API.
Sudo apt-get install python-pip-ypip install tencentcloud-sdk-python
d. Install image processing library system install python2.7 by default, but there is no opencv library, need to install. (the download package is large, and the default source is a foreign station, which is relatively slow. Raspberry pie to change the domestic origin method, please do your own Baidu, and choose the origin server close to you)
Sudo apt-get install libopencv-dev-ysudo apt-get install python-opencv-y
e. Deployment code
Visit github to get the source code, copy the contents of the src folder to / home/pi/faceid. To change the configuration information in / home/pi/faceid/config.json, you must change your cloud API key (sid/skey) and staff library ID (facegroupid), and adjust other configurations as needed.
f. To configure self-startup, you need to configure the graphical interface to self-start to ensure that the video output is output from the HDMI interface to the display screen, and edit / home/pi/.config/autostart/faceid.desktop to write the following
Type=ApplicationExec=python / home/pi/faceid/main.py (3) hardware wiring
Raspberry pie GPIO icon:
CSI interface
b. Ultrasonic transducer
TrigPin:BCM-24 / GPIO24
EchoPin:BCM-23 / GPIO23
VCC: connect 5V
GND: connect to GND
c. Relay 4 pin side connected to raspberry pie GPIO pin
VCC: connect 5V
GND/RGND: connect to GND
CH1: BCM-12 / GPIO12
3-port side connection electromagnetic lock
The initial state is electromagnetically locked normally closed end.
For the principle of relay, please refer to 3.3.4 hardware related section.
(3) Test run
After completing the above work, power up and start the system, local feedback to view the display screen, cloud identification results can view the system log.
3. Code logic and related technology (1) process pseudo code # Monitoring authentication process-main process acquisition application configuration (API ID/Key, etc.) initialize GPIO pin (prepare control sensor, relay) start video management process (child process) cycle: if not ranging reaches trigger standard: continue communicates with child process (captures the current frame and stores it in the specified path) And add "in authentication" watermark) call cloud API Face recognition using this frame picture if recognition succeeded: communicate with the child process (change the watermark to "authentication successful") wait 5 seconds to shut down or continue to run (specified by the su2halt field in config.json) else: communicate with the child process (change the watermark to "authentication failure") wait 2 seconds to communicate with the child process (remove the watermark) # Video management process-auxiliary Process initialization camera cycle starts: take frames and take the shared queue between processes for different operations (frame image saving / adding different watermarks / not processing) output frames (2) Video and recognition
a. Real-time video, as shown in the pseudo code above, is processed frame by frame and output continuously to display real-time video.
b. Trigger identification
The ranging sensor confirms that the object is close, and the distance change within 0.3 seconds is less than 2cm, which is confirmed as the state to be authenticated. The time delay is 0.3 seconds to capture the image frame. The reason for the delay again is that when the object stops, there will be torsion, fine-tuning and other actions. If the frame is taken directly, it will be blurred due to insufficient daylighting (the constraints mentioned above), so it will be delayed again to ensure that the stable image is captured.
c. Face recognition
Please refer to the document introduction.
(3) Image watermarking
a. Watermarking principle
In opencv, a variety of image processing functions are provided, such as: picture and text processing (graph plus words), graph processing (inter-graph addition / subtraction / multiplication / division / bit operation) and so on. Through different processing methods, we can achieve a variety of effects, such as base image addition, base map addition, mask processing and so on. The mask processing method based on bit operation is used in this case.
b. Watermark picture
In order to facilitate maintenance and update, in this case, the picture is used as the source of the watermark, which avoids font constraints and increases flexibility. It is easy to add graphics to the watermark and define the watermark size directly with resolution. The default watermark image is black on a white background.
c. Watermark processing logic
In order to highlight the floating effect of the watermark, the black area in the watermark image is transparent and superimposed into the original image. Due to the transparent effect of font, the color of watermark font changes with the basic video, and the effect is more obvious. Source code description
# img1 is the current video frame (base image), and img2 is the read watermark image def addpic (img1,img2): # region of interest ROI- takes the rows of the image to be edited by the watermark image, cols = img2.shape [: 2] roi = img1 [: rows,: cols] # picture gray-avoid watermark image non-pure black and white img2gray = cv2.cvtColor (img2, cv2.COLOR_BGR2GRAY) # generate mask-filter light color The bit operation takes non-ret, mask= cv2.threshold (img2gray, 220,255,3) # cv2.THRESH_BINARY mask_inv = cv2.bitwise_not (mask) # to generate the watermark area image-the base map cuts out the font part, generates the final image of the watermark area, and replaces the original watermark area img1_bg = cv2.bitwise_and (roi, roi, mask=mask_inv) dst = cv2.add (img1_bg, img2) img1 [: rows,: cols] = dst return img1
(4) hardware correlation
a. Ultrasonic distance measurement
Ultrasonic sensor (4-pin: VCC, Trig, Echo, GND), Trig output a high level greater than 10 μ s, activate to send out ultrasonic wave, and after receiving the reflected wave, the Echo terminal will output a continuous high level, the duration is the time from "sending wave to receiving wave". That is, the ranging result (m) = Echoterminal high voltage length * 340m / 2
b. Relay
The 5V relay module used has two sides of wiring, one side is power supply and signal (4-pin, compatible with 3.3V signal), and the other side is path opening and closing management (3 ports). The relay realizes a "single pole and double switch" mode on the "path management side", which controls the direction of the single pole through the high and low level of the "CH1 pin" on the "power supply and signal" side. In the process of installation, the electromagnetic lock power supply defaults to the normally closed end of the relay. after the signal is given to the relay, the relay is switched to the normal start, then the electromagnetic lock is turned off and unlocked.
C. GPIO
GPIO (General-purpose input/output Universal input and output), which provides the ability to connect hardware in the form of pins. The raspberry pie has 40 GPIO pins (see the reference illustration in the 3.2.3 hardware wiring). Under the raspberry pie's official operating system Raspbian, you can use the RPi.GPIO library installed by default in python.
On how raspberry pi code to achieve face recognition unlocking application is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.