1

尝试使用 JAVACV 库从网络摄像头捕获。但它会抛出一个UnsatisfiedLinkError. 堆栈跟踪如下:

Exception in thread "main" java.lang.UnsatisfiedLinkError:
C:\Users\anooj\AppData\Local\Temp\javacpp7955905460040\jniopencv_core.dll: %1 is not a valid Win32 application
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1928)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825)
at java.lang.Runtime.load0(Runtime.java:792)
at java.lang.System.load(System.java:1059)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:418)
at com.googlecode.javacpp.Loader.load(Loader.java:368)
at com.googlecode.javacpp.Loader.load(Loader.java:315)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:131)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.googlecode.javacpp.Loader.load(Loader.java:334)
at com.googlecode.javacv.cpp.opencv_imgproc.<clinit>(opencv_imgproc.java:96)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.googlecode.javacpp.Loader.load(Loader.java:334)
at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:91)
at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:170)
at javaapplication16.JavaApplication16.captureframe(JavaApplication16.java:24)
at javaapplication16.JavaApplication16.main(JavaApplication16.java:38)
Java Result: 1

我们的代码如下:

import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;

public class JavaApplication16 {

/**
 * @param args the command line arguments
 */
    public static void captureframe()
    {
        OpenCVFrameGrabber grabber=new OpenCVFrameGrabber(0);
        try
        {
            grabber.start();
            IplImage img=grabber.grab();
            if(img!=null)
            {
                cvSaveImage("capture.jpg", img);
            }
        }
        catch(Exception ae)
        {
            ae.printStackTrace();

        }
    }
    public static void main(String[] args) {
        captureframe();
    }    
}
4

3 回答 3

2

请记住,openCV 和 javaCV 的版本必须匹配。下载最新版本的openCV 2..46 http://opencv.org/downloads.html

并下载 javacp https://code.google.com/p/javacv/downloads/list [注意:选择 javacv-0.6-cppjars.zip 85.0 MB]

在这种情况下,您不会在线程“main”java.lang.UnsatisfiedLinkError 中获得异常:

我的代码运行成功。

于 2013-12-04T09:01:31.757 回答
2
于 2012-07-19T06:06:39.393 回答
1

请参阅此链接以解决您遇到的错误Link1

请参阅此链接以获取从相机捕获图像的程序,将其保存为 JPG 格式并将其显示在画布上Link2

希望它能解决您的查询。

于 2012-08-01T14:04:10.343 回答