Java to C++
Can someone convert this Java method to C++, I tried but can't figure it out.
private Mat rectifyCard(Mat image, MatOfPoint contour) {
MatOfPoint2f card2f = new MatOfPoint2f(contour.toArray());
double peri = Imgproc.arcLength(card2f, true);
MatOfPoint2f approx = new MatOfPoint2f();
Imgproc.approxPolyDP(card2f,approx, 0.02*peri, true);
log("=========================");
Point tmp = approx.toList().get(0);
boolean shouldRotate = false;
int i = 0;
for(Point p : approx.toList()) {
if(tmp.x + tmp.y > p.x + p.y) {
shouldRotate = true;
break;
}
i ++;
}
if (shouldRotate) {
log("shouldRotate");
List<Point> list = approx.toList();
Point[] points = {list.get(1), list.get(2), list.get(3), list.get(0)};
approx.fromArray(points);
}
Mat transform = getPerspectiveTransformation(loadPoints(approx.toArray()));
Mat result = new Mat(CARD_WIDTH, CARD_HEIGHT, CvType.CV_8UC1);
Imgproc.warpPerspective(image, result, transform, new Size(CARD_WIDTH, CARD_HEIGHT));
// Highgui.imwrite(EDIT_PATH, result);
// displayPhoto(EDIT_PATH);
return result;
}
Thanks