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 aQByteArray()
, and every possibility to generate/write into a QByteArray is based on achar*
in the end. My serializedcv::Mat.data
in turn retrievesuchar*
, 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