Self-Learning Classifier Example

Self-learning classifier on HUSKYLENS 2 lets the camera learn, recognize and label custom objects autonomously. It’s like giving the camera flashcards so it memorizes each card’s ID and name automatically, enabling personalized, flexible vision-based projects.

1. Self-Learning Classifier Code Example

Before You Start:

1.1 Output ID and Name of Learned Objects

During the Self-Learning Classifier function, HUSKYLENS 2 can learn and recognize any custom object. For detailed usage instructions on the custom classification function, please refer to the Self-Learning Classifier Function.

During the Self-Learning Classifier function, once an object has been learned, HUSKYLENS 2 will recognize it when encountered again. Use the following example program to obtain the corresponding ID and name of the learned object.

#include "DFRobot_HuskylensV2.h"
// Create object
HuskylensV2 huskylens;


// Main program starts
void setup() {
  Serial.begin(9600);
  Wire.begin();
  while (!huskylens.begin(Wire)) {
    delay(100);
  }
  huskylens.switchAlgorithm(ALGORITHM_SELF_LEARNING_CLASSIFICATION);
}
void loop() {
  huskylens.getResult(ALGORITHM_SELF_LEARNING_CLASSIFICATION);
  if ((huskylens.available(ALGORITHM_SELF_LEARNING_CLASSIFICATION))) {
    Serial.println((String("ID of the recognized object: ") + String((RET_ITEM_NUM(huskylens.getCachedCenterResult(ALGORITHM_SELF_LEARNING_CLASSIFICATION), Result, ID)))));
    Serial.println((String("Name of the recognized object: ") + String((RET_ITEM_STR(huskylens.getCachedCenterResult(ALGORITHM_SELF_LEARNING_CLASSIFICATION), Result, name)))));
  }
}

Running Result: As follows, when a previously learned object appears in the image, it will be framed and its ID and confidence level will be displayed simultaneously. Open the Serial Monitor to observe the corresponding ID and name in the output. If the name of the object is not set, the output name defaults to: Object.

Interface Diagram

Was this article helpful?

TOP