WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

_camera_common.h

Provides a generic interface to the cameras supported by WebbotLin.

 

Function

 


void cameraInit(CAMERA * camera)

Initialise a camera.
See the description of your actual camera as to how to MAKE a new one. Let's assume you have created an AVRcam on UART2 using:-
AVRCAM camera1 = MAKE_AVRCAM(UART2);
Then you can initialise the camera using:-
cameraInit( camera1 );

uint16_t cameraXresolution(CAMERA* camera)

Return the camera x resolution (ie number of pixels across).
Some cameras allow you to change the resolution - so don't rely on this always returning the same value!

uint16_t cameraYresolution(CAMERA* camera)

Return the camera y resolution (ie number of pixels down).
Some cameras allow you to change the resolution - so don't rely on this always returning the same value!

uint8_t cameraNumColorBins(const CAMERA* camera)

Returns the number of colour bins supported by this model of camera.
Note that this figure will NEVER change for a given model but may change from one model to another. A typical value is 8.

boolean cameraSetBin(CAMERA* camera,uint8_t bin,const COLOR*min, const COLOR*max)

Sets the value of a given colour bin.
This will return FALSE if the specified colour bin is higher than the number of bins this camera can support.
The min/max colours can be specified in any colour space you like (ie RGB or YUV) and will be automatically converted internally into the colour space used by the camera. Note that the sending of the colour bin to the camera may be delayed until such time as they will be used.
So to set colour bin #2 to cover a range of REDs then we could do:-
COLOR min,max; // create two empty variables
colorSetRGB(&min, 128,0,0); // set min to RGB(128,0,0)
colorSetRGB(&max, 255,128,128); // set max to RGB(255,128,128)
cameraSetBin(camera1, 2, &min, &max); // Set the color bin

void cameraSetMinBlobSize(CAMERA* camera, uint32_t minSize)

Reduces the amount of data returned by the camera by specifying the smallest blob size (width * height) that we are interested in. The default value is 4 pixels (ie 2x2, 4x1, or 1x4);
Example: if we know that the smallest blob that we are interested in is 30 pixels then we call call:
cameraSetMinBlobSize(camera,30);
Some cameras support this function themselves and will therefore not even send blobs that are smaller than this. Otherwise WebbotLib will automatically discard any blobs smaller than this. The result, for a WebbotLib developer, is the same. ie "don't worry about it!"

uint8_t cameraGetBlobs(CAMERA* camera,uint8_t bin)

Return the number of blobs which match the specified colour bin (or all).
This will ask the camera to return the matching blob areas which match the specified colour bin. The colour bin can either by any individual bin or can be the 'magic' value of CAMERA_ALL_BINS to mean ANY camera bin.
The value returned is the number of matching blobs. This can be used along with cameraFetchBlob to iterate through the list of blobs.
Note that the list returned is always sorted into descending rectangle size - so the biggest rectangle is always at the top of the list.
Here's an example:-
uint8_t blobs = cameraGetBlobs( camera, CAMERA_ALL_BINS);
if(blobs == 0){
    // No blobs are visible
}else{
    for(uint8_t b = 0; b<blobs; b++){
        // Fetch the blobs - the biggest first
        const CAMERA_BLOB* blob = cameraFetchBlob(camera, b);
        // See _camera_common.h to see the fields in a CAMERA_BLOB
    }
}

const CAMERA_BLOB* cameraFetchBlob(const CAMERA* camera, uint8_t blobNo)

Return the given blob from the list.
The return value is a pointer to a blob whose contents cannot be changed.
See cameraGetBlobs(CAMERA* camera,uint8_t bin) for an example.

boolean cameraGetPixel(CAMERA* camera,uint16_t x, uint16_t y, COLOR * color)

Returns the colour of a given pixel.
The return value is FALSE if there was an error talking to the camera in which case the returned colour has an unreliable value. A value of TRUE means that the function has completed and a returned colour is available.
Example to read the pixel at 10,10 :-
uint16_t x = 10;
uint16_t y = 10;
COLOR color;
if(cameraGetPixel(camera, x, y, &color)){
    // The color is in 'color' so lets dump it out
    rprintf("Pixel @ %u,%u =",x,y); colorDump(&color);
}else{
    // We had problems talking to the camera
}

char * cameraGetVersion(CAMERA* camera)

Reads the firmware revision number from the camera.
Note that the returned string is only valid until the next command is issued to the camera at which point it will get over-written. So either print it out straight away or save it somewhere else.
If there is a problem talking to the camera then the value returned will be NULL.
Here is an example to get the version and send it out to the current rprintf destination:-
char* strVer = cameraGetVersion(camera);
if(strVer){
    rprintf("Camera version:");
    rprintfStr(strVer);
    rprintfCRLF();
}else{
    rprintf("No reply\n");
}

Valid XHTML 1.0 Transitional