JavaCV / OpenCV: cvLoadImage not working

I installed the JavaCV / OpenCV libraries and I had a problem with a basic code example.

According to a few examples that I examined, this code should load an image:

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

But, when I start, I get the error "can not find the character."

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

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

Does 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 trying to start it:

Exception in the main thread java.lang.RuntimeException: Uncompiled source code - Invalid sym type: cvLoadImage on javacv.demo.main (demo.java:17)

Java Result: 1

It looks like it is claiming that cvLoadImage is not accepting the string as an argument.

+4
source share
9 answers

A walk around what I find for you is to upload an image using ImageIO and skip it later. IplImage

eg:.

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

This solved my problem: import static org.bytedeco.javacpp.opencv_imgcodecs.*;

+4
source

You must add this import statement:
import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage; This is necessary to use the static cvLoadImage method without using the class name.

+3
source

You need to import com.googlecode.javacv.cpp.opencv_highgui.*;

+2
source

With javacv 0.9 you should import static org.bytedeco.javacpp.opencv_highgui.*;

+2
source

Then I got the same error, I imported the next package, the problem is resolved.

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

+1
source

It may be old, but for those who stumbled upon this problem, as I am now, here is how I solved it and why:

First OP error: Exception in the main thread java.lang.RuntimeException: Uncompiled source code - Erroneous sym: cvLoadImage type in javacv.demo.main (demo.java:17)

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

cvLoadImage is a static method in JavaCPP. In particular, this is a static method in the opencv_imgcodecs class.

To solve this problem, you must first specify the import of the opencv_imgcodecs class.

This can be done by adding imports:
import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage;

This, in turn, will cause the opencv_imgcodecs class to be used inside your class, as well as its static methods and other functions.

Hope this helps.

+1
source

Recently, the same problem has appeared. if you are using javacv-0.10 (later at the moment), manually import this:

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

but the source of the project jre should be above 1.5

0
source

In my case, the problem occurred when the squeegee is in debug mode. Try to run as usual.

0
source

All Articles