Sample Vision Code, ComputeThreshold() exception

So, our team is trying to get the sample vision code to work using the Axis M1011 camera, and we are getting a weird exception. As we step through the code, I’m finding that the cause (or at least where the error occurs) is when “image->ThresholdHSV(threshold)” is called.

By going into ColorImage.cpp we have found that the exception occurs on line 37 when “wpi_setImaqErrorWithContext(success, “ImaqThreshold error”)” is called. The value of success is 0, which I assume means it was successful but I’m not sure.

We have not tried this process with any images loaded onto the cRio. We can see the camera by viewing it on the Dashboard and/or in a web browser. The IP is set to 10.15.51.11.

Any help or suggestions would be much appreciated.

http://i.imgur.com/ikSVZIY.png

void Autonomous(void)
	{
		Threshold threshold(60, 100, 90, 255, 20, 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("10.15.51.11");	//To use the Axis camera uncomment this line
		
		while (IsAutonomous() && IsEnabled()) {
            /**
             * Do the image capture with the camera and apply the algorithm described above. This
             * sample will either get images from the camera or from an image file stored in the top
             * level directory in the flash memory on the cRIO. The file name in this case is "testImage.jpg"
             */
			ColorImage *image;
			//image = new RGBImage("/testImage.jpg");		// get the sample image from the cRIO flash

			camera.GetImage(image);				//To get the images from the camera comment the line above and uncomment this one
			BinaryImage *thresholdImage = image->ThresholdHSV(threshold);	// get just the green target pixels
			//thresholdImage->Write("/threshold.bmp");
...
...
BinaryImage *ColorImage::ComputeThreshold(ColorMode colorMode,
		int low1, int high1,
		int low2, int high2,
		int low3, int high3)
{
	BinaryImage *result = new BinaryImage();
	Range range1 = {low1, high1},
		range2 = {low2, high2},
		range3 = {low3, high3};
	
	int success = imaqColorThreshold(result->GetImaqImage(), m_imaqImage, 1, colorMode, &range1, &range2, &range3);
	wpi_setImaqErrorWithContext(success, "ImaqThreshold error");
	return result;
}

Have you seen the error readout on the driver station? I am having the same problem and get an error saying that the image is not large enough. Although I can’t use Windriver debugging or deploy code to the cRio through windriver and have an FTP workaround instead

I don’t recall noticing anything on the drivers station, that’s not to say I just didn’t see it. I will definitely check to see what the readout says next time though, which might not be until Thursday unless another member can give it a try. We had the net console up at the time and the program just quits with a fatal kernel task exception.

We also had a lot of problems getting the debugger to work properly. I somehow got it working but I did not change anything that I know of, it just started to work. We have the same configurations (as far as I could tell) on my laptop and another team laptop and only mine can actually debug without it terminating too early. It’s very frustrating. We can deploy new code fine, so that’s not the issue.

I don’t think this should matter but we over-installed WR with the 2013 version. We have updated workbench with both the 1/5 and 1/18 updates. We’ve gone through the documentation several times so I’m not sure why this is happening.

What errors do you get when you try to deploy code? You have the correct team number and x.out file selected correct?

The IMAQ functions being used are documented here … C:\Program Files (x86)\National Instruments\Vision\Documentation in the NIVisionCVI.chm file.

For the function imaqColorThreshold() it states that the return value is nonzero for success and zero for failure and states that imaqGetLastError() will give more detail. From what I see, that isn’t happening, so the error is simply a generic threshold failure.

There are several requirements documented for the original function. These requirement include that the image type of the dest is a U8, that the source is a three element color, either RGB or HS(LVI). From statically looking at the code fragments you attached, I see nothing wrong, which is why it would be key to see what the error code tells us.

Greg McKaskle

I don’t get an error, the code simply starts transferring and gets anywhere from 50%to 90%before it stops transferring. It does not actually load code onto the cRIO. We have everything configured properly and the communication exists because we can load our code via FTP. It’s an error somewhere in windriver’s deploy function.

Thanks for the suggestion. We will try calling imaqGetLastError() after success is set to 0. Once we do this, I’ll post an update with the error message.

there are two differences between “works” and “doesn’t work” configurations: 1) the working laptop had windriver updated to 2013 whereas the other had 2012 uninstalled and wiped then 2013 installed; and 2) the working laptop was talking to a 4 slot cRIO and the non-working to an 8 slot. either config will deploy and run code without the debugger.

I had the same issue. I ended up solving it by recreating the main part of the code manually in my own function and class. All the other functions were copied over directly.

Because I’m having a similar issue, the Driver Station Messages are as follows:

<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) Error in convex hull operation:  ...in ConvexHull() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 209
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) Error in convex hull operation:  ...in ConvexHull() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 209
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) Error in convex hull operation:  ...in ConvexHull() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 209
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) Error in convex hull operation:  ...in ConvexHull() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 209
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) Error in convex hull operation:  ...in ConvexHull() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 209
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) Error in convex hull operation:  ...in ConvexHull() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 209
IMAQ Vision:  Not an image.
<Code>-1074396120 ERROR: status = -1074396120 (0xBFF60428) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  Not an image.
Warning <Code> 44002 occurred at Ping Results:  link-GOOD,  DS radio(.4)-bad,  robot radio(.1)-GOOD,  cRIO(.2)-GOOD,  FMS-bad Driver Station
<time>1/23/2013 2:58:58 PM<unique#>7
FRC:  Driver Station ping status has changed.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396159 ERROR: status = -1074396159 (0xBFF60401) Error in convex hull operation:  ...in ConvexHull() in C:/WindRiver/workspace/WPILib/Vision/BinaryImage.cpp at line 209
IMAQ Vision:  Not enough memory for requested operation.

<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
Warning <Code> 44002 occurred at Ping Results:  link-GOOD,  DS radio(.4)-bad,  robot radio(.1)-GOOD,  cRIO(.2)-GOOD,  FMS-bad Driver Station
<time>1/23/2013 2:58:37 PM<unique#>6
FRC:  Driver Station ping status has changed.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.
<Code>-1074396154 ERROR: status = -1074396154 (0xBFF60406) ImaqThreshold error:  ...in ComputeThreshold() in C:/WindRiver/workspace/WPILib/Vision/ColorImage.cpp at line 37
IMAQ Vision:  The image is not large enough for the operation.

Those errors are far less mysterious. It looks like one of the images used in threshold and convex hull and the other calls hasn’t been allocated or has been closed or released before being used.

Inspect the code that creates the images that go into those calls.

Greg McKaskle

Last year, people had some issues with images that were valid pointers (I think), but had 0 width, and would crash (due to an exception). I used this guard code after getting the image, but before converting to a binaryImage.
Code:


if ((colorImage == (void *) 0) || (colorImage->GetWidth() == 0) || (colorImage->GetHeight() == 0))
{
return returnVal;
}

Similarly, you should check the binary image after it is created.

My full code is here: https://github.com/TeamExcel/Project.../Robot2012.cpp
Line 795 has the camera code.
Edit/Delete Message

We’re having a similar issue as the OP with a fatal exception on the Threshold line. We invoked GetWidth() on the image prior to the call and got a very large non-sensical value.

(Sorry about the reply in 2 similar threads , but I’m not sure if both are getting the same attention.)

We have tried a few different things and still haven’t figured out how to get valid images. We transfered some images to the cRio via ftp and used those and it worked fine. Whenever we use the camera it fails with the initial exception. We would like to call the imaqGetLastError(), but once the exception happens everything just blows up, even with try/catch.

It seems that the image we get from camera.GetImage() is not valid. As a few other posters have noted, the height and width seem ridiculously large with values in the range of 17 million. When we use the images loaded onto the cRio the sizes was 320x240.

We also didn’t notice any strange output on the DS when the errors occur.

](http://imgur.com/ZtJH1Wo)http://i.imgur.com/ZtJH1Wo.png

I have been using the 2013 Vision Code example and am getting the same errors. We are using an 8-slot cRIO and a computer that didnt have windriver on it previously.

When I load the example code, and switch it so that it pulls in the image from the camera, I get an error on the driver station diagnostics:

Warning <Code> 44002 ocurred at Ping Results: link-bad, DS radio(.4)-bad, robot radio(.1)-GOOD, cRIO(.2)-GOOD, FMS-bad Driver Station
<time>1/15/2013 1:00:55 AM>unique#>4
FRC: Driver Station ping status has changed.

(Our system clock and date are way off, ignore it)
Emphasis mine. Also, earlier when I tried to change the value of the Hue in the code so that it could be any Hue, as we are using a white light and don’t want just green, I got the same error message as the OP, in the Target Exception error box.

That’s not an error. It’s not really even a warning, even though it claims to be. It’s just a status indication. The important parts are “link”, “robot radio(.1)”, and “cRIO(.2)”. If the cRIO is listed as GOOD, that’s…well, good. If you’re using a wired connection, the link should be GOOD; if you’re using wireless, the robot radio should be GOOD.

Unless you’re using a separate router connected to the Driver Station (perhaps for better range or 5 GHz WiFi), the DS radio will show as bad, and that’s okay. The FMS will always show as bad until you’re actually plugged in to a competition field.

We are also having trouble getting an image using the sample vision code.

I am a complete newbie wrt the FRC competition, and doing my best to learn.

The camera.GetImage (image) function is not returning anything in image. The sample code does not initialize image, so it could point to garbage. The call to camera.GetImage (image) passes image by value so I don’t see how it could change image and in our tests it doesn’t appear to. Since it initially contains a garbage pointer, this might explain some of the errors people send when the code attempts to dereference the pointer.

I’ve tried to find/guess a way to initialize the pointer without success. The sample code doesn’t show any way to initialize it, so it’s very puzzling to me how it could work. The function documentation is not very information, and all the examples/help talks about what to do once you’ve obtained an image.

Any basic help would be appreciated.

I’m pretty sure it passes by pointer as this is the declaration in AxisCamera.h.

int GetImage(ColorImage *image);

It’s my understanding that calling this method will set the passed pointer which in this case is “image.” I agree with you that after calling this function, image does not appear to be valid.

My understanding is that it can change whatever image is pointing to, but to change image itself it needs a pointer/reference to the image variable itself.

Trying storing a known value in image before calling GetImage and then comparing that to the value on return.

ColorImage *image = NULL;
camera.GetImage (image);
SmartDashboard::PutString ("image changed", image == NULL ? "no" : "yes");

(Apologies in advance if I messed up the syntax/function calls. This is from memory. I hope you get the general idea.)

P.S. Don’t keep processing if image==NULL, the pointer dereference will cause an error.

In our tests, the value in image never changed.

I looked for other ways to initialize image but couldn’t find anything.

One thing I’ll try when I next get a chance on the robot will be to put the access to the test image back in and see if that will work as a workable initializer.

I have begun to try C++ and ran the 2013 vision example, but seem to be having a problem similar to what is described here.

I have not yet attempted to debug it much other than to know that the driver station crashes out starting with the following line when I’m trying to use the camera rather than trying the files.

BinaryImage *thresholdImage = image->ThresholdHSV(threshold);

I was hoping that someone would have posted a solution, but it’s not clear from the description here that there is one. However, I presume that someone figured this out before competition.

I have loaded the last update available and am using the M1011 camera.

If someone identified a clear solution would you please post it.

thanks.

BinaryImage *thresholdImage = image->ThresholdHSV(threshold);

It looks like you’re trying to create a pointer and store something in what it points to at the same time. That will write over an undefined area in memory. Or maybe you’re just setting it to something that won’t fit in a pointer, and thus overwriting memory that way?

Don’t do that.

Instead, declare the pointer, then allocate memory and set the pointer to point to the newly allocated memory. Only after that’s done can you dereference the pointer. Alternatively, you might want to create thresholdImage as a BinaryImage instead of a pointer to one.