尝试使用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();
}
}
答案 0 :(得分:2)
确保您已安装Microsoft Visual C ++ Redistributable
包和设置路径变量正确。以下链接解释了所有
必要的步骤
http://opencvlover.blogspot.in/2012/04/javacv-setup-with-eclipse-on-windows-7.html
建议使用VideoInputFrameGrabber而不是OpncvFrameGrabber 在下面的链接中 http://code.google.com/p/javacv/wiki/Windows7AndOpenCV#I_cannot_capture_from_my_Webcam_using_opencv_highgui_or_OpenCVFr
答案 1 :(得分: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:
我的代码已成功运行。
答案 2 :(得分:1)