Raw Camera Data

I’ve been dabbling in the camera inputs, as our team’s mechanism is finally starting to come together, and I’ve noticed the color tracking that either NI or WPI set up (Not sure who the code is coming from) is very crudely written. Does anyone know of a way to get the raw data from the camera (preferably like a two-dimensional array of ints with rgb data)? I have written code to filter out blobs of known colors (And it works with pretty much any color, not just the bright pinks and greens for this), though I have yet to find a way to define their bounds without just averaging the position of each pixel of a given color. All I need is that array.

Thanks for your help

If you look into the nivision.h file, you should find something to extract pixel integers from the image file. Sorry I can’t be more helpful, but I don’t have the C tools installed on this computer. But it exists in LV, so I know it exists in C. If you are looking to do the comparisons in RGB, I’d encourage you to compare it against the color tracking in the WPI or nivision file. The nivision stuff is going to be hard to beat for standard algorithms like color thresholds. Second, I think you’ll find that the algorithm will be far more resilient using HSL math.

Greg McKaskle

I’m using an algorithm I designed from scratch that doesn’t use thresholds. And my algorithm uses an HSV derived colorspace, slightly diffent than HSL but I believe it to be more effective. We’ll see how it works though, and thanks for the heads up.

Sounds good so far. I’m curious to hear how it goes, and more about details.

Greg McKaskle

Maybe you are looking for
void* imaqImageToArray(const Image* image, Rect rect, int* columns, int* rows);
although it doesn’t show hsv

take a look in C:\WindRiver\docs\extensions\NIVisionCVI.chm it describes all the functions as well as the data structures etc.

Thanks, I’ll take a look at it at our team’s meeting today, and that it doesn’t show HSV is a good thing. Calculating HSV from RGB is a tad expensive, notably the hue component, so we are going to avoid that until we need it.

typedef struct {
	float r; /* Range of [0,1] */
	float g;
	float b;
} Colorf;

float maxRGB ( Colorf* input )
{
	return ( input->r > input->b && input->r > input->g )? input->r : ( input->b > input->g )? input->b : input->g;
}

float minRGB ( Colorf* input )
{
	return ( input->r < input->b && input->r < input->g )? input->r : ( input->b < input->g )? input->b : input->g;
}

angle hue ( Colorf* input )
{
	float maxvalue = maxRGB( input );
	float minvalue = minRGB( input );
	if ( maxvalue == 0 ) return 0;
	else if ( maxvalue == input->r ) return ( ( LAMBDA / 3 ) * ( ( input->g - input->b ) / ( maxvalue - minvalue ) ) + ( 2 * LAMBDA ) );
	else if ( maxvalue == input->g ) return ( ( LAMBDA / 3 ) * ( ( input->b - input->r ) / ( maxvalue - minvalue ) ) + ( 2 * LAMBDA / 3 ) );
	else return ( ( LAMBDA / 3 ) * ( ( input->r - input->g ) / ( maxvalue - minvalue ) ) + ( 4 * LAMBDA / 3 ) );
}

float sat ( Colorf* input )
{
	if ( input->r == 0 && input->g == 0 && input->b == 0 ) return 0;
	return 1 - maxRGB( input ) - minRGB( input );
}

#define val maxRGB

Here’s a quick thing on how to do the conversions I wrote last night in C, since C is arguably faster than C++ (though my float calculations don’t help much XD). I was going to change this to use unsigned chars, and if I get around to it (In my free time, when such a thing exists again) handwrite a library in assembly to do it as fast as possible. Though I’m not too terribly concerned. We haven’t had a problem with processing on the cRIO yet this year. Thanks again for your help.

Okay, today at our meeting we looked at that, and it looks like what we need, but we have been unable to figure out how to get the Image object we need. Do you know how to get this data?

I’d also like to get a bit more help on how to go about getting RGB and coordinates for pixels…I’ve worked with OpenCV before and my approach to programming the bot is influenced by that…My experience with object oriented programming is limited and the User Guide is helpful, but exhausting. I’d find it easier to get some raw data and make my own functions.

In case you want to use it, the NI libraries already include HSL and HSV conversions. The color threshold in the examples is already being done in HSL.

And if you want the raw stuff imaqImageToArray() will get it for you.

Greg McKaskle