I don't have the demo in front of me, but I have some test code that we wrote that was based on it. We moved some things around, so you'll have to do a little legwork to find the exact files that the corresponding code is in.
To detect elipses, the DetectEllipses of the MonoImage class is called from somewhere in the demo code
Code:
results = luminancePlane->DetectEllipses(&ellipseDescriptor,
&curveOptions, &shapeOptions,
roi);
If you look at the what DetectEllipses is doing, you'll see this among some other code
Code:
EllipseMatch *e = imaqDetectEllipses(m_imaqImage, ellipseDescriptor, curveOptions, shapeDetectionOptions, roi, &numberOfMatches);
This is the call to the IMAQ library that is doing the vision processing. If you look in nivision.h in the section where imaqDetectEllipses is defined, you'll see this prototype (kept the ellipse one here for reference)
Code:
IMAQ_FUNC EllipseMatch* IMAQ_STDCALL imaqDetectEllipses(const Image* image, const EllipseDescriptor* ellipseDescriptor, const CurveOptions* curveOptions, const ShapeDetectionOptions* shapeDetectionOptions, const ROI* roi, int* numMatchesReturned);
IMAQ_FUNC RectangleMatch* IMAQ_STDCALL imaqDetectRectangles(const Image* image, const RectangleDescriptor* rectangleDescriptor, const CurveOptions* curveOptions, const ShapeDetectionOptions* shapeDetectionOptions, const ROI* roi, int* numMatchesReturned);
So, you'll see that other than the second parameter, the calls are identical in terms of inputs.
So where does that leave you? What I would do is create a new class that inherits from MonoImage. I would do this in the team code instead of making the change directly in WPILib. This makes it easier to update WPILib in the future. In that class I would have a DetectRectangles method that mirrors what DetectEllipses is doing. Something like
Code:
class WsMonoImage : public MonoImage
{
vector<RectangleMatch> * MonoImage::DetectRectangles(
RectangleDescriptor *rectangleDescriptor, CurveOptions *curveOptions,
ShapeDetectionOptions *shapeDetectionOptions, ROI *roi);
};
vector<RectangleMatch> * WsMonoImage::DetectRectangles(
RectangleDescriptor *rectangleDescriptor, CurveOptions *curveOptions,
ShapeDetectionOptions *shapeDetectionOptions, ROI *roi)
{
// I'm just showing the IMAQ call here. You'll need to complete the implementation
RectangleMatch *e = imaqDetectRectangles(m_imaqImage, rectangleDescriptor, curveOptions, shapeDetectionOptions, roi, &numberOfMatches);
// more implementation would be here
}
As a C++ takeaway for the day, this demonstrates the importance of inheritance. The MonoImage does some things that are really good, but it doesn't quite do what we want and it's in a file that we don't really want to modify if we can avoid it. So, by using inheritance, we can make a class that does everything that MonoImage does plus what we want.
Good luck