JavaCV中的ExceptionInInitializerError

时间:2013-11-19 14:29:27

标签: java opencv javacv

我正在尝试使用JavaCV,但我收到了ExceptionInInitializerError。

以下是日志:

Exception in thread "Thread-2" java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.googlecode.javacpp.Loader.load(Loader.java:553)
    at com.googlecode.javacpp.Loader.load(Loader.java:532)
    at com.googlecode.javacv.cpp.opencv_core$CvArr.<clinit>(opencv_core.java:156)
    at com.googlecode.javacv.VideoInputFrameGrabber.grab(VideoInputFrameGrabber.java:163)
    at com.sudev.robo.Robot.run(Robot.java:30)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Can't overwrite cause
    at java.lang.Throwable.initCause(Throwable.java:456)
    at com.googlecode.javacpp.Loader.load(Loader.java:581)
    at com.googlecode.javacpp.Loader.load(Loader.java:532)
    at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:134)
    ... 8 more

有人可以帮我解决这个问题。我使用的是JavaCV 0.6,OpenCV 2.4.7和Microsoft visual c ++ 2010可再发行的x64

该计划的代码在这里:

import static com.googlecode.javacv.cpp.opencv_core.cvFlip;
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.FrameGrabber;
import com.googlecode.javacv.VideoInputFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core.IplImage;

public class Robot implements Runnable {
    IplImage image;
    CanvasFrame canvas = new CanvasFrame("Web Cam");

    public Robot() {
        canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void run() {
        FrameGrabber grabber = new VideoInputFrameGrabber(0);
        // 1 for next camera
        int i = 0;
        try {
            grabber.start();
            IplImage img = null;
            while (true) {
                 long sleepTime= (long)((1000 / 60));
                    img = grabber.grab();
                if (img != null) {
                    cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise
                    cvSaveImage((i++) + "-aa.jpg", img); // show image on window
                    canvas.showImage(img);
                } 
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Robot gs = new Robot();
        Thread th = new Thread(gs);
        th.start();
    }
}

1 个答案:

答案 0 :(得分:0)

对于那些在使用JavaCV并尝试加载相机时发现此错误的人......

我发现导入下面文件中的所有文件解决了我的问题。

https://code.google.com/p/javacv/downloads/detail?name=javacv-0.6-cppjars.zip