OpenCV + Java = UnsatisfiedLinkError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18625948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV + Java = UnsatisfiedLinkError
提问by efmoyano
I need capture a video stream from my USB webcam, for this i use Opencv 2.4.6 for developing in Java. I follow the steps listed in here
我需要从我的 USB 网络摄像头捕获视频流,为此我使用 Opencv 2.4.6 进行 Java 开发。我按照此处列出的步骤操作
I add the "C:\opencv\build\java\x64" dir to my System PATH and include the "opencv-246.jar" file into my libraries on ECLIPSE. When y run the explame
我将“C:\opencv\build\java\x64”目录添加到我的系统路径中,并将“opencv-246.jar”文件包含到我在 ECLIPSE 上的库中。当你运行说明
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Main {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
}
i get
我明白了
m = [1, 0, 0;
0, 1, 0;
0, 0, 1]
OK =)
好的 =)
but when i run
但是当我跑步时
import org.opencv.highgui.VideoCapture;
public class Main {
public static void main(String[] args) {
VideoCapture vc = new VideoCapture(0);
if(vc.isOpened()){
System.out.println("Works!");
}
}
}
i get
我明白了
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.highgui.VideoCapture.n_VideoCapture(I)J
at org.opencv.highgui.VideoCapture.n_VideoCapture(Native Method)
at org.opencv.highgui.VideoCapture.<init>(VideoCapture.java:113)
at Main.main(Main.java:5)
i add all the routes containes in:
我添加了所有包含的路由:
C:\opencv\build\x64\vc10
C:\opencv\build\x64\vc10
one by one,but doesn`t work.
一个一个,但不起作用。
Finally i create a variable called OPENCV_DIR with C:\opencv\build\x64\vc10 but still getting UnsatisfiedLinkError.
最后,我用 C:\opencv\build\x64\vc10 创建了一个名为 OPENCV_DIR 的变量,但仍然得到 UnsatisfiedLinkError。
PLEASE HELP ME!
请帮我!
回答by berak
in your second example , you skipped this line
在你的第二个例子中,你跳过了这一行
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
so the opencv libs werent loaded, UnsatisfiedLinkError, etc...
所以opencv库没有加载,UnsatisfiedLinkError等......
[edit]:
[编辑]:
thanks to @Jishnu Prathap for highlighting the java.library path issue, if you run into problems setting that, you can still try to use an absolute path to the java wrapper so/dll/dylib like:
感谢@Jishnu Prathap 突出显示 java.library 路径问题,如果您在设置时遇到问题,您仍然可以尝试使用 java 包装器 so/dll/dylib 的绝对路径,例如:
System.load("/path to/our/java_wrapper");
回答by Jishnu Prathap
I had a similar error while using OpenCV with java.I did 2 things to resolve it.
我在使用 OpenCV 和 java 时遇到了类似的错误。我做了两件事来解决它。
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
- I added the path to OpenCV dll or .so to javalibpath or path. which actually didnt work for some reason and i ended up putting the OpenCV dll in the system32 folder.
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
- 我将 OpenCV dll 或 .so 的路径添加到 javalibpath 或路径。这实际上由于某种原因不起作用,我最终将OpenCV dll 放在 system32 文件夹中。
回答by Varu
So, I was having this problem too and I did what you all suggested, it worked fine in my x64 windows, but in a x86 couldn't make it work.
所以,我也遇到了这个问题,我按照你们的建议做了,它在我的 x64 窗口中运行良好,但在 x86 中无法正常工作。
At last I found a solution by changing:
最后我通过更改找到了解决方案:
VideoCapture capture = new VideoCapture(0);
for
为了
VideoCapture capture = new VideoCapture();
capture.open("resources/vid.MP4");
I don't know why this worked but I hope it may help somebody with my same problem.
我不知道这为什么有效,但我希望它可以帮助解决我同样问题的人。
回答by Samira Pouyanfar
For general users using opencv3.x:
对于使用 opencv3.x 的一般用户:
HighGUI module does not exist anymore in Java for opencv 3.0 and above.
对于 opencv 3.0 及更高版本,Java 中不再存在 HighGUI 模块。
import org.opencv.videoio.VideoCapture;
instead of
代替
import org.opencv.highgui.VideoCapture;
videoio includes VideoCapture, VideoWriter.
videoio 包括 VideoCapture、VideoWriter。
Similarly:
相似地:
imgcodecs includes imread/imwrite and friends
imgcodecs 包括 imread/imwrite 和朋友
Example:
例子:
Highgui.imread(fileName)
-->
-->
Imgcodecs.imread(fileName)
回答by Bala
Try the below code
试试下面的代码
import org.opencv.core.CvType; import org.opencv.core.Mat;
导入 org.opencv.core.CvType; 导入 org.opencv.core.Mat;
import nu.pattern.OpenCV;
导入 nu.pattern.OpenCV;
public class OpencvMain {
公共类 OpencvMain {
public static void main( String[] args )
{
OpenCV.loadLocally();
Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
System.out.println( "mat = " + mat.dump() );
}
}
}