How to find coordinates in a real image using a scaled image

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

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

I am trying to find out the coordinates (x ', y') in the original image when I get the coordinates in the scaled image (x, y). I use the formula: x '= x * rw and y' = y * rh . But when I draw a line, or a rectangle there is always a shift that increases when x or y is higher.

Please, does anyone know how to convert coordinates without losing accuracy?

Thanks in advance! Oscar.

+3
c ++ math qt image coordinates
source share
3 answers

Or you can use QTransform :: quadToQuad to create a transformation and use it to match points, rectangles, 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); 
+4
source share

Use more decimal points, for example. 4.1484375 and 4.171875, otherwise you will get a difference of 5 pixels.

+2
source share

Always use decimal points. You will get a shift. Here you can also see.

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

Here you lose your coordinates. In which image do you draw the line original or scaled? Thank you, hope helps you ...

+1
source share

All Articles