|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ImaqThreshold error
Everytime we try and run binaryImage = camera.GetImage()->ThresholdHSL(huemin,huemax, saturationmin....) we get an ImaqThreshold error: -1074396154 in the driver station. Is it beause of the image that its receiving from the camera or the threshold itself and how can we solve it?
|
|
#2
|
|||
|
|||
|
Re: ImaqThreshold error
I can't say for sure without seeing your code, but my guess is that you aren't deleting your binary image (and color image if your calling new for it), and so you end up running out of memory pretty quickly and the threshold function cannot allocate memory for new binary images.
|
|
#3
|
||||
|
||||
|
Re: ImaqThreshold error
Quote:
Code:
HSLImage* AxisCamera::GetImage()
{
HSLImage *image = new HSLImage();
GetImage(image);
return image;
}
Code:
HSLImage *cameraImage = camera.GetImage(); BinaryImage *binaryImage = cameraImage->ThresholdHSL(.....); ... ... delete binaryImage; delete cameraImage; Regarding your error, the above probably doesn't address that. It is probably related to how you created the camera object. So you need to post the code surrounding it too. Last edited by mikets : 02-02-2012 at 20:29. |
|
#4
|
||||
|
||||
|
Re: ImaqThreshold error
Aside from posting code, there are some generally good things to do which will also help diagnose...
a) After getting an image from GetImage, check to see if the pointer is non-null. b) If it's non-null, check that image->GetHeight() and image->GetWidth() are non-zero. I've seen other threads where zero sized images come back if the brightness is zero and things are rather dark. c) Use GetError() to get the error back from WPILib and validate the reason via Code and Description. in pseudo-code from the office... Code:
while (IsOperatorControl())
{
HSLImage* image = camera.GetImage();
if (image)
{
if (image->GetHeight() && image->GetWidth())
{
// Now go forward with using image->Threshold operations
}
else
printf("image has zero width or zero height. Hmm\n");
delete image;
}
else
printf("NULL Image returned. Hmm.\n");
}
|
|
#5
|
||||
|
||||
|
Re: ImaqThreshold error
According to the WPI source code, I believe it is impossible to get a NULL image pointer unless you are totally running out of memory. However, it is always a good practice to check for NULL anyway to guard against unforeseen circumstances. But it is true that you should check for zero image height and width because the camera needs some time to boot and you could "acquire" an image while the camera is not ready. Although you get a valid image pointer, there is really no image yet.
Last edited by mikets : 03-02-2012 at 14:11. |
|
#6
|
||||
|
||||
|
Re: ImaqThreshold error
Interestingly, I am trying to figure out what happened to GetHeight() and GetWidth if the camera is not ready. According to the source code:
Code:
/**
* Gets the height of an image.
* @return The height of the image in pixels.
*/
int ImageBase::GetHeight()
{
int height;
imaqGetImageSize(m_imaqImage, NULL, &height);
return height;
}
/**
* Gets the width of an image.
* @return The width of the image in pixels.
*/
int ImageBase::GetWidth()
{
int width;
imaqGetImageSize(m_imaqImage, &width, NULL);
return width;
}
|
|
#7
|
||||
|
||||
|
Re: ImaqThreshold error
MikeTS,
Two items -- 1) while it is true that GetImage should not fail, the memory (out of memory) situation is exactly why you SHOULD check it. 2) Regarding the height/width item...I totally agree. I think the right thing to do would be to file a bug report on WPILib so that they could do "int height=0;" or "int height=-1;" at declaration in case the imaq call fails. bob |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|