After battling libJpeg for 2 days (pointers, step-by-step memory management and hair pulling), I gave up and used all my favorite methods of saving to disk-load-to-memory, so if anyone is interested here, this is the method
char* convert2jpeg(IplImage* frame, int* frame_size) {
FILE* infile = NULL;
struct stat fileinfo_buf;
if (cvSaveImage(name_buf, frame) < 0) {
printf("\nCan't save image %s", name_buf);
return NULL;
}
if (stat(name_buf, &fileinfo_buf) < 0) {
printf("\nPLAYER [convert2jpeg] stat");
return NULL;
}
*frame_size = fileinfo_buf.st_size;
char* buffer = (char *) malloc(fileinfo_buf.st_size + 1);
if ((infile = fopen(name_buf, "rb")) == NULL) {
printf("\nPLAYER [convert2jpeg] fopen %s", name_buf);
free(buffer);
return NULL;
}
fread(buffer, fileinfo_buf.st_size, 1, infile);
fclose(infile);
return buffer;
}
I hope someone finds this useful. I want one of the OpenCV developers to see this stream and implement direct conversion to JPEG conversion in OpenCV and save us from unhappiness and 1 save / load to disk operation.
user175419
source
share