Object Classification Example

Object classification on HUSKYLENS 2 lets you recognize learned objects and directly read their ID and name via code. It’s like a smart labeler that tags what the camera sees. Using the I2C API, you initialize the board, switch to the object classification algorithm, then loop to fetch results and display the current object’s classID and name on the GUI while confidence is only visible on-screen, not accessible in code.

1.Object Classification

Before You Start:

1.1 Recognize Learned Objects and Output ID/Name

Under the Object Classification function, HUSKYLENS 2 can classify 1000 fixed categories of objects. The following example program can be used to get the corresponding ID and name of the recognized learned object.

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_CLASSIFICATION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=16, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=16, color="#0000FF")
while True:
    huskylens.getResult(ALGORITHM_OBJECT_CLASSIFICATION)
    if (huskylens.available(ALGORITHM_OBJECT_CLASSIFICATION)):
        line1.config(text=(str("Object ID:") + str((huskylens.getCachedCenterResult(ALGORITHM_OBJECT_CLASSIFICATION).classID if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_CLASSIFICATION) else -1))))
        line2.config(text=(str("Object name:") + str((huskylens.getCachedCenterResult(ALGORITHM_OBJECT_CLASSIFICATION).name if huskylens.getCachedCenterResult(ALGORITHM_OBJECT_CLASSIFICATION) else -1))))

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

After HUSKYLENS 2 finishes learning the object, point the HUSKYLENS 2 camera at the learned object and observe the output results. For detailed instructions on how to learn objects, refer to: Object Classification.

Output Result:As shown below, when a learned object appears in the frame, its name, ID, and confidence level will be displayed (confidence level cannot currently be retrieved via program).

Interface Diagram

Was this article helpful?

TOP