Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Sample Vision Code, ComputeThreshold() exception (http://www.chiefdelphi.com/forums/showthread.php?t=111644)

bmbroom 26-01-2013 23:11

Re: Sample Vision Code, ComputeThreshold() exception
 
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.

Pulverator 27-01-2013 01:21

Re: Sample Vision Code, ComputeThreshold() exception
 
Quote:

Originally Posted by bmbroom (Post 1222560)
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'm pretty sure it passes by pointer as this is the declaration in AxisCamera.h.
Code:

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.

bmbroom 27-01-2013 02:09

Re: Sample Vision Code, ComputeThreshold() exception
 
Quote:

Originally Posted by Pulverator (Post 1222616)
I'm pretty sure it passes by pointer as this is the declaration in AxisCamera.h.
Code:

int GetImage(ColorImage *image);
It's my understanding that calling this method will set the passed pointer which in this case is "image."

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.
Code:

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.

Rabell 18-09-2013 10:06

Re: Sample Vision Code, ComputeThreshold() exception
 
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.

Alan Anderson 18-09-2013 11:28

Re: Sample Vision Code, ComputeThreshold() exception
 
Code:

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.


All times are GMT -5. The time now is 14:25.

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