cv::Mat to QByteArray



  • 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



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.