目前,我正在构建一个使用Opencv来检测相似图像的
Java Web项目.但是当我跑步时,我总是得到这个错误
java.lang.UnsatisfiedLinkError: Expecting an absolute path of the
library: opencv_java249 java.lang.Runtime.load0(Runtime.java:806)
java.lang.System.load(System.java:1086)
com.hadoop.DriverServlet.doPost(DriverServlet.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我也搜索这个问题,但仍然找不到我的案例的任何解决方案.即使我尝试将此http://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-use/添加到eclipse中的java.library路径指向opencv-249 jar但仍未解决.
有人可以帮帮我吗?提前致谢.
解决方法
要使用opencv,您需要jar文件和二进制文件.
可以通过本地maven存储库或任何其他变体简单地添加JAR文件.
可以通过本地maven存储库或任何其他变体简单地添加JAR文件.
private static void addLibraryPath(String pathToAdd) throws Exception{ final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths"); usrPathsField.setAccessible(true); //get array of paths final String[] paths = (String[])usrPathsField.get(null); //check if the path to add is already present for(String path : paths) { if(path.equals(pathToAdd)) { return; } } //add the new path final String[] newPaths = Arrays.copyOf(paths,paths.length + 1); newPaths[newPaths.length-1] = pathToAdd; usrPathsField.set(null,newPaths); } public void init() { String pathToOpenCvDll = "c:\\opencv\\"; //linux path works too try { addLibraryPath(pathToOpenCvDll); System.loadLibrary("opencv_java320"); } catch (Exception ignored) { } } }