1

我使用 javacv 在 java 中编写了运动检测代码,它在 Windows 上完美运行,但在 Ubuntu 13.04 中显示类似这样的错误请建议解决方案,我也在附加代码

代码

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo;

/**
 *
 * @author Admin
 */
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;

public class Demo {
    public static void main(String[] args) throws Exception {
        OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
        grabber.start();

        IplImage frame = grabber.grab();
        IplImage image = null;
        IplImage prevImage = null;
        IplImage diff = null;

        CanvasFrame canvasFrame = new CanvasFrame("Original stream");
        canvasFrame.setCanvasSize(frame.width(), frame.height());

        CanvasFrame editFrame = new CanvasFrame("Edited stream");
        canvasFrame.setCanvasSize(frame.width(), frame.height());

        CvMemStorage storage = CvMemStorage.create();

        while (canvasFrame.isVisible() && (frame = grabber.grab()) != null) {
            //cvSmooth(frame, frame, CV_GAUSSIAN, 9, 9, 2, 2);
            if (image == null) {
                image = IplImage.create(frame.width(), frame.height(), IPL_DEPTH_8U, 1);
                //cvCvtColor(frame, image, CV_RGB2GRAY);
            } else {
                prevImage = IplImage.create(frame.width(), frame.height(), IPL_DEPTH_8U, 1);
                prevImage = image;
                image = IplImage.create(frame.width(), frame.height(), IPL_DEPTH_8U, 1);
                cvCvtColor(frame, image, CV_RGB2GRAY);
            }

            if (diff == null) {
                diff = IplImage.create(frame.width(), frame.height(), IPL_DEPTH_8U, 1);
            }

            if (prevImage != null) {
                // perform ABS difference
                cvAbsDiff(image, prevImage, diff);
                // do some threshold for wipe away useless details
                cvThreshold(diff, diff, 64, 255, CV_THRESH_BINARY);

                canvasFrame.showImage(frame);
                editFrame.showImage(diff);

            }
        }
        grabber.stop();
        canvasFrame.dispose();
    }
}

输出:

sx=158sy=37w=350h=350op7 线程“main”中的异常 java.lang.UnsatisfiedLinkError:/tmp/javacpp94368173067/libjniopencv_core.so:libopencv_core.so.2.4:无法打开共享对象文件:java 中没有这样的文件或目录。 lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1957) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1882) at java.lang.ClassLoader.loadLibrary( ClassLoader.java:1843) 在 java.lang.Runtime.load0(Runtime.java:795) 在 java.lang.System.load(System.java:1061) 在 com.googlecode.javacpp.Loader.loadLibrary(Loader.java :566) com.googlecode.javacpp.Loader.load(Loader.java:489) com.googlecode.javacpp.Loader.load(Loader.java:431) com.googlecode.javacv.cpp.opencv_core.(opencv_core .java:136) 在 java.lang。Class.forName0(Native Method) at java.lang.Class.forName(Class.java:270) at com.googlecode.javacpp.Loader.load(Loader.java:453) at com.googlecode.javacv.cpp.opencv_imgproc。 (opencv_imgproc.java:97) 在 java.lang.Class.forName0(Native Method) 在 java.lang.Class.forName(Class.java:270) 在 com.googlecode.javacpp.Loader.load(Loader.java:453 ) at com.googlecode.javacv.cpp.opencv_highgui.(opencv_highgui.java:85) at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:174) at demo1.Demo1.main(Demo1.java:187)作者:java.lang.UnsatisfiedLinkError:java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878) 处 java.lang.Runtime.loadLibrary0(Runtime.java:849) 处的 java.library.path 中没有 opencv_core .System.loadLibrary(System.java:1087) 在 com.googlecode.javacpp.Loader。loadLibrary(Loader.java:593) at com.googlecode.javacpp.Loader.load(Loader.java:481) ... 还有 12 个 Java 结果:1 构建成功(总时间:0 秒)

4

2 回答 2

1

它的简单含义是它无法找到本机依赖项。JavaCV 在内部使用 JNI 调用来使用 OpenCV dll。在 Windows 上,依赖项位于路径上(背后可能有多种原因,opencv 可能位于环境变量或某些资源中)。

我建议通过 linux:https ://code.google.com/p/javacv/

于 2013-08-01T11:25:39.573 回答
1

在您的终端中尝试“echo $PATH”命令,并确保您机器上的 opencv*.dll 文件的路径是否存在。

于 2013-11-04T01:48:56.547 回答