问题描述
我试图在具有以下maven依赖项的spring mvc项目中使用上述方法加载opencv:-
I am trying to load opencv using the above method in a spring mvc project that has the following maven dependency:-
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
</dependency>
我的代码是:
static {
nu.pattern.OpenCV.loadShared();
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
}
在解决此错误方面的任何帮助将不胜感激.预先感谢
Any help in solving this error will be appreciated. Thanks in advance
推荐答案
解决了这个问题.
基于一个堆栈帖子,我包含了以下几行代码来加载库.
Based on a stack post I included the following lines of code to load the library..
static{
String osName = System.getProperty("os.name");
String opencvpath = System.getProperty("user.dir");
if(osName.startsWith("Windows")) {
int bitness = Integer.parseInt(System.getProperty("sun.arch.data.model"));
if(bitness == 32) {
opencvpath=opencvpath+"\\opencv\\x86\\";
}
else if (bitness == 64) {
opencvpath=opencvpath+"\\opencv\\x64\\";
} else {
opencvpath=opencvpath+"\\opencv\\x86\\";
}
}
else if(osName.equals("Mac OS X")){
opencvpath = opencvpath+"Your path to .dylib";
}
System.out.println(opencvpath);
System.load(opencvpath + Core.NATIVE_LIBRARY_NAME + ".dll");
//nu.pattern.OpenCV.loadShared();
//System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
}
在检查各种参数时,发现os.name返回了WINDOWS. user.dir返回eclipse根目录,sun.arch.data.model返回64.然后,根据此代码,我在eclipse根目录中创建必要的文件夹,并将最新的opencv dll粘贴在该目录中.但是现在另一个问题是代码正在搜索dll的较旧版本,并且不接受此较新版本.
问题是由于以下事实:内置库正在使用旧版本的opencv,而我正在尝试使用最新版本.因此,我不得不从该库和tada的maven依赖项中排除opencv的先前版本,从而解决了问题.
On checking the various parameters it was found that os.name returned WINDOWS. user.dir returned the eclipse root directory and the sun.arch.data.model returned 64. Based on this code I then created the necessary folders in eclipse root directory and pasted the latest opencv dll over there.But now the other problem was that the code was searching for an older version of the dll and wasnt accepting this newer version.
The problem was due to the fact that an inbuilt library was using an older version of opencv and i was trying to use the latest version. So I had to exclude that previous version of opencv from the maven dependency of that library and tada the problem was solved.
这篇关于nu.pattern.OpenCV $ UnsupportedPlatformException:操作系统"WINDOWS"和架构"X86_64"不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!