This API can be called through the ccc member of the Pixy2 object, for example:
Pixy2 pixy; pixy.ccc.getBlocks();
Firmware versions 3.0.11 and greater will automatically switch to the color_connected_components program when making requests through the color connected components API. Older firmware versions will return errors when attempting to call these functions while the color connected components program is not running.
A good program to run to familiarize yourself the CCC algorithm is the ccc_hello_world example found in the Arduino library.
getBlocks() gets all detected blocks in the most recent frame. The new data is then available in the blocks member variable. The returned blocks are sorted by area, with the largest blocks appearing first in the blocks array. It returns an error value (<0) if it fails and the number of detected blocks (>=0) if it succeeds.
Setting wait to false causes getBlocks() to return immediately if no new data is available (polling mode). Setting wait to true (default) causes getBlocks() to block (wait) until the next frame of block data is available. Note, there may be no block data if no objects have been detected.
sigmap is a bitmap of all 7 signatures from which you wish to receive block data. For example, if you are only interested in block data from signature 1, you would pass in a value of 1. If you are interested in block data from both signatures 1 and 2, you would pass in a value of 3. If you are interested in block data from signatures 1, 2, and 3, you would pass a value of 7, and so on. The most-significant-bit (128 or 0x80) is used for color-codes. A value of 255 (default) indicates that you are interested in all block data.
maxblocks indicates the maximum number of blocks you wish to receive. For example, passing in a value of 1 would return at most 1 block. A value of 255 (default) indicates that you are interested in all blocks.
The number of blocks contained in the blocks member variable.
This array contains all of the block data as a result of getBlocks(). The blocks in this array are sorted by area, with the largest blocks appearing first in the blocks array.
Inside the Block struct:
Calling this prints the block information to the console.
This variable contains the signature number or color-code number.
This variable contains the x location of the center of the block. The value ranges between 0 and frameWidth (315).
This variable contains the y location of the center of the block. The value ranges between 0 and frameHeight (207).
This variable contains the width of the block. The value ranges between 0 and frameWidth (316).
This variable contains the height of the block. The value ranges between 0 and frameHeight (208).
This variable contains the angle of color-code in degrees. The value ranges between -180 and 180. If the block is a regular signature (not a color-code), the angle value will be 0.
This variable contains the tracking index of the block. When Pixy2 detects a new block, it will add it to a table of blocks that it is currently tracking and assign it a tracking index. It will then attempt to find the block (and every block in the table) in the next frame by finding its best match. Each block index will be kept for that block until it either leaves Pixy2's field-of-view, or Pixy2 can no longer find the object in subsequent frames (because of occlusion, lack of lighting, etc.)
This variable contains the number of frames a given block has been tracked. When the age reaches 255, it remains at 255.