3

I am using opencv 2.3.1 on Debian. The following code fails to load a given jpeg 2000 file.

#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <vector>
#include <iostream>

int main()
{
    IplImage* img_temp = cvLoadImage("delmeg.jp2", CV_LOAD_IMAGE_ANYCOLOR);
    //IplImage* img_temp = cvLoadImage("delmec.jp2");
    if(img_temp == NULL)
    {
        std::cout << "Can't load the image.." << std::endl;
        return -1;
    }
    cv::Mat img(img_temp);

    if (img_temp != NULL){
        cvReleaseImage(&img_temp);
    }
    return 0;
}

I used the following command to compile it:

g++ -Wall -g -I /usr/include/ testopencv2x.cpp -o testopencv2x -lopencv_core -lopencv_imgproc -lopencv_highgui

Anybody know what I am missing here?

Thanks.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
user193272
  • 984
  • 1
  • 12
  • 18

1 Answers1

2

I don't know about 2.3.1, but here is what the documentation says about 2.4.3:

Note: OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With help of plugins (you need to specify to use them if you build yourself the library, nevertheless in the packages we ship present by default) you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2 - codenamed in the CMake as Jasper), TIFF files (tiff, tif) and portable network graphics (png). Furthermore, OpenEXR is also a possibility.

So make sure you build OpenCV to support this format.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Yes, I have gone through the documentatoin, so perhaps I don't understand it properly. In this context, I have also tried compiling OpenCV (in Windows 7) by specifying jasper (the jpeg2000 library) in cmake to be built in. In that case also I am not able to read the jp2 files (same source code as I have listed). – user193272 Feb 06 '13 at 17:05
  • Furthermore, I have jasper libs installed on my Debian machines: libjasper-dev and libjasper1:i386 – user193272 Feb 06 '13 at 17:07
  • Make sure CMake can see them. Before issuing `make` you should be able to see if cmake was able to find the libraries on your system to support this type. – karlphillip Feb 06 '13 at 17:21
  • I thought OpenCV source code came with jasper source code (when I compiled in Windows). When I configure cmake, I confirmed that it is going to build JPEG 2000 build ver 1.900.1. Besides, Linux already appears to have jasper libraries installed. So I seem to be all set for this. I was wondering whether you are able to load a jp2 file in your setup, or if I can trouble you to try my code example. – user193272 Feb 06 '13 at 17:59
  • Upload your jp2 file somewhere and let me try it. – karlphillip Feb 06 '13 at 18:12
  • I was trying to form an image to upload for your test and I discovered that I am actually able to load a jp2 file. This was done on an example image (the airplane.jpg that comes with opencv, converted to jp2). Then I tried with my own image that I am working with again, it failed. Then I converted that image to a jp2 image again (using the convert command in Linux) and lo and behold I was able to read the newly converted image. So it looks like there is either a problem with the original jp2 image encoding, or memory allocation problem. I will update here with what I find out. Thanks. – user193272 Feb 06 '13 at 18:39
  • Okay, just found out that the jp2 files I was working with do not appear to be properly formed. Now, geeqie in Linux reads those same files fine, irfanviewer in Windows does too, only cvLoadImage cannot load them. As I mentioned earlier, converting those jp2 files to jp2 files using imagemagic appears to produce sane jp2 files that cvLoadImage is able to read.Thanks for all your comments. – user193272 Feb 06 '13 at 18:49
  • No problem, feel free to up vote my answer if it helped or select it as the official problem solver by clicking on the checkbox near it. Good luck. – karlphillip Feb 06 '13 at 18:51
  • 1
    Sure, I will mark it as the solution since it is technically correct. Besides, the comments should give the whole picture to any future online wanderer. – user193272 Feb 06 '13 at 19:36