You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
IoT-For-Beginners/translations/pcm/5-retail/lessons/2-check-stock-device/wio-terminal-object-detecto...

5.2 KiB

Call your object detector from your IoT device - Wio Terminal

Wen you don publish your object detector, you fit use am from your IoT device.

Copy di image classifier project

Most of di stock detector na di same as di image classifier wey you don create for one previous lesson.

Task - copy di image classifier project

  1. Connect your ArduCam to your Wio Terminal, follow di steps wey dey for lesson 2 of di manufacturing project.

    You fit wan fix di camera for one position, like hang di cable for top box or can, or use double-sided tape take fix di camera to one box.

  2. Create new Wio Terminal project with PlatformIO. Give di project name stock-counter.

  3. Follow di steps wey dey for lesson 2 of di manufacturing project to capture images from di camera.

  4. Follow di steps wey dey for lesson 2 of di manufacturing project to call di image classifier. Most of di code go dey reused to detect objects.

Change di code from classifier to image detector

Di code wey you use to classify images dey almost di same as di code to detect objects. Di main difference na di URL wey you get from Custom Vision, and di results wey di call go return.

Task - change di code from classifier to image detector

  1. Add dis include directive for di top of di main.cpp file:

    #include <vector>
    
  2. Change di name of di classifyImage function to detectStock, both di name of di function and di call for di buttonPressed function.

  3. For di top of di detectStock function, declare one threshold to remove any detections wey get low probability:

    const float threshold = 0.3f;
    

    Unlike image classifier wey dey return only one result per tag, di object detector go return plenty results, so any wey get low probability need to dey filtered out.

  4. For di top of di detectStock function, declare one function to process di predictions:

    void processPredictions(std::vector<JsonVariant> &predictions)
    {
        for(JsonVariant prediction : predictions)
        {
            String tag = prediction["tagName"].as<String>();
            float probability = prediction["probability"].as<float>();
    
            char buff[32];
            sprintf(buff, "%s:\t%.2f%%", tag.c_str(), probability * 100.0);
            Serial.println(buff);
        }
    }
    

    Dis one go take list of predictions and print dem for di serial monitor.

  5. For di detectStock function, replace di contents of di for loop wey dey loop through di predictions with dis:

    std::vector<JsonVariant> passed_predictions;
    
    for(JsonVariant prediction : predictions) 
    {
        float probability = prediction["probability"].as<float>();
        if (probability > threshold)
        {
            passed_predictions.push_back(prediction);
        }
    }
    
    processPredictions(passed_predictions);
    

    Dis one go loop through di predictions, compare di probability to di threshold. All predictions wey get probability wey high pass di threshold go dey added to one list and go dey passed to di processPredictions function.

  6. Upload and run your code. Point di camera to objects wey dey for shelf and press di C button. You go see di output for di serial monitor:

    Connecting to WiFi..
    Connected!
    Image captured
    Image read to buffer with length 17416
    tomato paste:   35.84%
    tomato paste:   35.87%
    tomato paste:   34.11%
    tomato paste:   35.16%
    

    💁 You fit need adjust di threshold to better value for your images.

    You go fit see di image wey dem take, and dis values for di Predictions tab for Custom Vision.

    4 cans of tomato paste for shelf with predictions for di 4 detections of 35.8%, 33.5%, 25.7% and 16.6%

💁 You fit find dis code for di code-detect/wio-terminal folder.

😀 Your stock counter program work well!


Disclaimer:
Dis dokyument don translate wit AI translation service Co-op Translator. Even as we dey try make sure say e correct, abeg no forget say machine translation fit get mistake or no dey accurate well. Di original dokyument for im native language na di main source wey you go fit trust. For important information, e good make you use professional human translation. We no go fit take blame for any misunderstanding or wrong interpretation wey fit happen because you use dis translation.