美文网首页OpenCv
搭建opencv javaweb项目

搭建opencv javaweb项目

作者: 奇迹迪 | 来源:发表于2018-12-04 21:29 被阅读11次

    搭建opencv javaweb项目

    用到的技术maven、git、ssm、opencv、javaweb

    搭建opencv javaweb项目时,踩了很多坑;怀疑过spring,想过python,最后竟然一不小心成了,what.......闲话不多说,让我们看看这关键的一条命令

    即把opencv jar包放到maven本地仓库中
    mvn install:install-file -Dfile="G:\opencv\opencv\build\java\opencv-341.jar" -DgroupId=org.opencv -DartifactId=opencv -Dversion=3.4.1 -Dpackaging=jar

    再看看一直报'javaClassNotDefound'的maven依赖配置

    <dependency>
        <groupId>org.opencv</groupId>
        <artifactId>opencv</artifactId>
        <version>3.4.1</version>
        <systemPath>G:/opencv/opencv/build/java/opencv-341.jar</systemPath>
        <scope>system</scope>
    </dependency>
    

    再看看不报错的配置

    <dependency>
        <groupId>org.opencv</groupId>
        <artifactId>opencv</artifactId>
        <version>3.4.1</version>
    </dependency>
    

    到这离成功已经很近了,我们还需要加载dll或者so文件

    我们可以在用到opencv的类中用静态代码块加载dll或者so文件,
    或者配置一个监听器如下,别忘了在web.xml中配置

    package cn.edu.njupt.configure;
    
    import cn.edu.njupt.utils.OpencvConstantUtils;
    
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    
    public class InitOpencv  implements ServletContextListener {
    
        @Override
        public void contextDestroyed(ServletContextEvent servletContextEvent) {
    
        }
    
        public void contextInitialized(ServletContextEvent arg0) {
            System.load("G:/opencv/opencv/build/java/x64/opencv_java341.dll");
        }
    
    }
    

    web.xml

    <listener>
            <listener-class>cn.edu.njupt.configure.InitOpencv</listener-class>
    </listener>
    
    

    到此项目可以说就搭建好了,liunx,mac只需要按照上述步骤把对应文件路径替换掉就可以了

    本项目地址:https://github.com/YLDarren/stitp
    相关项目地址:https://github.com/YLDarren/opencvHandleImg

    相关文章

      网友评论

        本文标题:搭建opencv javaweb项目

        本文链接:https://www.haomeiwen.com/subject/sjtbcqtx.html