Reputation: 411
I'm trying to encode some Mats into a gif file using giflib, but I can't get it to work.
Here's how I convert the opencv mat's data into gif pixel:
cv::resize(input_mat, input_mat, cv::Size (160, 160));
cv::Mat mrgba(160, gif_size, CV_8UC4, cv::Scalar(0,0,0,0));
cv::cvtColor(input_mat, mrgba, CV_BGR2RGBA);
Byte * buffer = malloc( 160 * 160 *sizeof(Byte));
memcpy(buffer, mrgba.data, 160 * 160 *sizeof(Byte));
Then encode buffer into gif file. The other part of my code is right because I can use it to encode pixel buffers I got from OpenGL by using glReadPixel
. I think maybe there's something wrong with OpenCV mat's data structure.
Let me attach a picture to show you what I got now:
Upvotes: 0
Views: 1508
Reputation: 411
As @berak said, I was not copying enough bytes. the current size should be
memcpy(buffer, mrgba.data, 160 * 160 *sizeof(Byte));
Upvotes: 1