How to convert an IplImage to Mat?

1.9k Views Asked by At

I am trying to understand how to make this conversion but I still have the same error. I need to convert IN JAVA an ipl image into mat to get the pyrDown of the image. Here the error: Type mismatch: cannot convert from opencv_core.IplImage to Mat

public class Image {
    IplImage i;
    public void downsample(){
        System.loadLibrary( Core.NATIVE_LIBRARY_NAME );             
        Mat Out= new Mat();
        Mat in(i); //  error in this line
        //Down sample the image by factor of 2
        Imgproc.pyrDown(in, Out);
    }
}
2

There are 2 best solutions below

0
Aqeel Haider On

Convert IplImage to Mat is simple.

IplImage iplImage= cvLoadImage("image.png");

Mat matImage = new Mat(iplImage);

vice versa

0
Anton Tsyopa On

Code that works for me:

    CvMat mat = cvLoadImageM (filename, iscolor);

If color: iscolor=1

If grey: iscolor=0

For example:

CvMat mat = cvLoadImageM("./image.png", 1);