QDataStream an openCV::mat serialisation...
-
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?
-
@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 : -)
-
@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 : -)