如果我有一个大小为960*720的 Mat
图像对象(OpenCV),我已经计算出了一个 Point
对象的坐标,然后我对这个 Mat 图像进行了缩放,它的新尺寸是640*480,那么我该如何找到 Point
的新坐标呢?
原矩阵中的点 (x,y)
将被映射到新矩阵中的 (x',y')
,其规则如下:
(x',y') = 2*(x,y)/3.
cv::Point scale_point(cv::Point p) // p is location in 960*720 Mat
{
return 2 * p / 3; // return location in 640*480 Mat
}
public class ScaledPoint extends Point {
public ScaledPoint (double[] points, double scale) {
super(points[0] * scale, points[1] * scale);
}
}
然后,我计算了一个缩放因子,并在我扩展的类中使用它:
Mat originalObject;
// TODO: populate the original object
Mat scaledObject;
// TODO: populate the scaled object
double scaleFactor = scaledObject.getHeight()/(double)originalObject.getHeight();
matOfSomePoints = new Mat(4,1, CvType.CV_23FC2);
// TODO: populate the above matrix with your points
Point aPointForTheUnscaledImage = new Point(matOfSomePoints.get(0,0));
Point aPointForTheScaledImage = new ScaledPoint(matOfSomePoints.get(0,0), scaleFactor);