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. QDataStream an openCV::mat serialisation...
QtWS25 Last Chance

QDataStream an openCV::mat serialisation...

Scheduled Pinned Locked Moved Solved General and Desktop
qbytearrayqdatastreamopencv
3 Posts 2 Posters 1.1k Views
  • 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 25 Nov 2019, 11:53 last edited by Dariusz
    #1

    Hey

    I'm running these commands to save/load my data & its my first time using read/write raw data so I'm fairly sure I broke it...

    Any idea what did I mess up with this ?

    Write

            int dataSize = mImage->total() * mImage->elemSize1();
            int type = mImage->type();
            int step = mImage->step;
            int width = mImage->cols;
            int height = mImage->rows;
            stream << type << step << width << height << dataSize;
            qDebug() << "Storing image : " << type << step << width << height << dataSize;
            stream.writeRawData(reinterpret_cast<const char *>(mImage->data), dataSize);
    

    Read:

            int dataSize;
            int type;
            int step;
            int width;
            int height;
            stream >> type >> step >> width >> height >> dataSize;
            char *data = new char[dataSize];
            qDebug() << "Restoring image : " << type << step << width << height << dataSize;
            //stream.device()->reset();
            stream.readRawData(data, dataSize);
            mImage = new cv::Mat(height, width, type, data, step);
    

    I think I'm writing/reading data incorrectly.. not sure... any hints?

    J 1 Reply Last reply 25 Nov 2019, 12:01
    0
    • J jsulm
      25 Nov 2019, 12:01

      @Dariusz What is stream here? Is it QDataStream?
      "Any idea what did I mess up with this ?" - well, what is not working?

      D Offline
      D Offline
      Dariusz
      wrote on 25 Nov 2019, 12:10 last edited by Dariusz
      #3

      @jsulm said in QDataStream an openCV::mat serialisation...:

      @Dariusz What is stream here? Is it QDataStream?
      "Any idea what did I mess up with this ?" - well, what is not working?

      Yep :- )

      I think I might "got it". Naturally 5 min after asking question... elemSize1() return incorrect number of channels. Looks like I need elemSize() instead. still testing.

      Yep it was wrong element number.

      Hope it helps other "serializers" out here : -)

      1 Reply Last reply
      1
      • D Dariusz
        25 Nov 2019, 11:53

        Hey

        I'm running these commands to save/load my data & its my first time using read/write raw data so I'm fairly sure I broke it...

        Any idea what did I mess up with this ?

        Write

                int dataSize = mImage->total() * mImage->elemSize1();
                int type = mImage->type();
                int step = mImage->step;
                int width = mImage->cols;
                int height = mImage->rows;
                stream << type << step << width << height << dataSize;
                qDebug() << "Storing image : " << type << step << width << height << dataSize;
                stream.writeRawData(reinterpret_cast<const char *>(mImage->data), dataSize);
        

        Read:

                int dataSize;
                int type;
                int step;
                int width;
                int height;
                stream >> type >> step >> width >> height >> dataSize;
                char *data = new char[dataSize];
                qDebug() << "Restoring image : " << type << step << width << height << dataSize;
                //stream.device()->reset();
                stream.readRawData(data, dataSize);
                mImage = new cv::Mat(height, width, type, data, step);
        

        I think I'm writing/reading data incorrectly.. not sure... any hints?

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 25 Nov 2019, 12:01 last edited by
        #2

        @Dariusz What is stream here? Is it QDataStream?
        "Any idea what did I mess up with this ?" - well, what is not working?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply 25 Nov 2019, 12:10
        1
        • J jsulm
          25 Nov 2019, 12:01

          @Dariusz What is stream here? Is it QDataStream?
          "Any idea what did I mess up with this ?" - well, what is not working?

          D Offline
          D Offline
          Dariusz
          wrote on 25 Nov 2019, 12:10 last edited by Dariusz
          #3

          @jsulm said in QDataStream an openCV::mat serialisation...:

          @Dariusz What is stream here? Is it QDataStream?
          "Any idea what did I mess up with this ?" - well, what is not working?

          Yep :- )

          I think I might "got it". Naturally 5 min after asking question... elemSize1() return incorrect number of channels. Looks like I need elemSize() instead. still testing.

          Yep it was wrong element number.

          Hope it helps other "serializers" out here : -)

          1 Reply Last reply
          1

          1/3

          25 Nov 2019, 11:53

          • Login

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