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. cv::Mat to QByteArray

cv::Mat to QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 2.2k 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.
  • Q Offline
    Q Offline
    QtExchange
    wrote on last edited by
    #1

    I'm trying to send cv::Mat via QTcpSocket to another network participant, but I'm having difficulties with the data types.

    QTcpSocket::write() requires a QByteArray(), and every possibility to generate/write into a QByteArray is based on a char* in the end. My serialized cv::Mat.data in turn retrieves uchar*, where I couldn't find anything smooth to convert and I don't like to touch every element on its own (processing speed) - that would be my last hope.

    Isn't there a faster possibility like memcpy or ::fromUChar() ?

    Kind Regards

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      since char and uchar store binary data and are not used as actual numeric values you can easily just cast it reinterpret_cast<char*>

      P.S.

      QTcpSocket::write() requires a QByteArray()

      This is not the only way to write data to the socket, you can use a QDataStream and overload the operator>> and operator<< to accept a cv::Mat

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

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