Data-array "organisation" of image Mat. (Mat->GIF)
I'm trying to export some frames as a GIF by using this library: https://github.com/ginsweater/gif-h
Unfortunately, it seems that the char-array the library requires for each frame is ordered differently than Mat#data.
Which led me to memory errors when trying to simply pass the Mat-data-array as argument.
I did read the documentation of "Mat", but can't say that I truly understood, and thus don't know how to properly convert it.
I tried to convert it like this:
const int dim = resolution.width * resolution.height * 4;
uint8_t* pixels = (uint8_t*)alloca(sizeof(uint8_t) * dim);
for (int y = 1; y <= res.width; y++){
for (int x = 1; x <= res.height; x++){
uint8_t* pixel = NULL;
f->pixelAt(x, y, f->pixelAt(x-1, y-1, pixel);
pixels[(y*x-1)] = pixel[0];
pixels[(y*x - 1) + 1] = pixel[1];
pixels[(y*x - 1) + 2] = pixel[2];
pixels[(y*x - 1) + 3] = 255;
}
}
Where f->pixelAt(x, y, pixel)
equals to:
void OpenCV_Frame::pixelAt(int x, int y, uint8_t* retVal){
retVal = new uint8_t[3];
cv::Vec3b vec = at<cv::Vec3b>(y, x);
retVal[0] = vec[0];
retVal[1] = vec[1];
retVal[2] = vec[2];
}
I get a stackoverflow error when allocating the uint8_t array. I know that the array is ridiculously big, but I'm not sure how to approach this problem otherwise.
Help appreciated, thanks!