0

I try to use the well known "jpeglib" now available in version 9.

Overview: I am a programming starter in C using MS Visual C++ 2010 Express and read a C-book finally. My goal is to compress a RGB(.bmp)-file into JPEG. So I downloaded the jpeglib (v9), read all the install and so on *.txt-files. It was possible to compile the C-files to get cjpeg.exe, djpeg.exe, jpeg.lib and so on.

After this success I tried to use the example.c to get deeper into the jpeg and to control the compression. -> It did not work. Then I tried to use the jpeglib included in OpenCV. Same non working result, while the OpenCV code samples are compiled successfully.

I googled lots of samples, problem solutions and tips how to use jpeglib. Most helpful information I found here. But in the result I was still not able to compile my own jpeg-tool or example.c (rewriting the write_JPEG_file() function ).

Question: What in the basics could be wrong, when every other programmer just uses #include "jpeglib.h" in their codes to run the jpeg functions successfully? For me including this file seems not to be enough. Because of that I have to ask you and to relaunch a one year old Question that also did not helped solving my probs. I can not give you a specific error message because of multiple attempts to solve those issues.

Here is my current MS-VC++2010 config for using OpenCV 2.4.6:

  1. C/C++ -> General -> Additional Include Directories:
    • C:\opencv\build\include
    • C:\opencv\build\include\opencv
    • C:\opencv\build\include\opencv2
    • C:\opencv\include
    • C:\opencv\include\opencv
    • C:\opencv\include\opencv2
    • C:\opencv\3rdparty\libjpeg
  2. Linker -> General -> Additional Library Directories:
    • C:\opencv\build\x86\vc10\lib
  3. Linker -> Input -> Additional Dependencies:
    • opencv_core246d.lib
    • opencv_imgproc246d.lib
    • opencv_highgui246d.lib
    • opencv_ml246d.lib
    • opencv_video246d.lib
    • opencv_features2d246d.lib
    • opencv_calib3d246d.lib
    • opencv_objdetect246d.lib
    • opencv_contrib246d.lib
    • opencv_legacy246d.lib
    • opencv_flann246d.lib
    • jpeg.lib [this I added into C:\opencv\build\x86\vc10\lib]

At last some threads I have already read:

If there is something missing you want to know I will do my best to add this information!

EDIT - Some error messages:

1>jpeg_coder.obj : error LNK2001: unresolved external symbol ""unsigned char * image_buffer" (?image_buffer@@3PAEA)".

1>jpeg_coder.obj : error LNK2001: unresolved external symbol ""int image_height" (?image_height@@3HA)".

1>jpeg_coder.obj : error LNK2001: unresolved external symbol """int image_width" (?image_width@@3HA)".

First symbol should be typedefed in jpeglib.h as JSAMPLE FAR *JSAMPROW, second and third are defined in rdjpgcom.c as unsigned int image_height, image_width;

Maybe, with a lot of luck, I figured out what is need to be done to get jpeglib running. In the current state I have to check and double check whether my problem solution is correct or not. At this point thank you very much for your attention for my issues. As soon as I am sure with the solution I will post it.

Problem Solution: I did not setup OpenCV correctly for using jpeglib. The mistake I made was to link the wrong *.lib-file. The proper file for linking is libjpegd.lib. Too bad that jpeglib v6.2 is included in OpenCV 2.4.6 instead of v9. The hint to add HAVE_JPEG to use jpeglib functions inside OpenCV I ignored completely. For now the problem is solved.

Community
  • 1
  • 1
watashi
  • 1
  • 3
  • The question is so long, but you didn't write exactly how `It did not work` – Alex F Oct 16 '13 at 10:41
  • Sorry for the long question! _It did not work_ means several declarations or functions are missing which are located in `jpeglib.h`, `jdatadst.c`, `jcapimin.c` and many more files. I did not even figure out which files are necessary to get are compilable set of files (minimal configuration). – watashi Oct 16 '13 at 10:58
  • To get answer to your question, you need to provide error messages - compiler or linker errors, runtime crash information etc. – Alex F Oct 16 '13 at 11:02
  • opencv already comes with libjpeg on board (3rdparty), so why roll your own ? all you'd need to do is `imwrite("my.jpg",img);` and you're done. – berak Oct 16 '13 at 12:59
  • I noticed that OpenCV comes with jepglib. This is why my current concentration is focus on it. Somewhere in the Net is written: to activate jpeglib in OpenCV `HAVE_JPEG` has to be added to `highgui.h`. But this file is existing four times and adding `#define HAVE_JPEG` to them changes nothing. I do not know if I use this command correct. Futher more I do not know how to manipulate the OpenCV-jpeg-coding-with-activated-jpeglib for example to modify the DCT... – watashi Oct 16 '13 at 13:08
  • Are these variables from your program? It looks like you need to learn how to use `extern` C keyword. – Alex F Oct 16 '13 at 13:43
  • Those variables are copied right out of the _example.c_ provided by IJG.ORG. I did not change them. The chapter about `extern` I have read four days ago by the way ;) – watashi Oct 16 '13 at 13:49

1 Answers1

0

Problem Solution: I did not setup OpenCV correctly for using jpeglib. The mistake I made was to link the wrong *.lib-file.

The proper file for linking is libjpegd.lib.

Too bad that jpeglib v6.2 is included in OpenCV 2.4.6 instead of v9. The hint to add HAVE_JPEG to use jpeglib functions inside OpenCV I ignored completely. Thanks to all who tried solving this issue. For now the problem is solved.

watashi
  • 1
  • 3