[UNIHIKER M10][MindPlus][Python] Optical Character Recognition
Last revision 2026/08/12
What is HuskyLens OCR on UNIHIKER M10? It detects text blocks, reads only the one under the crosshair, and shows its ID, content, position and size on screen.
1.Optical Char Recognition
Before You Start:
1.1 Optical Char Recognition - Output Relevant Data
Under the Optical Char Recognition function, HUSKYLENS 2 can recognize and frame the areas where text blocks appear in its field of view, and display the recognized text on the screen. The following example program can be used to count the total number of recognizable text blocks in the frame and acquire data for the text block closest to the crosshair. Readable data includes: the text block's ID, Name, Content, center X and Y coordinates, and the text block's Width and Height.
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_OCR_RECOGNITION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=15, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=15, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=15, color="#0000FF")
line4=u_gui.draw_text(text="",x=0,y=120,font_size=15, color="#0000FF")
line5=u_gui.draw_text(text="",x=0,y=160,font_size=15, color="#0000FF")
line6=u_gui.draw_text(text="",x=0,y=200,font_size=15, color="#0000FF")
line7=u_gui.draw_text(text="",x=0,y=240,font_size=15, color="#0000FF")
line8=u_gui.draw_text(text="",x=0,y=320,font_size=15, color="#0000FF")
while True:
huskylens.getResult(ALGORITHM_OCR_RECOGNITION)
if (huskylens.available(ALGORITHM_OCR_RECOGNITION)):
line1.config(text=(str("Text count:") + str((huskylens.getCachedResultNum(ALGORITHM_OCR_RECOGNITION)))))
line2.config(text=(str("Center text ID:") + str(huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION).ID if huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION) else -1)))
line3.config(text="Center text content:")
line4.config(text=huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION).content if huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION) else -1)
line5.config(text="Center text")
line6.config(text=(str("Coords") + str((str(huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION).xCenter if huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION) else -1) + str((str(",") + str(huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION).yCenter if huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION) else -1)))))))
line7.config(text="Center text")
line8.config(text=(str("Width & height:") + str((str(huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION).width if huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION) else -1) + str((str(",") + str(huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION).height if huskylens.getCachedCenterResult(ALGORITHM_OCR_RECOGNITION) else -1)))))))
Click 'Run' in Mind+ and wait for the program to upload.
Point the HUSKYLENS 2 camera at any optical characters and observe the results displayed on the M10 (User provided K10, but document context is M10) screen.
Output Result: As shown below, the default output ID for unlearned text blocks is 0.
You can aim it at a learned text block. For detailed instructions on how to learn optical characters, refer to: Optical Character Recognition
Output Result: As shown below, the output ID for a learned text block matches the ID displayed on the HUSKYLENS 2 screen.
Note: Under the Optical Char Recognition function, HUSKYLENS 2 can detect and frame all areas where text blocks appear in the frame, but it only recognizes the content of the single text block area where the crosshair is located and displays the text content at the top left of the frame.
Was this article helpful?
