The “show_signatures” Code Block in Pixy2TerminalDisplay.svg
The Pixy2TerminalDisplay.svg program translated the color signatures into numbers and displayed them in the Terminal. This example BlocklyProp code has many functions, but one of them — the show_signatures function — steps through all detected color signatures and displays their signature numbers, sizes, and position.
The key to using the Pixy2TerminalDisplay.svg code example is to be able to use the variables in the show_signatures function.
Vision is complex! Amazon, Google, Uber, Softbank and GM are spending billions of dollars to effectively use vision and sensors for autonomous vehicles. Pixy2 simplifies what your robot sees, yet there’s still a significant amount of data to evaluate when color signatures are detected. Attributes such as quantity of each signature, the signature number, size and location may quickly complicate simple robotic code!Before we use the show_signatures function, let’s get a look at what’s inside:
The repeat blockIdx loop reports the maximum number of color signatures detected, which you taught the Pixy2 with the PixyMon software. The variables within this function describe the properties of each colored block that was detected: blockIdx, blocksDetected, bSignature, bXpos, bYpos, bWidth, and bHeight. Also, note maxBlocks = 3; it’s the 3rd block in the function. You will have to adjust that if you want the program to report more than three blocks.
For each of the color signatures that were detected, the loop stores the signature number, x/y location, width and height in their respective variables. These variables are also overwritten with each loop iteration. For example, if you taught the Pixy2 to recognize three signatures and are only interested in the data from signature 1, you’ll need to add code that uses the data before it gets overwritten by the next loop iteration. To do that, you could add an if block that checks if bSignature = 1 that contains a routine that takes some kind of action in response to the bXpos and bYpos values.