Ask Your Question
0

Getting a point from a contour opencv android

asked 2013-04-13 16:41:17 -0600

Sofia gravatar image

updated 2013-04-18 14:58:40 -0600

Hi everyone !

I am trying to extract a point from a contour in opencv android, but I can't seem to find an equivalent for cvGetSeqElem, so I don't really know what to do. Here is my code :

            Imgproc.findContours(mGray, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
            Mat maxContour = contours.get(idx);

            for(int i=0; i< maxContour.total();i++)
            {
                Point v= ? //This is where I would write new Point(Imgproc.cvGetSeqElem(maxContour, i)) 
            }`

Does someone know the android equivalent for cvGetSeqElem? Or some other way to extract the points?

Edit : The question is solved. I just thought I would post the working code in case someone is interested. I get the biggest contour detected and extract the points from it :

          List<MatOfPoint>contours= new ArrayList<MatOfPoint>();
          Imgproc.findContours(mGray, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
          for (int idx = 0; idx < contours.size(); idx++) 
          {
                MatOfPoint contour = contours.get(idx);
                double contourarea = Imgproc.contourArea(contour);
                if (contourarea > maxContourArea) 
                {
                         maxContour = contour;
                         maxContourArea = contourarea;
                         maxAreaIdx = idx;
                }
          }

          points_contour = maxContour.toArray();
          nbPoints = points_contour.length; 

          for(int i=0; i< nbPoints;i++)
          {
                  Point v=points_contour[i];
          }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2013-04-16 01:38:14 -0600

With the function findContours, contours parameter is a MatOfPoint, therefore, with toArray, you can use the points stored:

int nbPoints = contours.length();
Point points = contours.toArray();
for( int i = 0 ; i < nbPoints ; ++i )
{
    Point v = points[i];
}

See the doc here and here.

edit flag offensive delete link more

Comments

Thanks for your answer ! It helped me out a lot !

Sofia gravatar imageSofia ( 2013-04-18 15:01:37 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-04-13 16:41:17 -0600

Seen: 7,021 times

Last updated: Apr 18 '13