简体   繁体   中英

JavaCV/OpenCV: cvLoadImage not working

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.

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

eg:

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

这解决了我的问题: import static org.bytedeco.javacpp.opencv_imgcodecs.*;

You have to add this import statement:
import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage; This is required so that the static method cvLoadImage can be used without using the class name.

你必须import com.googlecode.javacv.cpp.opencv_highgui.*;

使用javacv 0,9,您必须import static org.bytedeco.javacpp.opencv_highgui.*;

我得到了同样的错误,我导入了以下包,问题解决了。

import static com.googlecode.javacv.cpp.opencv_highgui.*;

This might be old but for those who stumbled upon this problem like me just now, here is how I solved it and why:

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

This indicates that the compiler cannot find the cvLoadImage method that you are trying to call.

cvLoadImage is a static method under JavaCPP. Specifically it is a static method under opencv_imgcodecs class.

To solve this issue one must first specify the import of the opencv_imgcodecs class.

This can be done by adding the import:

This in turn would result for the opencv_imgcodecs class to be usable within your class along with its static methods and other functions.

I hope this helps.

Got the same problem recently. if you are using javacv-0.10 (more recent at the moment), import manually this one:

import static org.bytedeco.javacpp.opencv_highgui.*;

but the source of JRE of the project should be higher than 1.5

In my case, the problem happened when the squeegee in debug mode. Try to run in normal mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM