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


Support for the Blackfin camera from Surveyor Corporation http://www.surveyor.com/blackfin/
I am very grateful to Surveyor Corporation for answering all of my questions and helping me to support this device.
The firmware on the camera contains some powerful image processing commands thereby allowing you to delegate this intensive work and free up your micro controller to concentrate on what you want it to do.
The camera uses a UART operating at 115,200 baud (although this may vary depending on the firmware version) to talk to the micro controller.
To know more about what bits to order and how to set them up then read http://webbot.org.uk/blackfin/
That page also has details on my own Blackfin Java Console which allows you to experiment with the camera connected to your PC to visualise the commands. I believe you will find it very useful.
The camera supports a number of video resolutions and these have been defined with the following constants:-
The default resolution is 160 by 120 but you can change this either by using the blackfinSetResolution command or by adding a definition prior to including blackfin.h. For example: to set the default resolution as 640 by 480 then the top of your program should look something like this:
#include "Cameras/Surveyor/blackfin.h"
You must also make sure that the UART you are using to communicate with the camera has a receive buffer of around 80 bytes. If you fail to set up the receive buffer then you will get an error message. If the receive buffer is too small then you may also get an error indicating that the receive buffer has overflowed.
The next considerations is 'colours' and 'colour spaces'. The Blackfin camera uses the YUV colour space which is very different from the RGB colour space you are probably used to. This library contains routines to convert colours from one colour space to another - see color.h. If you use a non-YUV colour space then this library will automatically convert it into a YUV colour as and when required.
Here is a complete example for the Axon using UART3 to talk to the camera at 115,200 baud and that sends information to your PC via UART1 at 115,200 baud:
// Define a receive buffer from the camera
// Define a transmit buffer to the PC
// Set the default resolution to 640 x 480

// Include library files
#include <buffer.h>
#include <sys/Axon.h>
#include <Cameras/Surveyor/blackfin.h>
#include <rprintf.h>
// Define colour bins
#define RED 6
#define BLUE 3
// Create the camera
// Set the baud rate and then initialise the camera
void appInitHardware(void){
    // Initialise the UART to the Camera at the expected baud rate
    uartInit(UART3, 115200);
    // Initialise the UART to the PC at the expected baud rate
    uartInit(UART1, 115200);
    // Send rprintf to the PC
    // Put the camera into a known state
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
    // Define the colour bins
    COLOR min,max;
    // Set RED bin - using YUV values
    colorSetYUV(&min, 50, 73,200);
    colorSetYUV(&max, 78,100,250);
    blackfinSetBinRange(&camera, RED, &min, &max);
    // Set BLUE bin - using RGB values
    colorSetRGB(&min, 0,0,100);
    colorSetRGB(&max, 50,50,255);
    blackfinSetBinRange(&camera, BLUE, &min, &max);
    return 0;
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
    // Find RED pixels
    int nBlobs = blackfinDetectBlobs(&camera,RED);
        // Get the first (ie biggest) blob and dump to PC
        const BLACKFIN_BLOB* blob = blackfinFetchBlob(&camera, 0);
        rprintf("Blobs=%d Biggest: Center=",nBlobs);
        rprintf(" Pixels=");rprintfNum(10,10,FALSE,' ',blob->pixels);
        rprintf("No blobs\n");
    return 0;




blackfinInit(BLACKFIN_CAMERA* camera)

Initialise the camera.
This will send commands to the camera to initialise it and MUST be called once in your startup code before issuing any other commands to the camera.

BLACKFIN_RESOLUTION blackfinGetResolution(const BLACKFIN_CAMERA* camera)

Get the current resolution of the camera.
This will return one of the following constants:-

blackfinSetResolution(BLACKFIN_CAMERA* camera, BLACKFIN_RESOLUTION res)

Changes the working resolution of the camera.
This will automatically add a two second delay to allow the camera to adjust to the new resolution.

const COLOR * blackfinMeanColor(BLACKFIN_CAMERA* camera)

This will return the mean colour of all the pixels in view.
You can convert this colour into a given colour space, such as RGB or YUV, using the commands in 'colors.h' or if you want to dump it out to your current rprintf destination then you can use 'colorDump'.

blackfinGetPixel(BLACKFIN_CAMERA* camera,uint16_t x, uint16_t y, COLOR * color)

Read the colour of an individual pixel.
The x and y values should be within range for the current screen resolution. ie if the screen resolution is 640x480 then the x value can be in the range 0...639 and the y value 0....479.
The colour is returned in the colour variable you specified. For example:
// Create a color variable
COLOR my_color;
// Read pixel at 10,20
blackfinGetPixel(&camera,10,20, &my_color);
// Dump it out using rprintf.
rprintf("The pixel = ");

blackfinSetBinRange(BLACKFIN_CAMERA* camera, uint8_t bin, const COLOR* min, const COLOR* max)

Sets a colour bin on the camera to the specified range of colours.
A colour bin can be thought of as a palette of colours. The camera allows you to create 10 of these palettes and they are numbered from 0 to 9. Having defined one, or more, then they can be referenced from other commands by specifying the colour bin number.

uint32_t blackfinCountPixels(BLACKFIN_CAMERA* camera,uint8_t bin, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2)

Return the number of pixels in a rectangle that match a given colour bin.
The co-ordinates of the rectangle can be specified in any order you like ie it doesn't matter whether the first 'x' is the left or the right. We sort it out for you.

uint8_t blackfinDetectBlobs(BLACKFIN_CAMERA* camera, uint8_t bin)

Returns the number of blobs that match a given colour bin.
If there are no matches then it will return 0. Otherwise it may return up to 16 different blobs - sorted into order so that the largest one comes first, and the smallest one last.
Each blob can be returned with a call to blackfinFetchBlob.

const BLACKFIN_BLOB* blackfinFetchBlob(BLACKFIN_CAMERA* camera, uint8_t blobNo)

Returns a specific blob that was found using the last call to blackfinDetectBlobs.
The blob_no parameter starts at 0. The returned value points to a structure that will be filled in with the following details for the blob:

Valid XHTML 1.0 Transitional