cv::Mat to QByteArray
QtExchange last edited by
I'm trying to send cv::Mat via QTcpSocket to another network participant, but I'm having difficulties with the data types.
QByteArray(), and every possibility to generate/write into a QByteArray is based on a
char*in the end. My serialized
cv::Mat.datain 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() ?
VRonin last edited by VRonin
since char and uchar store binary data and are not used as actual numeric values you can easily just cast it
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