LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Evaluating Change in an Image

I am a programmer on FRC robotics team 1257, and I need to write some custom image analyzation code.  I want to loop through two slighlty different images and find the average x position of the change in green between the images.  I also want the average color of the area that changed (that part works).

 

// info1 and info2 contain valid data

rgb* pixelImage1 = (rgb*)info1.imageStart;
rgb* pixelImage2 = (rgb*)info2.imageStart;
	

for(int y = 0; y < info1.yRes; y++)
{
	pixelImage1 += 5;
	pixelImage2 += 5;
	for(int x = 5; x < info1.xRes; x++)
	{
		// Do the processing
		if((int)pixelImage2->green - (int)pixelImage1->green > 150) 
		{
			if(y < 120)
			{
				if(pixelImage2->green > 70 && pixelImage2->red < 150 && pixelImage2->blue < 150)
				{
					averagePosX += x;
					red += (int)pixelImage2->red;
					green += (int)pixelImage2->green;
					blue += (int)pixelImage2->blue;
						
					total++;
				}
			}
		}
		////////////
		pixelImage1++;
		pixelImage2++;
	}
	pixelImage1 += info1.pixelsPerLine - info1.xRes + 5;
	pixelImage2 += info2.pixelsPerLine - info2.xRes + 5;
}

 rgb is a struct that looks like this:

struct rgb
{	
	unsigned char blue;
	unsigned char green;
	unsigned char red;
	unsigned char alpha;
};

 

Any help you can offer would be appreciated.  Again, we are finding the color correctly, but the x value (averagePos) is definitely wrong.  The nested if statements are just restrict our search in the image.

0 Kudos
Message 1 of 2
(2,631 Views)

Hi soystuff,

 

For all FRC related questions, you will want to use http://www.ni.com/frc

 

Click on the Discussions Tab to post questions relating to LabVIEW, FRC, and any of the utilities. If you are looking for help relating with C++ or Java, then you will want to use the corresponding forums for these languages. For example, http://www.chiefdelphi.com/forums/portal.php has a really good C++/Java community. In addition, US FIRST has a really good list of technical resources available for C++/Java programmers here: http://www.usfirst.org/roboticsprograms/frc/2013-Technical-Resources

 

Sincerely,

 

 

Aldo A
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(2,607 Views)