zoukankan      html  css  js  c++  java
  • 搭建opencv javaweb项目

    搭建opencv javaweb项目

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

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

    即把opencv jar包放到maven本地仓库中
    mvn install:install-file -Dfile="G:opencvopencvuildjavaopencv-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

  • 相关阅读:
    使用 Eclipse 平台共享代码
    给定一个整数数组,其中元素的取值范围为0到10000,求其中出现次数最多的数
    学习
    eclipse优化
    约瑟夫环
    propedit插件
    OData 11 入门:实现一个简单的OData服务
    OData 14 OData语法(上)
    CLR via C# 读书笔记 54 在使用非托管资源情况下的GC
    面试:等车时间
  • 原文地址:https://www.cnblogs.com/qjmnong/p/10067314.html
Copyright © 2011-2022 走看看