Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
DFRobot
Published © GPL3+

New Function Update: Object Classification

In the new version 0.4.9Class of HuskyLens, a new function “Object Classification” is released.

BeginnerProtip4 hours3,348

Things used in this project

Hardware components

HUSKYLENS AI Camera
DFRobot HUSKYLENS AI Camera
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Code

Code snippet #1

Plain text
					#include "HUSKYLENS.h"
#include "SoftwareSerial.h"

HUSKYLENS huskylens;
//HUSKYLENS green line >> SDA; blue line >> SCL
void printResult(HUSKYLENSResult result);

void setup() {
    Serial.begin(115200);
    Wire.begin();
    while (!huskylens.begin(Wire))
    {
        Serial.println(F("Begin failed!"));
        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
        Serial.println(F("2.Please recheck the connection."));
        delay(100);
    }
}

void loop() {
    if (!huskylens.request()) Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!"));
    else if(!huskylens.available()) Serial.println(F("No block or arrow appears on the screen!"));
    else
    {
        Serial.println(F("###########"));
        while (huskylens.available())
        {
            HUSKYLENSResult result = huskylens.read();
            printResult(result);
        }    
    }
}

void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK){
        if(result.ID == 1){
        Serial.println("Face with Mask");
        }
        else if(result.ID == 2){
        Serial.println("Just Face");  
        }
        else{
        Serial.println("Defualt");
        }
     }
    else{
        Serial.println("Object unknown!");
    }
}
				

Code snippet #2

Plain text
#include "HUSKYLENS.h"
#include "SoftwareSerial.h"

HUSKYLENS huskylens;
//HUSKYLENS green line >> SDA; blue line >> SCL
void printResult(HUSKYLENSResult result);

void setup() {
    Serial.begin(115200);
    Wire.begin();
    while (!huskylens.begin(Wire))
    {
        Serial.println(F("Begin failed!"));
        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
        Serial.println(F("2.Please recheck the connection."));
        delay(100);
    }
}

void loop() {
    if (!huskylens.request()) Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!"));
    else if(!huskylens.available()) Serial.println(F("No block or arrow appears on the screen!"));
    else
    {
        Serial.println(F("###########"));
        while (huskylens.available())
        {
            HUSKYLENSResult result = huskylens.read();
            printResult(result);
        }    
    }
}

void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK){
        if(result.ID == 1){
        Serial.println("Face with Mask");
        }
        else if(result.ID == 2){
        Serial.println("Just Face");  
        }
        else{
        Serial.println("Defualt");
        }
     }
    else{
        Serial.println("Object unknown!");
    }
}

Github file

https://github.com/HuskyLens/HUSKYLENSUploader/blob/master/HUSKYLENSWithModelV0.4.9Class.kfpkg

Credits

DFRobot
66 projects • 147 followers
Empowering Creation for Future Innovators

Comments