如何将OpenCV lib添加到Dynamic Web Project

前端之家收集整理的这篇文章主要介绍了如何将OpenCV lib添加到Dynamic Web Project前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目前,我正在构建一个使用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文件.

您需要手动添加和加载的二进制文件.
像这样的东西:

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) {
        }
    }
}
原文链接:https://www.f2er.com/html/227139.html

猜你在找的HTML相关文章