Go to Post Please teams I implore you obey the no saving seats rule. Or at least be very friendly in inviting people to sit with you. - IndySam [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-03-2014, 22:25
dougwilliams's Avatar
dougwilliams dougwilliams is offline
Engineer - Controls, Electronics
FRC #2053 (TigerTronics)
Team Role: Mentor
 
Join Date: May 2013
Rookie Year: 2013
Location: Vestal, NY
Posts: 109
dougwilliams is on a distinguished road
Image Threshold Always Returns Black Image - C++ / Vision / AXIS

We have been struggling to get hot goal detection working using vision processing. We have an AXIS camera mounted with green LED rings and looking at the live camera feed we see the tape light up nicely. We have gone through camera settings and in the code can dump the raw image file and we see an expected dulled green target in a very dark background.

No matter what we have tried we keep getting an all black image back from the threshold operation.

We originally had the camera settings "normal", and that did the same thing (except produced a standard light image of the target).

We have messed around with all sorts of threshold values and code tweaks and nothing seems to work.

We are command-based / C++ (and a snapshot of the code section is below). It should basically be the reference code.

Some other items that we have tried - included changing to various sets of HSL and HSV settings (the reference code says one thing, the description online says another...), changed the ColorImage to HSLImage with no luck. The printf's all go through so it's running the threshold operation, but doesn't give us anything useful.

Any ideas????


Code:
void AutonomousCommandN::Execute() {
	printf("Begin Auto Exe\n");
	switch(state){
	case 0:
	{
		printf("Case 0:\n");
	//	Scheduler::GetInstance()->AddCommand(new DriveForwardcommand(3.0));
		printf("Starting Autonomous");
		Scores *scores;
		TargetReport target;
		int verticalTargets[MAX_PARTICLES];
		int horizontalTargets[MAX_PARTICLES];
		int verticalTargetCount, horizontalTargetCount;
		Threshold threshold(104, 117, 221, 255, 139, 255);	//HSV threshold criteria, ranges are in that order ie. Hue is 60-100
		ParticleFilterCriteria2 criteria[] = {
				{IMAQ_MT_AREA, AREA_MINIMUM, 65535, false, false}
		};												//Particle filter criteria, used to filter out small particles
		AxisCamera &camera = AxisCamera::GetInstance();	//To use the Axis camera uncomment this line

		ColorImage *image;
		printf("Now creating new image.");
		//image = new RGBImage("/testImage.jpg");		// get the sample image from the cRIO flash

		image = camera.GetImage();


		Scheduler::GetInstance()->AddCommand(new AutoDriveandLowerGroup());

		
		image->Write("rawI.bmp");
		//To get the images from the camera comment the line above and uncomment this one
		BinaryImage *thresholdImage = image->ThresholdHSL(threshold);	// get just the green target pixels
		thresholdImage->Write("/threshold.bmp");
		BinaryImage *filteredImage = thresholdImage->ParticleFilter(criteria, 1);	//Remove small particles
		filteredImage->Write("Filtered.bmp");

		vector<ParticleAnalysisReport> *reports = filteredImage->GetOrderedParticleAnalysisReports();  //get a particle analysis report for each particle
  #2   Spotlight this post!  
Unread 13-03-2014, 12:16
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Image Threshold Always Returns Black Image - C++ / Vision / AXIS

If the libraries work the same for C++ as they do for LabVIEW, a BinaryImage has values of 0 and 1. If you use a normal color palette to view it, the image will consist of pixels that are either truly black or so dark as to appear black. Change the palette to distinguish clearly between those two values and you'll probably see what you expect.
  #3   Spotlight this post!  
Unread 13-03-2014, 15:11
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Image Threshold Always Returns Black Image - C++ / Vision / AXIS

Quote:
Originally Posted by Alan Anderson View Post
If the libraries work the same for C++ as they do for LabVIEW, a BinaryImage has values of 0 and 1. If you use a normal color palette to view it, the image will consist of pixels that are either truly black or so dark as to appear black. Change the palette to distinguish clearly between those two values and you'll probably see what you expect.
In C++ when you write a binary image (eg: filtered.bmp) the 1 pixels show up as red, 0 as black.
  #4   Spotlight this post!  
Unread 13-03-2014, 15:33
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Image Threshold Always Returns Black Image - C++ / Vision / AXIS

A few comments:

The NI Vision Assistant tool is really helpful for this; it will allow you to open a raw image on your PC and build and tune your filtering process.

I've observed (but haven't confirmed in code) that your first call to Camera::GetInstance() is what initiates your connection to the camera, however it takes some time before you can get an image; you should do this in DisabledInit to ensure that when auto begins, the camera has images ready. (we use a framerate of 5, so it could be due to this as well, but the delay seems > 1sec)

You don't have a convex hull operation; you will want to do this to combine smaller particles before you get particle reports.

You can use Paint.net to inspect the HSV values, this can at least give you a rough idea of the hue and saturation ranges to use (since you are currently using an HSL filter). Keep in mind the numeric ranges for paint.net are different from those in the threshold
(ie paint.net H range is 0 to 360, S range is 0 to 100, but I believe threshold is 0 to 255 for each).


If you are using 320x240 (lower resolution than the default 640x480), the default value for #define AREA_MINIMUM is not appropriate, you need to divide that value by 4 since the resolution is halved in each direction.

You don't show any delete operations in your code snippet, so the memory you use for each image is leaked/lost; not a major problem for one image, but it would be a problem if you run autonomous too many times. The following need to be deleted in if you are using the example code: image, thresholdImage, filteredImage, convexHullImage, reports, and scores. Scores should be deleted just before you leave the if condition where scores = New is called, filtered image and reports should be deleted at the end of your analysis, and the rest should be deleted after they are processed.

Last edited by DjScribbles : 13-03-2014 at 15:42.
  #5   Spotlight this post!  
Unread 14-03-2014, 23:38
dougwilliams's Avatar
dougwilliams dougwilliams is offline
Engineer - Controls, Electronics
FRC #2053 (TigerTronics)
Team Role: Mentor
 
Join Date: May 2013
Rookie Year: 2013
Location: Vestal, NY
Posts: 109
dougwilliams is on a distinguished road
Thumbs up Re: Image Threshold Always Returns Black Image - C++ / Vision / AXIS

Hey - thanks everyone...that was all helpful...

DJScribbles - I had only posted the first bunch of code until the threshold operation knowing it wasn't doing that, and figuring the rest didn't matter (yet).

Our software guy will follow up with a more detailed analysis of what was wrong for everyone once we're done with tomorrow ( he made the changes, I only hack at the software).

We were using paint.net previously, but didn't realize the 0-100 vs 0-255. And the divide by 4 as well.

Thanks for all the help, again!
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi