Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaCV/OpenCV: cvLoadImage not working

Tags:

java

javacv

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.

like image 473
Lucas Avatar asked Dec 02 '22 19:12

Lucas


2 Answers

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);
like image 148
Festus Tamakloe Avatar answered Dec 04 '22 10:12

Festus Tamakloe


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

like image 39
Fernando Avatar answered Dec 04 '22 09:12

Fernando