Quote:
Originally Posted by pentrium
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.