JavaCV/OpenCV: cvLoadImage not working

Lucas picture Lucas · Apr 7, 2013 · Viewed 12.6k times · Source

I installed the JavaCV/OpenCV libraries, and I'm having a problem with the basic example code.

According to several examples that I have looked at, this code should load an image:

IplImage image = cvLoadImage("C:\\img.jpg");

But, when I run that I get a "cannot find symbol" error.

Since this is my first time using it, I'm not sure if I messed the install up or not.

According to the newest JavaCV readme, I do have the correct version of OpenCV. I also have all the JavaCV jar files imported. As far as I can tell, I also have all the paths set correctly too.

Anyone know what the problem is?

Edit:

Full code:

import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import java.io.File;


public class demo {

    public static void main(String[] args) 
    {
        IplImage image = cvLoadImage("C:\\img.jpg");

        final CanvasFrame canvas = new CanvasFrame("Demo");
        canvas.showImage(image);
        canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
    }

}

Error when I try to run it:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: cvLoadImage at javacv.demo.main(demo.java:17)

Java Result: 1

Seems like it is claiming cvLoadImage doesn't take a string as an argument.

Answer

Festus Tamakloe picture Festus Tamakloe · Apr 8, 2013

A walk around that i find for you is to load the image by ImageIO and passe it later to IplImage

e.g.:

 BufferedImage img =  ImageIO.read(new File("C:\\img.jpg") );
 IplImage origImg = IplImage.createFrom(img);