4

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.

9

9 Answers 9

5

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);
3
  • ImageIO.read("C:\\img.jpg") says: no suitable method found for read(String) I think maybe I messed up the install somewhere.
    – Lucas
    Apr 7, 2013 at 22:29
  • Yes, that works. Thanks for the help. Any idea why the other won't work? CanvasFrame is loading from cv library, so it must be working.
    – Lucas
    Apr 7, 2013 at 22:35
  • Not exactly. Any there is sometimes problems between the Filenames according to ASCII, UTF-8 and i18n Apr 7, 2013 at 22:40
4

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

5
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. Oct 23, 2015 at 7:38
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context.
    – Joe Taras
    Oct 23, 2015 at 8:11
  • @JoeTaras This is not a question. I wonder what makes you think that. Perhaps you misclicked.
    – Artjom B.
    Oct 23, 2015 at 13:04
  • @Chris This is an attempt at an answer and not a comment. It would have been nice to see a description why this would solve the problem, but still, it's an answer.
    – Artjom B.
    Oct 23, 2015 at 13:05
  • @ArtjomB. I try to respond, your answer does not respond to the question. Your problem can be different of problem of Lucas.
    – Joe Taras
    Oct 23, 2015 at 13:06
3

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.

2

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

2

With javacv 0,9 you have to import static org.bytedeco.javacpp.opencv_highgui.*;

1

I got the same error then, i imported the following package, problem solved.

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

1

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:
import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage;

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.

0

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.