Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]How to save pixmap's transformation matrix as ".txt"
Qt 6.11 is out! See what's new in the release blog

[solved]How to save pixmap's transformation matrix as ".txt"

Scheduled Pinned Locked Moved General and Desktop
16 Posts 2 Posters 6.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venkatesh
    wrote on last edited by
    #5

    hi,
    I have tried the following inserting the expression inside the for loop. But again the application gets crashed when i execute. I am puzzled where i am getting wrong.

    @

    for(int j=0;j<height;j++)
    {
    for (int i=0;i<width;i++)
    {
    *matrix[width][height]=qGray(img.pixel(i,j));
    QFile file("/Users/venkateshpadmanabhan/Desktop/out1.txt");
    file.open(QIODevice::WriteOnly);
    QTextStream tex(&file);
    tex<<matrix;
    file.close();

                                endl(tex);
                           }
    
                       }
    

    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Line 5: why the * ?

      Anyway: why the matrix variable ? It's useless since you get the pixel value from the image.

      Also why do you reopen the file on each iteration ?

      And why the call to endl(tex) after the file has been closed ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        venkatesh
        wrote on last edited by
        #7

        Hi,

        Thanks for your response, i could get a text file which has the color information of the pixels. The code

        @

        QPixmap p(scn3->width(),scn3->height());
        QPainter paint(&p);
        scn3->render(&paint);
        QImage img=p.toImage();
        int width=img.width();
        int height=img.height();
        QFile file("/Users/venkateshpadmanabhan/Desktop/out1.txt");
        file.open(QIODevice::WriteOnly);
        QTextStream tex(&file);
        for(int j=0;j<height;j++)
        {
        for (int i=0;i<width;i++)
        {
        int s=img.pixel(i,j);
        //matrix[width][height]=qGray(img.pixel(i,j));
        tex<<s;

                               endl(tex);
        

        //
        }

                           }
        
                file.close();
        

        @

        This works fine, but what i wanted to get is @ TransformationMatrix @ of the pixmap in a scene and convert it as a readable format like int and save it to a .txt file. But i couldn't trace how to convert the transformation matrix into Int or anything which could be accepted by @ QTextStream @

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #8

          Again, what is the use of your matrix variable ?

          Do you set that transformation somewhere ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • V Offline
            V Offline
            venkatesh
            wrote on last edited by
            #9

            Hi,

            Sorry i forgot to comment the line for the matrix, i have done that. But the problem comes when i access the transformation which i have done in

            @QGraphicsPixmapItem@

            In this case i try to access it by

            @ QTransform mat=itm2->transform();
            mat=QPixmap::trueMatrix(mat,scn3->width(),scn3->height());@

            But the problem is i am not sure how to set the @QTransform@ into the Text Stream for storing the transformation as @Matrix@ in ".txt" file, as i did for the color information of a pixmap

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #10

              You have to do it by hand. Meaning create your text representation of each element of the QTransform (you can get inspiration from the qDebug() stream or QDataStream operator of QTransform)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • V Offline
                V Offline
                venkatesh
                wrote on last edited by
                #11

                Hi,
                Can you suggest me some example?... I tried to find some reference idea how to implement it. But i couldn't find it any where :( I just tried

                @
                QDataStream<<QTransform(trans);
                @

                Is there anyway to convert the @QTransform@ into int? or any other data format to push it into QTextStream.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  Not int, qreal or you'll loose information.

                  You can retrieve all the transform parameters using the mXX functions

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    venkatesh
                    wrote on last edited by
                    #13

                    Hi,

                    I tried to convert the QTransform into QVariant and again into qreal and pass it into QTextStream but some how it doesn't seam to work. I guess my casting is wrong ....
                    @

                    QTransform mat=itm2->transform();
                    mat=QPixmap::trueMatrix(mat,scn3->width(),scn3->height());
                    QVariant qv(mat);
                    qreal re=qv.toReal();
                    QFile file("/Users/venkateshpadmanabhan/Desktop/out2.txt");
                    file.open(QIODevice::WriteOnly | QIODevice::Text);
                    QTextStream data(&file);
                    data<<re;
                    endl(data);
                    @

                    Is this conversion method wrong?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      Yes it is, you are expecting a matrix to be somehow transformed in one qreal value.

                      As I wrote before, take each parameter of the QTransform and write it to your text file.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        venkatesh
                        wrote on last edited by
                        #15

                        Hi,

                        I have done as per your suggestion. But i am not sure whether it is correct. Is there any method to verify its reliability??

                        @

                        QTransform mat1=itm2->transform();
                        QTransform mat=QPixmap::trueMatrix(mat1,scn3->width(),scn3->height());

                        mat.dx();
                        mat.dy();

                            mat.m11();
                            mat.m12();
                            mat.m13();
                            mat.m21();
                            mat.m22();
                            mat.m23();
                            mat.m31();
                            mat.m32();
                            mat.m33();
                        
                            QVariant QV(mat.dx());
                            QVariant QV1(mat.dy());
                        

                        QVariant qv(mat.m11());
                        QVariant qv1(mat.m12());
                        QVariant qv2(mat.m13());
                        QVariant qv3(mat.m21());
                        QVariant qv4(mat.m22());
                        QVariant qv5(mat.m23());
                        QVariant qv6(mat.m31());
                        QVariant qv7(mat.m32());
                        QVariant qv8(mat.m33());
                        qreal re=qv.toReal();
                        qreal re1=qv1.toReal();
                        qreal re2=qv2.toReal();
                        qreal re3=qv3.toReal();
                        qreal re4=qv4.toReal();
                        qreal re5=qv5.toReal();
                        qreal re6=qv6.toReal();
                        qreal re7=qv7.toReal();
                        qreal re8=qv8.toReal();

                        qreal RE=QV.toReal();
                        qreal RE1=QV1.toReal();

                        QFile file("/Users/venkateshpadmanabhan/Desktop/out2.txt");
                        file.open(QIODevice::WriteOnly | QIODevice::Text);
                        QTextStream data(&file);
                        data<<re;
                        data<<re1;
                        data<<re2;

                        endl(data);

                        data<<re3;
                        data<<re4;
                        data<<re5;

                        endl(data);

                        data<<re6;
                        data<<re7;
                        data<<re8;

                        endl(data);

                        data<<RE;
                        data<<RE1;

                        endl(data);
                        file.close();

                        @

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #16

                          Why are you converting everything back and forth ?

                          just do:

                          @data << mat.m11()
                          << mat.m12 etc...@

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved