Compressing IplImage to JPEG using libjpeg in OpenCV -
So I have this problem. I have an ipype that I have to compress with JPEG and do something with it "libus Input colorspace goes to the function of jpeg_start_compress () with an error when it use libzpeg8b.The code exhaust. Here's my code.
#include "highgui.h" #include & lt; Stdio.h & gt; #include "jpeglib.h" #include "cv.h" # Include & lt; Iostream & gt; # Include & lt; Fstream & gt; using namespace std; Using namespace cv; #pragma Comment (lib, "jpeglib.lib") bool ipl2jpeg (IplImage * frame, unsigned char ** outbuffer, unsigned long * outlen) {IplImage * img = new IplImage; Memcpy (img, frame, frame & gt; n shape); Unsigned four * outdata = (uchar *) img- & gt; Image data; Struct jpeg_compress_struct cinfo = {0}; Struct jpeg_error_mgr Ger; JSAMPROW row_ptr [1]; Int row_stride; * Outbuffer = Faucet; * Outlines = 0; Cinfo.err = jpeg_std_error (& jerr); Jpeg_create_compress (& amp; cinfo); Jpeg_mem_dest (& amp; cinfo, outbuffer, outlined); Cinfo.image_width = frame-> Width; Cinfo.image_height = frame- & gt; Height; Cinfo.input_components = frame-> NChannels; Cinfo.in_color_space = JCS_RGB; Jpeg_set_defaults (& amp; cinfo); Jpeg_start_compress (& amp; cinfo, TRUE); System ("pause"); Row_stride = frame- & gt; Width * frame- & gt; NChannels; While (cinfo.next_scanline
I have never used libjpeg before but it seems that You are mixing the color spaces you load the image as a grayscale (CV_ID_INUnUURJRL), but it is saying that this is a RGB image (JCS_RGB). Have you tried changing the line
cinfo.in_color_space = JCS_RGB; to
cinfo.in_color_space = JCS_GRAYSCALE; ?
Comments
Post a Comment