Go to Post How many robotics kids does it take to turn on a light? - demosthenes2k8 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-02-2012, 16:19
pentrium pentrium is offline
Registered User
FRC #1075
 
Join Date: Jan 2012
Location: Whitby
Posts: 5
pentrium is an unknown quantity at this point
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 02-02-2012, 14:29
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: 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.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2012, 20:18
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: ImaqThreshold error

Quote:
Originally Posted by pentrium View Post
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?
You guys have to be careful on how you write this code. When in doubt check the source code in the WPI library. For example, the AxisCamera::GetImage() code is:
Code:
HSLImage* AxisCamera::GetImage()
{
        HSLImage *image = new HSLImage();
        GetImage(image);
        return image;
}
Notice that this function instantiated an HSLImage object. Since your code is directly using the returned HSLImage object to call its ThresholdHSL method and not saving the HSLImage pointer at all. This means you never free the HSLImage object. Instead, your code should look like this:
Code:
HSLImage *cameraImage = camera.GetImage();
BinaryImage *binaryImage = cameraImage->ThresholdHSL(.....);
...
...
delete binaryImage;
delete cameraImage;
The rule is: every new must be matched with a delete. So when calling a method that returns a pointer, you need to ask yourself that where that pointer comes from? If it is just returning a reference (such as GetInstance) and somebody is responsible for freeing it, you are fine. Otherwise, if the method created the object and did not keep a copy of it, you are responsible for freeing the object after you are done with it.

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.
Reply With Quote
  #4   Spotlight this post!  
Unread 03-02-2012, 13:55
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
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");
}
bob
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #5   Spotlight this post!  
Unread 03-02-2012, 14:04
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 03-02-2012, 14:18
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
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;
}
Both height and width are uninitialized local variables and imaqGetImageSize could have failed. Since there is no source code to the nivision module so I can't tell if width and height will be zero initialized and both the GetHeight and GetWidth function do not check the return code of imaqGetImageSize.
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 03-02-2012, 15:33
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
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
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
Reply


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 03:04.

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