Thread: Raw Camera Data
View Single Post
  #6   Spotlight this post!  
Unread 26-01-2009, 10:43
WatersongX WatersongX is offline
Registered User
AKA: Matthew Keen
FRC #1111 (Powerhawks)
Team Role: Programmer
 
Join Date: Feb 2008
Rookie Year: 2006
Location: Edgewater, MD
Posts: 7
WatersongX is an unknown quantity at this point
Send a message via AIM to WatersongX
Re: Raw Camera Data

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.

Code:
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.
Reply With Quote