Object Tracking Example
HUSKYLENS 2 object tracking returns ID, name, center XY, width and height in real time. It’s like a smart tape measure that follows one chosen item in view. Using the Python example, you initialize the board, switch to ALGORITHM_OBJECT_TRACKING, then loop to read cached center results and display object ID, label, coordinates and size on the Unihiker GUI after framing the target in Mind+.
1.Object Tracking
Before You Start:
1.1 Object Tracking - Output Relevant Data
When HUSKYLENS 2 detects a trackable target object, it can acquire relevant tracking data. The data that can be acquired includes: the object's ID, Name, XY coordinates, 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_OBJECT_TRACKING)
line1=u_gui.draw_text(text="Objct ID:",x=0,y=0,font_size=15, color="#0000FF")
line2=u_gui.draw_text(text="Object name:",x=0,y=40,font_size=15, color="#0000FF")
line3=u_gui.draw_text(text="Object coords:",x=0,y=80,font_size=15, color="#0000FF")
line4=u_gui.draw_text(text="Object width & height:",x=0,y=120,font_size=15, color="#0000FF")
while True:
huskylens.getResult(ALGORITHM_OBJECT_TRACKING)
if (huskylens.available(ALGORITHM_OBJECT_TRACKING)):
line1.config(text=(str("Objct ID:") + str((huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING).ID if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING) else -1))))
line2.config(text=(str("Object name:") + str((huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING).name if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING) else -1))))
line3.config(text=(str("Object coords:") + str((str((huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING).xCenter if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING) else -1)) + str((str(",") + str((huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING).yCenter if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING) else -1))))))))
line4.config(text=(str("Object width & height:") + str((str((huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING).width if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING) else -1)) + str((str(",") + str((huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING).height if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING) else -1))))))))
Click 'Run' in Mind+ and wait for the program to upload.
Point the HUSKYLENS 2 camera at the object to be tracked (the target object must be framed first, see Object Tracking.
After framing is complete, aim at the target object to observe the output results.
Output Result:It can output the tracked object's ID, Name, XY coordinates, Width, and Height. The default object name is "Object" .
Was this article helpful?
