Search code examples
opencvjavacvjavacpp

Create input for cvContourArea in JavaCV


How to create the contour to pass to cvContourArea? I have four 2D points, but don't know to create the CvSeq.

int[] myPolygon = new int[] { point1.x, point1.y, point2.x, point2.y, ... };
cvCountourArea(???, null, 0);

Solution

  • I found the solution:

    int[] myPolygon = new int[] { point1.x, point1.y, point2.x, point2.y, ... };
    Mat rectMat = cvCreateMat(1, myPolygon.length/2, CV_32SC2);
    rectMat.getIntBuffer().put(myPolygon);
    cvCountourArea(rectMat, CV_WHOLE_SEQ, 0);
    cvReleaseMat(rectMat);