Note that there are some explanatory texts on larger screens.

plurals
  1. POCompressing IplImage to JPEG using libjpeg in OpenCV
    text
    copied!<p>So I have this problem. I have an IplImage that i want to compress to JPEG and do something with it. I use libjpeg8b.The code exit when it goes the function of jpeg_start_compress() with an error of "Bogus input colorspace" .Here are my code.</p> <pre><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;nSize); unsigned char *outdata = (uchar *) img-&gt;imageData; struct jpeg_compress_struct cinfo = {0}; struct jpeg_error_mgr jerr; JSAMPROW row_ptr[1]; int row_stride; *outbuffer = NULL; *outlen = 0; cinfo.err = jpeg_std_error(&amp;jerr); jpeg_create_compress(&amp;cinfo); jpeg_mem_dest(&amp;cinfo, outbuffer, outlen); cinfo.image_width = frame-&gt;width; cinfo.image_height = frame-&gt;height; cinfo.input_components = frame-&gt;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 &lt; cinfo.image_height) { row_ptr[0] = &amp;outdata[cinfo.next_scanline * row_stride]; jpeg_write_scanlines(&amp;cinfo, row_ptr, 1); } jpeg_finish_compress(&amp;cinfo); jpeg_destroy_compress(&amp;cinfo); return true; } int main() { ofstream fout("text.txt"); unsigned char **buf; buf = new unsigned char* [120]; for(int i=0;i&lt;500;i++) { buf[i] = new unsigned char[120]; } for(int i=0;i&lt; 120;i++) { for(int j=0;j&lt;120;j++) { buf[i][j] = 0; } } unsigned long *len = new unsigned long; *len = 120*120; Ptr&lt;IplImage&gt; img = cvLoadImage("test.jpg",CV_LOAD_IMAGE_GRAYSCALE); ipl2jpeg(img,buf,len); for(int i=0;i&lt; 120;i++) { for(int j=0;j&lt;120;j++) { fout&lt;&lt;buf[i][j]&lt;&lt;endl; } } return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload