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.

berak
  • 39,159
  • 9
  • 91
  • 89
Lucas
  • 567
  • 1
  • 8
  • 21

9 Answers9

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);
Festus Tamakloe
  • 11,231
  • 9
  • 53
  • 65
  • ImageIO.read("C:\\img.jpg") says: no suitable method found for read(String) I think maybe I messed up the install somewhere. – Lucas Apr 07 '13 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 07 '13 at 22:35
  • Not exactly. Any there is sometimes problems between the Filenames according to ASCII, UTF-8 and i18n – Festus Tamakloe Apr 07 '13 at 22:40
4

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

Fernando
  • 51
  • 2
  • 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](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Kristijan Iliev Oct 23 '15 at 07:38
  • If you have a new question, please ask it by clicking the [Ask Question](http://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. – Joe Taras Oct 23 '15 at 08:11
  • @JoeTaras This is not a question. I wonder what makes you think that. Perhaps you misclicked. – Artjom B. Oct 23 '15 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 '15 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 '15 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.

404error
  • 133
  • 11
2

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

bmkay
  • 462
  • 6
  • 9
2

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

grzebyk
  • 1,024
  • 1
  • 15
  • 26
1

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

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

Lucas Zamboulis
  • 2,494
  • 5
  • 24
  • 27
nuzree
  • 11
  • 1
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.

Jero Dungog
  • 379
  • 1
  • 10
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

Edess Elder
  • 1,461
  • 13
  • 9
0

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