Ask Your Question

CvInvoke.cvContourArea in c#, Emgu

asked 2013-10-24 20:26:36 -0600

fred gravatar image

updated 2013-10-25 02:47:46 -0600

Hi, I am using C# to find the area within a contour and need help translating c/c++ code as found in the following example: Unfortunately, C#, Emgu does not support vectors.

vector<Point> contour;
contour.push_back(Point2f(0, 0));
contour.push_back(Point2f(10, 0));
contour.push_back(Point2f(10, 10));
contour.push_back(Point2f(5, 4));

double area0 = contourArea(contour);
vector<Point> approx;
approxPolyDP(contour, approx, 5, true);
double area1 = contourArea(approx);

cout << "area0 =" << area0 << endl <<
        "area1 =" << area1 << endl <<
        "approx poly vertices" << approx.size() << endl;

Thx, Fred.

edit retag flag offensive close merge delete



Since @Luca Del Tongo has made the effort to post an answer I will keep it open for some replying. However, keep in mind that EmguCV is not an official supported OpenCV package and that questions about it should be posted at the correct supporting EmguCV forum.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-25 03:04:56 -0600 )edit

Given that it was quite simple to reply to this question I did it :-) Feel free to delete it as it's not related to opencv and break site rules...

Luca Del Tongo gravatar imageLuca Del Tongo ( 2013-10-25 06:00:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-10-25 02:34:20 -0600

Luca Del Tongo gravatar image

You should use EmguCv classes and C# features. Here is a small toy example that replicate what you want to do :

         using (MemStorage storage = new MemStorage()) //allocate storage for contour approximation         
         Contour<Point> contour = new Contour<Point>(storage);

             contour.Push(new Point(0, 0));
             contour.Push(new Point(0, 10));
             contour.Push(new Point(10, 10));
             contour.Push(new Point(10, 0));

         double area0 = contour.Area;
         Contour<Point> approxContour = contour.ApproxPoly(contour.Perimeter * 0.05, storage);

Hope this helps, Luca

edit flag offensive delete link more

Question Tools


Asked: 2013-10-24 20:26:36 -0600

Seen: 4,545 times

Last updated: Oct 25 '13