5

如果我有一个Mat大小为 960*720 的图像对象(OpenCV),我已经计算了一个Point对象的坐标,然后我缩放这个 Mat 图像,它的新大小是 640*480,我怎样才能找到新的的坐标Point

4

2 回答 2

1

(x,y)原始矩阵中的一个点将通过以下方式映射到(x',y')新矩阵中

(x',y') = 2*(x,y)/3.

将其简化为 OpenCV 函数,我们有:

cv::Point scale_point(cv::Point p) // p is location in 960*720 Mat
{
    return 2 * p / 3;   // return location in 640*480 Mat
}
于 2013-06-26T14:08:02.827 回答
0

我最终做的是创建一个ScaledPoint扩展的对象Point。这样,它对我已经使用纯Point对象的代码的破坏性较小。

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);
于 2017-06-28T14:44:51.143 回答