License Plate Recognition Example

HuskyLens 2 license plate recognition reads plate IDs, text, size and center coordinates, like a smart camera counting cars at a gate, and with UNIHIKER it displays total plates, learned IDs, center plate info, and data for specific ID plates including count, content and position.

1.License Plate Recognition Blocks

Before You Start:

1.1 License Recognition - Output Relevant Data

Under the License Recognition function, when a license plate appears on the HUSKYLENS 2 screen, it can be recognized and framed, and its relevant data acquired. Readable license plate data includes: the ID and Name of a specific license plate, the license plate content (license number), Width, Height, X and Y coordinates of the license plate's center point, the total number of license plates in the frame, and the total number of learned license plates in the frame.

Example Program:

from unihiker import GUI
from pinpong.board import Board
from dfrobot_huskylensv2 import *


u_gui=GUI()
Board().begin()
huskylens = HuskylensV2_I2C()
huskylens.knock()
huskylens.switchAlgorithm(ALGORITHM_LICENSE_RECOGNITION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=10, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=10, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=10, color="#0000FF")
line4=u_gui.draw_text(text="",x=0,y=120,font_size=10, color="#0000FF")
while True:
    huskylens.getResult(ALGORITHM_LICENSE_RECOGNITION)
    if (huskylens.available(ALGORITHM_LICENSE_RECOGNITION)):
        line1.config(text=(str("License plate count:") + str((huskylens.getCachedResultNum(ALGORITHM_LICENSE_RECOGNITION)))))
        line2.config(text=(str("Learned License plate count:") + str((huskylens.getCachedResultMaxID(ALGORITHM_LICENSE_RECOGNITION)))))
        line3.config(text=(str("Center QR License plate ID:") + str(huskylens.getCachedCenterResult(ALGORITHM_LICENSE_RECOGNITION).ID if huskylens.getCachedCenterResult(ALGORITHM_LICENSE_RECOGNITION) else -1)))
        line4.config(text=(str("1st License plate ID:") + str(huskylens.getCachedResultByIndex(ALGORITHM_LICENSE_RECOGNITION, 1-1).ID if huskylens.getCachedResultByIndex(ALGORITHM_LICENSE_RECOGNITION, 1-1) else -1)))

Click 'Run' in Mind+ and wait for the program to upload.

Point the HuskyLens 2 camera at the license plate in the frame to learn it. For detailed instructions on how to learn license plates, refer to License Plate Recognition.

Point the HUSKYLENS 2 camera at the license plate and observe the data on the UNIHIKER M10 screen.

Output Result:As shown below, three license plates are recognized in the frame, one of which is learned. The ID of the license plate near the center and the ID of the first detected license plate are both 0. (Unlearned license plates have an ID of 0; learned license plates output their corresponding ID.)

Interface Diagram

1.2 Output Data for a Specific ID License Plate

When multiple license plates of the same ID appear in the frame, the following example program can be used to gather relevant data for that ID's license plates.

from unihiker import GUI
from pinpong.board import Board
from dfrobot_huskylensv2 import *


u_gui=GUI()
Board().begin()
huskylens = HuskylensV2_I2C()
huskylens.knock()
huskylens.switchAlgorithm(ALGORITHM_LICENSE_RECOGNITION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=10, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=10, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=10, color="#0000FF")
line4=u_gui.draw_text(text="",x=0,y=120,font_size=10, color="#0000FF")
line5=u_gui.draw_text(text="",x=0,y=160,font_size=10, color="#0000FF")
while True:
    huskylens.getResult(ALGORITHM_LICENSE_RECOGNITION)
    if (huskylens.available(ALGORITHM_LICENSE_RECOGNITION)):
        line1.config(text=(str("License plate ID1 count:") + str((huskylens.getCachedResultNumByID(ALGORITHM_LICENSE_RECOGNITION, 1)))))
        line2.config(text="License plate ID1:")
        line3.config(text=(str("Contenr") + str(huskylens.getCachedResultByID(ALGORITHM_LICENSE_RECOGNITION, 1).content if huskylens.getCachedResultByID(ALGORITHM_LICENSE_RECOGNITION, 1) else -1)))
        line4.config(text="1st license plate ID1:")
        line4.config(text=(str("1st License plate ID:") + str((str((str(huskylens.getCachedIndexResultByID(ALGORITHM_LICENSE_RECOGNITION, 1, 1-1).xCenter if huskylens.getCachedIndexResultByID(ALGORITHM_LICENSE_RECOGNITION, 1, 1-1) else -1) + str(","))) + str(huskylens.getCachedIndexResultByID(ALGORITHM_LICENSE_RECOGNITION, 1, 1-1).yCenter if huskylens.getCachedIndexResultByID(ALGORITHM_LICENSE_RECOGNITION, 1, 1-1) else -1)))))

Output Result: As shown below, when multiple license plates of a specific ID appear in the frame, it can acquire the total count of that ID's license plates, the license plate number of a specific plate under that ID, and its coordinates, among other data.

Interface Diagram

Was this article helpful?

TOP