Search code examples
image-processingarduinohardwareimage-recognitionarduino-c++

How can I make the Arduino do a certain action when it recognizes a certain object though the pixy cam


It would also be helpful if you could tell me how I can make the Arduino display the name of object detected.

Can you tell me what I need to add to do this:

#include <Pixy2.h>

// This is the main Pixy object 
Pixy2 pixy;

void setup()
{
  Serial.begin(115200);
  Serial.print("Starting...\n");
  
  pixy.init();
}

void loop()
{ 
  int i; 
  // grab blocks!
  pixy.ccc.getBlocks();
  
  // If there are detect blocks, print them!
  if (pixy.ccc.numBlocks)
  {
    Serial.print("Detected ");
    Serial.println(pixy.ccc.numBlocks);
    for (i=0; i<pixy.ccc.numBlocks; i++)
    {
      Serial.print("  block ");
      Serial.print(i);
      Serial.print(": ");
      pixy.ccc.blocks[i].print();
    }
  }  
}

Solution

  • I'm not sure, if I get your question correct, but as far as I remember getBlocks() returns you the number of recognised objects. Given the case, that there has been a detection of a known object, this number should be positive. As you do already print those blocks, what keeps you from calling new functionality from this loop?

    For the second question on how to display the names I'm not exactly sure, what you're looking for. You can take the "signature" of a block and use it as a name and of course you can match your own names to certain signatures. If you want to print them like all other values, you can just use Serial.print() as well. If you want to print them differently e.g. to a LC-display, then we first need to know your intentions.

    Maybe check out this tutorial to get a better grasp of the interface: https://www.open-electronics.org/pixy-camera-detect-the-colour-of-the-objects-and-track-their-position/