[Interest] Understanding QImage::transformed()

Jason H jhihn at gmx.com
Fri Dec 14 22:49:46 CET 2018

I have an image. I have identified 4 control points in in image (1920x1080).
I want to map the points to a square image, of 1080 on a side.

QPolygonF fromPoly(QVector<QPointF> { ... });
QPolygonF toPoly(QVector<QPointF> {QPoint(squareDimension/2, 0), QPoint(squareDimension, squareDimension/2), QPoint(squareDimension/2, squareDimension), QPoint(0, squareDimension/2)});

Where the toPoly maps to [(960,0), (1080,960), (960,1080), [0, 960)]

QTransform tx;
if (QTransform::quadToQuad(fromPoly, toPoly, tx)) {
	out = image.transformed(QImage::trueMatrix(tx, image.width(), image.height()));
	qDebug() << out.save("sdsd1.jpg");
	out = out.copy ((out.width() - squareDimension)/2,(out.height() - squareDimension)/2, squareDimension, squareDimension);
	qDebug() << out.save("sdsd2.jpg");

But out is (3270x2179);
The control points match up a square in that out image of 1600x1600, which is not right. No matter what I do, using trueMatrix() or not, when I crop the image to 1080x1080, it is too zoomed in.

What do I need to go to get all the control points to fit into an image of 1080x1080? Imagine an image (1920x1080) of a clock with some perspective skew. I identify 12,3, 6, and 9 hour positions. I want to create an image of the clock without perspective skew, that is to say, a face-on approximation of the clock.


More information about the Interest mailing list