1

这是obj-C代码:

std::vector<Point2f> obj_corners(4);
obj_corners[0] = cvPoint(0,0);
obj_corners[1] = cvPoint(img_object.cols, 0 );
obj_corners[2] = cvPoint(img_object.cols, img_object.rows );
obj_corners[3] = cvPoint(0, img_object.rows );

std::vector<Point2f> scene_corners(4);
perspectiveTransform(obj_corners, scene_corners, H);

我想把它改成java。但是当我perspectiveTransform从文档中检查函数时,它变成Matvector

http://docs.opencv.org/java/org/opencv/core/Core.html#perspectiveTransform(org.opencv.core.Mat,%20org.opencv.core.Mat,%20org.opencv.core.Mat)

我怎样才能在 Java 中做同样的事情?谢谢。

4

1 回答 1

0

现在无法测试,但应该是这样的:

Mat result = getPerspectiveTransformation(scene_corners,W,H);//assuming you also have H somewhere

Mat getPerspectiveTransformation(Point[] points, int w, int h) {
  Point[] canonicalPoints = new Point[4];
  canonicalPoints[0] = new Point(w, 0);
  canonicalPoints[1] = new Point(0, 0);
  canonicalPoints[2] = new Point(0, h);
  canonicalPoints[3] = new Point(w, h);

  MatOfPoint2f canonicalMarker = new MatOfPoint2f();
  canonicalMarker.fromArray(canonicalPoints);

  MatOfPoint2f marker = new MatOfPoint2f(points);
  return Imgproc.getPerspectiveTransform(marker, canonicalMarker);
}
于 2013-08-23T12:02:21.797 回答