如何从缩放的图像知道真实图像中的坐标 [英] How to know coordinates in a real image from a scaled image

查看:404
本文介绍了如何从缩放的图像知道真实图像中的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先感谢您阅读我的问题: - )

First of all thanks for your time reading my question :-)

我有一个原始图片(w':2124,h':3204) (w:512,h:768)。宽度比为4.14(rw),高度比为4.17(rh)。

I have an original image (w': 2124, h': 3204) and the same image scaled (w: 512, h: 768). The ratio for width is 4.14 (rw) and the ratio for height is 4.17 (rh).

当我收到缩放图像(x,y)中的坐标时,我想知道原始图像中的坐标(x',y')。我使用的公式为: x'= x * rw y'= y * rh 。但是,当我画一条线时,或者矩形总是出现一个移动,当 x y 更高时会增加。

I'm trying to know the coordinates (x', y') in the original image when I receive the coordinates in the scaled image (x, y). I'm using the formula: x' = x * rw and y' = y * rh. But when I'm painting a line, or a rectangle always appears a shift that is incremented when x or y is higher.

请大家知道如何在不损失准确度的情况下变换坐标?

Please anybody knows how do I transform coordinates without losing accuracy?

提前感谢!
Oscar。

Thanks in advance! Oscar.

推荐答案

或者您可以使用 QTransform :: quadToQuad 创建一个变换,并使用它来映射点,矩形,线等:

Or you can use QTransform::quadToQuad to create a transform and use it to map points, rects, lines, etc.:

QVector<QPointF>    p1;
p1 << scaledRect.topLeft() << scaledRect.topRight() << scaledRect.bottomRight() << scaledRect.bottomLeft();
QVector<QPointF>    p2;
p2 << originalRect.topLeft() << originalRect.topRight() << originalRect.bottomRight() << originalRect.bottomLeft();
QTransform::quadToQuad(p1, p2, mappingTransform);
...
QPointF originalPoint = mappingTransform.map(scalePoint);

这篇关于如何从缩放的图像知道真实图像中的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆