javacv NullpointerException loading image.

asked 2013-09-27 12:16:20 -0500

updated 2013-09-27 12:17:46 -0500

berak gravatar image

I'm trying to execute this simple java class to test opencv and javacv correct installation:

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

    public class demo1 {
        public static void main(String[] args) {
            //Load image img1 as IplImage
            final IplImage image = cvLoadImage("img1.png");
            System.out.println("Image loaded");
            //create canvas frame named 'Demo'
            final CanvasFrame canvas = new CanvasFrame("Demo");
            //Show image in canvas frame
            //This will close canvas frame on exit

I receive this console output:

Image loaded
Exception in thread "main" java.lang.NullPointerException
    at com.googlecode.javacv.CanvasFrame.showImage(
    at com.googlecode.javacv.CanvasFrame.showImage(
    at demo1.main(

I installed OpenCV- in my win7 64bit pc

extracted it in C:\opencv,

set the environment variable PATH as C:\opencv\build\x64\vc11\bin,

i've got the Java SDK,

downloaded javacv (source and cppjars)

and added all opencv and javacv jar files in the Eclipse project.

The img1.png is in the same folder of

What is the problem? Thank you for help.

edit retag flag offensive close merge delete


try System.out.println("Image loaded" + image); // and see,that it wasn't loaded.

try an absolute path, like "c:/my/folder/img1.png"

berak gravatar imageberak ( 2013-09-27 12:21:01 -0500 )edit

It worked, thank you very much! can you say me something about this error? I think is the same problem but the image should be passed like configuration argument and i tried a path like "c:/my/folder/img1.png" but still not works.

Schiawo gravatar imageSchiawo ( 2013-09-27 12:32:37 -0500 )edit

OK, i fixed the other one too.

Schiawo gravatar imageSchiawo ( 2013-09-27 12:40:01 -0500 )edit