With continuous urban development, parking problems have become increasingly difficult. For drivers looking for suitable parking spaces, "parking full" is undoubtedly frustrating. So how can we solve "difficult parking"? One of the best ways is to share idle parking spaces, activating unused spots and providing more choices for car owners. Therefore, communities should consider opening idle parking spaces to ease parking pressure.

Next, we will use UNIHIKER M10 to build an AIoT community parking-space sharing system. Community staff publish idle parking-space information; after receiving it, car owners can send license plate numbers and apply for parking.
Goal
Community staff can publish currently available parking-space information through the server side. After a car owner on a mobile device receives available-space information, they can upload their plate number and send a parking-space request. The intelligent terminal receives and stores plate information from the mobile terminal. When the camera recognizes that plate number, the system automatically opens the gate so the owner can enter smoothly.
Note: The intelligent terminal and server side use the same UNIHIKER M10.

Get to Know
1. Understand principles and usage of camera-based license plate recognition.
2. Learn practical applications of AIoT in daily life.
Materials List
Hardware List:


Software: Mind+ programming software (V1.8.0) x1
Note: This lesson uses Mind+ visualization panel, so UNIHIKER M10 SIoT service must be upgraded to version 2.0. You can find the update file in the course resources folder.
Instructions: Open the program, follow the steps below to switch to Python mode, connect the device, open the update.py file, and run it. Wait until the update is complete.

Hands-on Practice
The AIoT community parking-space sharing system is mainly for community staff to share parking spaces. After receiving shared information, car owners upload their plate numbers and request usage. When owners enter the community, the gate opens automatically. Therefore, we complete the system through the following four tasks.
Task 1: Automatic Plate-Recognition Gate
Press button A, and the USB camera recognizes the plate number. If the recognized plate is a registered one, the gate opens automatically.
Task 2: Build Server Side
Build a simple available-space publishing interface for community administrators to publish available-space messages.
Task 3: Build Mobile Terminal
The mobile terminal is used for users to receive available-space information. After receiving it, if they want to use the space, they can send their plate number to the server side through a request button.
Task 4: Build Intelligent Terminal
The intelligent terminal receives and stores plate numbers from server side. When recognition result is a registered plate number, open the gate.
Task 1: Plate Recognition Gate
1. Hardware Connection
Connect camera to USB port of UNIHIKER M10, connect servo to pin P23 of UNIHIKER M10, then connect UNIHIKER M10 to computer with USB cable after successful hardware connection.

2. Software Preparation
Open Mind+ and complete software preparation as shown below.

3. Write a Program
(1)Load License Plate Recognition Library
After connecting to UNIHIKER M10 remote terminal at `10.1.2.3`, find the `Chinese_license_plate_detection_recognition` folder in `assets`, and import it into `Files in
UNIHIKER M10`.

To use the plate-recognition library on UNIHIKER M10, install dependencies first. Method:
click "Code" to switch programming mode, find `1-Install_dependency.py` in imported folder
and double-click it, then click Run.

After installation, click "Blocks" to switch to graphical programming. Then import plate-recognition library:
click "Extensions", enter URL `https://gitee.com/chenqi1233/ext chinese_license_plate_detection_recognition` in "User-Ext", then click "License Plate Recognition" to add it.

If plate recognition result belongs to a vehicle in this community, control gate opening.
Use a servo to simulate gate opening; import servo library by clicking "Extensions", then
finding and adding "Servo" in "pinpong" library.

After adding plate-recognition library, we can use blocks and USB camera to recognize plates. First use `initialize camera until success` with ID 0.

After camera initialization succeeds, use `open camera frame for reading` block to read camera frames.

Press button A to recognize the plate in camera frame. Use conditional block to determine
whether button A is pressed.When condition is true, use `start license plate recognition` block
to recognize plate, then use print block to output recognition result in Mind+ terminal.
Note: For principle of plate recognition, see Knowledge Section.

Community staff maintain a vehicle information table for the community. Registered plate numbers are:
No. | Plate Number |
1 | 川A12345 |
2 | 川B12345 |
3 | DF00000 |
4 | DF11111 |
Use a list to store registered plate numbers. Create variable `plate_info_list`, initialize it as
list, then fill plate numbers in the list.
Note: Plate numbers in list should be enclosed in English quotation marks and separated
by English commas.

Then under `when Python main program starts`, use servo initialization block to initialize
servo pin as P23; then use servo rotation block to set servo angle to 10 degrees (simulate
gate closed).

How to determine whether the vehicle belongs to this community? Use conditional statement to check whether recognition result exists in list. Use `for` loop block to iterate plate numbers in list and compare with recognition result.

When condition is true, use servo rotation block to set servo angle to 100 degrees (open gate). After waiting 3 seconds for vehicle to pass, set servo angle back to 10 degrees (close
gate).

4. Run the Program
Click Run. After successful execution, plate recognition can begin. Press button A to start recognition. When recognized plate is a registered community plate, gate opens automatically and closes after 3 seconds.
Note: Plate images are provided in assets and can be printed directly.

The community parking-sharing system uses two UNIHIKER M10 boards: one serves as server side for staff publishing and as intelligent terminal for recognition/gate control; the other serves as mobile terminal for users. In this task, we first complete server-side setup.
1. Write a Program
Main function of server side is to publish available parking-space information to car owners. Therefore, directly use Mind+ visualization panel to design a simple publishing interface.
(1)Build Server Side
Connect the computer and two UNIHIKER M10 boards to the same subnet, and enable IoT service (SIoT2.0) on the server-side UNIHIKER M10.
Note: For operations like connecting multiple UNIHIKER M10 boards to the same network and checking network info, refer to the tutorial:
https://learn.dfrobot.com/makelog-308777.html.
Next, enter IoT platform and create required topics. This project includes two topics: available spaces and plate information.

Click "Visualization Panel" at the top of Mind+ to open "Mind+ Data Visualization" window.

Click "Create a project", fill in project name in popup, click OK, and a new project tag appears on project-management page.

(3) Connect SIoT
After project creation, click "Edit" on corresponding tag to enter editor. In top menu bar, click "Not Set", select "Data Source Settings", and fill IoT platform information in popup. After completion, subscription success is shown.

Now complete visualization interface design according to requirements.

First, on visualization edit page, set canvas size, theme, and cover in the right "Properties" area.

Find "Text" in "Decorative Components" and add it. In component properties, modify displayed text and hide background.

Using the same method, add text "Please enter and publish available community parking-space count:".

Find "Input Box" in "Basic Components" and add it. In properties, find "Topic", choose `siot/available_space_count`, and check "Hide Background".

2. Run the Program
Click "Save" in project-name dropdown menu, then click "Full Screen" to view complete visualization interface.

Community staff enter available-space count in input box and click Send to publish available-space information. After successful sending, corresponding data can be viewed under `siot/available_space_count` topic on IoT platform.

The mobile terminal is mainly used for car owners to receive available-space information
and upload their plate information to server side. Therefore, mobile-terminal functions are
mainly two parts: receive available-space information and upload plate information.

1. Write a Program
(1)Design UI Interface
To simplify programming, the frame and fixed text in interface are made into a background image. First import required image from image asset library into file system.

Use `display image` block to set background-image position. Use `display text` block to set text positions. Use `add button` block to set a request-to-use button. Program is as follows:

To receive available-space information sent by server side, use blocks from `MQTT-py` library. Add `MQTT-py` by clicking "Extensions" and selecting it from official library.

Use MQTT blocks to complete four steps: MQTT initialization -> connect -> keep connection -> subscribe. Topic to subscribe here is `siot/Available Spaces`.

Use MQTT receive block to receive messages from server side. When receiving available-space message from server topic `siot/Available Spaces`, use `update text content parameter` block to update available-space data.

After seeing available-space count on UNIHIKER M10, the car owner can click request-use button and send request message to server side. Under `when click callback is pressed`, use MQTT publish-and-save-to-database block to send own plate number to topic `siot/plate info`, and use `update text content parameter` block to show "Successfully!".
Complete program is as follows:

2. Run the Program
Click Run. After successful execution, use Task 2 visualization interface to send community available-space count. After mobile terminal receives message from topic `siot/Available Spaces`, click request-use button to send plate number to topic `siot/plate_info`. The plate number will also appear under `siot/plate_info` topic on SIoT platform.

The intelligent terminal mainly performs plate recognition for vehicles entering/leaving the community and controls the gate. When camera recognizes a plate uploaded by mobile terminal, gate opens automatically. Therefore, intelligent-terminal functions are three parts: create plate list, recognize plate, and control gate.
1. Hardware Connection
Connect camera to USB port of UNIHIKER M10, connect servo to pin P23, and connect UNIHIKER M10 to computer with USB cable after successful hardware connection.

2. Write a Program
(1)Create Plate List
Because intelligent terminal and server side use the same UNIHIKER M10, continue
improving program based on Task 2. Add `MQTT-py` library and complete four steps: MQTT
initialization -> connect -> keep connection -> subscribe. Subscribed topic is `siot/plate_info`.

Create variable `plate_info` and initialize it as a list.

Use MQTT receive block to receive plate information from server side. When receiving plate-number message sent from mobile-terminal topic `siot/plate_info`, use list-add block to append MQTT message (plate number) to end of list.

To open camera and recognize plate, under `when Python main program starts`, add `initialize camera until success` block. In `forever`, add `open camera frame for reading`, `start license plate recognition`, and `get license recognition result` blocks.

Use `for` loop block to iterate plate numbers in plate-info list and compare each with recognized plate result.

Add `Servo` library: click Extensions, find `Servo` in `pinpong` library, and add it. Under `when Python main program starts`, use servo pin initialization block to initialize servo pin, and use servo rotation block to set initial angle to 10 degrees.
When recognized plate is in vehicle-info list, use servo rotation block to rotate servo to 100 degrees (open gate), then wait 10 seconds and rotate servo to 10 degrees (close gate). Complete program is as follows:

3. Run the Program
Run Task 3 program on mobile-terminal UNIHIKER M10 and Task 4 program on intelligent-terminal UNIHIKER M10. After both run successfully, open visualization interface on intelligent terminal and publish available-space count. Mobile terminal receives and displays available-space count; after pressing request-use button, plate number is sent to intelligent terminal.

Intelligent terminal stores plate number into plate-info list. Press button A; when camera-recognized plate is in stored list, the gate opens.

Knowledge Base
1. Understand Camera-Based Plate Recognition Principles
The principle is to capture vehicle images with a camera and then recognize plate numbers from those images. Main steps include: vehicle detection -> image acquisition → image preprocessing -> plate localization -> character segmentation -> character recognition → result output.
(1)Vehicle Detection
Before taking photos, detect whether the vehicle has entered the optimal focal-distance position of the camera. So vehicle detection is the first step of plate recognition. The camera passively collects data and does not know when to take a picture by itself. There are many ways to trigger camera capture. A common one in daily life is infrared triggering: when a vehicle enters capture area and blocks infrared rays, the camera and system linkage triggers photo capture.

In this lesson, we use UNIHIKER hardware trigger. When a vehicle enters capture area, press button A, and the camera captures the vehicle image for subsequent plate recognition.
(2)Image Acquisition
Capture photos of vehicles entering valid focal range. This step is straightforward. Software of the plate-recognition system can capture frames from video or directly take photos. Acquired images are then provided to recognition system.

Vehicles have many colors, which can confuse computers. Therefore the image is processed into only black and white. This is image binarization, also called "panda style". During processing, RGB value of each pixel is judged; based on threshold (e.g., 160), pixels greater than 160 are set to white and pixels lower than 160 are set to black.

After image processing, how to locate the plate? A plate is a regular rectangle, so we need to find rectangles in the image. The computer scans the processed image left-to-right and top-to-bottom, recording all pixels where color changes black-to-white or white-to-black. Then it calculates which region is rectangular and finds positions matching plate proportion. How to determine whether it is a plate number? Very simple: scan that region again. Since image is processed, if there is a plate, there must be black-white changes, especially in vertical direction. This narrows range and allows quick plate finding.

After successfully locating the plate, perform vertical segmentation according to width of each character from scanned plate. Because plate image is now black and white, characters are either white-on-black or black-on-white, so character height and width are easy to get. Segmentation uses this basis to split all plate characters into individual characters.

(6)Character Recognition
Compare segmented characters one by one with plate-template library, then find the
image with highest similarity from template library. Goal is to obtain province Chinese
character, 26 uppercase English letters, and digits 0-9.

During matching, templates with highest similarity are stored in an array in sequence.
Finally, by traversal, the successfully recognized plate number is obtained.

2. Understand Practical AIoT Applications
AIoT is the combination of AI and IoT, integrating artificial intelligence with internet-of-things technology. The fusion brings strong human-computer interaction, data management, and data analysis. AIoT is changing our lives in a new and fast way. From home, education, cities, security, agriculture, healthcare, manufacturing to transportation, AIoT appears in every field.
Now let us briefly look at two most common AIoT applications in life: smart home and
smart agriculture.
Smart Home
One of the most discussed AIoT applications is in homes, where AIoT makes appliances
more intelligent. Whether for lighting systems or home monitoring, AIoT truly raises home
convenience to a new level.
Take home lighting as an example. After combining lighting systems with AIoT, you can
not only turn home lights on/off via smartphone, but also control them through voice
commands, and even adjust brightness and color based on sensed ambient light.

In traditional agriculture, fertilizing, irrigation, and harvesting are done by people. With
AIoT, these tasks can be "decided" by the land itself. Sensors monitor soil and plant growth in
real time and transmit information to decision layer. After AI analyzes data, it decides which
task to execute. AIoT enables personalized management for each plot and even different
services for different plants in the same area, freeing hands while saving resources and
improving yield.

3. Block Overview

Challenge Yourself
To make the mobile terminal more user-friendly, modify programs of intelligent and mobile terminals so the mobile terminal displays vehicle entry and exit times. You can also add a prompt after showing exit time: "Welcome to use again. Have a safe trip!"
Hint: Create another topic `siot/recognition_time` on SIoT V2.0 platform.








![[Spanish ver.] HuskyLens Cámara Inteligencia Artificial](https://dfimg.dfrobot.com/nobody/makelog/902f49d1d2eb94077e1ba7d8b652cee6_224x164.jpg)
