How to know coordinates in a real image from a scaled image

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-24 09:25:13

问题


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

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).

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?

Thanks in advance! Oscar.


回答1:


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);



回答2:


Use more decimal points, eg. 4.1484375 and 4.171875, otherwise you get 5px difference.




回答3:


Always use decimal points.Else you will get the shift Here also you can see

for x' = 512 * 4.14 = 2119.68 and y' = 768 * 4.17 = 3202.56

Here you are losing the coordinates. On which image you are drawing the line original or scaled? Thanks hope will help you...



来源:https://stackoverflow.com/questions/2988467/how-to-know-coordinates-in-a-real-image-from-a-scaled-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!