Problems with Open-Source Downloads read and

QTransform::quadToQuad for QImage

  • I'll use the terms from:

    I seem to have some problem understanding this function. Iwould have expected, that the Points of polygone one end up at the coresponding points of polygone two. Here an extract of my source:
    QPolygonF quadQ, quadZ;
    quadQ <<mpkt1 <<mpkt2 << mpkt3 << mpkt4;
    int w=2500,h=1800;
    quadZ << QPointF(0,0) << QPointF(w,0) << QPointF(0,h) << QPointF(w,h);
    QTransform q2q;
    QImage target=source.transformed(q2q);

    The mpkts are QPoints  and are calculated before. They are:
    mpkt1 =(539,208)
    mpkt2 =(2921,196) 
    mpkt3 =(467,2119) 
    mpkt4 =(2966,2135) 
    So I would expect to find the part of the source image at (539,208) at the target image at (0,0), but it ends up at about (588,211), the others are where I would expect them relative to this on. So a translation of -588,-211 would solve the problem, but how do I get these parameters. Itried to transform the QPoint mpkt1 with the same transformation, but that gives me (0,0) as I would have expexted.
    Any idea?

  • Sometimes asking a question helps understand it So what seem to happen is, that the full source image is mapped to the target, not only the part of inside the polygone one.
    There it is:

    The transformation matrix is internally adjusted to compensate for unwanted translation; i.e. the image produced is the smallest image that contains all the transformed points of the original image. Use the trueMatrix() function to retrieve the actual matrix used for transforming an image.

    So now I have to find out how to either deactivate this adjustment or, bycomparing the two matrixes, to find out the added translation

  • So that the next one with the same problem finds a solution here.

    I added:

           qDebug() <<QImage::trueMatrix(q2q,source.width(),source.height()).dx();
           qDebug() <<QImage::trueMatrix(q2q,source.width(),source.height()).dy();
           qDebug() <<q2q.dy();
           qDebug() <<q2q.dx();

    and got

    The difference between these two (dx,dy) should be the added translation. so mpkt1 does not end up at (0,0) but at (0.68924+582.219,0.963701+208.209) =(583,209), which is what I observed.

Log in to reply