<< return to Pixycam.com

User Tools

Site Tools


wiki:v2:ccc_api

Color Connected Components API

This API can be called through the ccc member of the Pixy2 object, for example:

Pixy2 pixy;

pixy.ccc.getBlocks();

See also the Pixy2 General API, Line tracking API, and Video API for other functionality.

For a byte-level reference to the protocol, check out the new Pixy2 Serial Protocol - Packet Reference

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.

Color connected components image coordinates from Pixy2's perspective

Member functions

int8_t getBlocks(bool wait [optional], uint8_t sigmap [optional], uint8_t maxBlocks [optional])

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.

Member variables

uint8_t numBlocks

The number of blocks contained in the blocks member variable.

Block blocks[]

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:

void print()

Calling this prints the block information to the console.

uint16_t m_signature

This variable contains the signature number or color-code number.

uint16_t m_x

This variable contains the x location of the center of the block. The value ranges between 0 and frameWidth (315).

uint16_t m_y

This variable contains the y location of the center of the block. The value ranges between 0 and frameHeight (207).

uint16_t m_width

This variable contains the width of the block. The value ranges between 0 and frameWidth (316).

uint16_t m_height

This variable contains the height of the block. The value ranges between 0 and frameHeight (208).

int16_t m_angle

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.

uint8_t m_index

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.)

uint8_t m_age

This variable contains the number of frames a given block has been tracked. When the age reaches 255, it remains at 255.

wiki/v2/ccc_api.txt · Last modified: 2018/10/10 20:05 by jfrench