Hello, we want to start modifying the 2010 image demo on windriver. We want to make it so that the robot detects a square instead of a circle. How would we do that and where would we change the code?
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
results = luminancePlane->DetectEllipses(&ellipseDescriptor,
&curveOptions, &shapeOptions,
roi);
If you look at the what DetectEllipses is doing, you’ll see this among some other 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)
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
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
I’m sorry but how would we make the implementations and of what would we implement.
Look at DetectEllipses inside MonoImage.cpp. That should be the foundation for your DetectRectangles. Just copy/paste the entire guts of DetectEllipses into DetectRectangles. At this point, all you need to do is replace references to ellipse with rectangle. The EllipseMatch will become RectangleMatch. The vector type will change, the vector variable name should be changed to rectangles.
Along the way, I would suggest reading and understanding exactly what the function is doing. That’s the only way you’ll really learn. Copy/Paste never taught anybody anything.
Give that a shot and if you really can’t figure it out, send me a PM and I’ll clarify more.
Hey, thanks for the info on this thread, but how do you access the MonoImage.cpp file? We’re having trouble finding it.
Thanks.
It’s now 2012. The thread is about code from two years ago.
If your just getting started with the 2010 Image Demo, I would recommend updating your WPILib and using the new 2012 image demo sample.
See: http://www.chiefdelphi.com/forums/showthread.php?t=101991
I understand that this is the code from 2010, but our team was considering examining this image demo to understand how to detect the squares above the goals this year. We have the 2010 image demo, how can we access the MonoImage.cpp file? Or are you saying that this is not a good way to go about image tracking?
There is a new vision sample for 2012. If you have installed the latest update (http://firstforge.wpi.edu/sf/frs/do/…2_update_for_c), you will see the vision tracking sample.
Wow, this helps… Thanks guys! (Sorry if I caused any facepalms)
Actually I thank you, cause I want to get the camera working and didn’t know there is a 2012 sample! I thought I would have to change it around when I don’t even understand how to do it on my own.
Thanks!