Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top