opencv训练工具编译

opencv训练需要两个工具,这两个工具的源码在opencv源码中的位置:
在这里插入图片描述
createsample 用于生成正样本的vec文件
traincascade 用于训练我们最终需要的xml 文件
具体如何使用,网络上非常多,在此不再赘述。

编译过程

  • 安装cmake : 用于通过一系列的源码和相关的配置来生成需要的编译器平台上的项目文件,在linux中生成 Makefile 文件,以供我们使用make进行编译
    1.1 安装方法: apt-get install cmake 或源码安装
  • 安装 make
    apt-get install make
  • 进行编译
    3.1 下载opencv 源码(注意,必须下载 4.0.0 以下版本,否则没有上述两个模块)
    wget https://codeload.github.com/opencv/opencv/zip/3.4
    3.2 解压,创建 build 目录
    unzip master & cd 3.4 & mkdir build & cd build
    3.3 使用cmake 生成 Makefile
    cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local …
    3.4 编译 & 安装
    make & make install
    3.5 编译完成
    可执行文件在 builld/bin 目录中
    在这里插入图片描述

编译过程走过的弯路

  • 尝试单独编译模块报错
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at CMakeLists.txt:1 (ocv_warnings_disable):
  Unknown CMake command "ocv_warnings_disable".


CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.15)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
See also "/home/IServer/opencv-4.1.1/apps/traincascade/build/CMakeFiles/CMakeOutput.log".

尝试单独编译过程:
为什么要单独编译?
因为我全编opencv4.1.1(写文档当前最新版),编译完成之后发现没有生成我需要的两个文件。
cd opencv-4.1.1/apps/traincascade/build/ & cmake … 报错
看上边的错误信息,大概就是 Unknown CMake command “ocv_warnings_disable”. 这个命令找不到
百度也找不到什么相关的信息,很奇怪。
这个调用在什么地方呢?在 opencv-4.1.1/apps/traincascade 下边的CMakeLists.txt 中,看这个命名 ocv,应该是opencv ,说明不是 cmake 自带的命令,说明我们不能这样单独编译。
那怎么办?我们继续往下。
找来找去,发现 opencv-4.1.1/apps 下边的CMakeLists.txt 最下边有这样几行

#ocv_add_app(traincascade)
#ocv_add_app(createsamples)
ocv_add_app(annotation)
ocv_add_app(visualisation)
ocv_add_app(interactive-calibration)
ocv_add_app(version)

原来是被注释掉了,去掉注释进行编译:

/home/IServer/opencv-4.1.1/apps/traincascade/old_ml.hpp:803:24: error: ‘CvFileStorage’ has not been declared
     virtual void read( CvFileStorage* fs, CvFileNode* node );
                        ^
/home/IServer/opencv-4.1.1/apps/traincascade/old_ml.hpp:803:43: error: ‘CvFileNode’ has not been declared
     virtual void read( CvFileStorage* fs, CvFileNode* node );
                                           ^
/home/IServer/opencv-4.1.1/apps/traincascade/old_ml.hpp:804:25: error: ‘CvFileStorage’ has not been declared
     virtual void write( CvFileStorage* fs, const char* name ) const;
                         ^
/home/IServer/opencv-4.1.1/apps/traincascade/old_ml.hpp:807:24: error: ‘CvFileStorage’ has not been declared
     virtual void read( CvFileStorage* fs, CvFileNode* node,
                        ^
/home/IServer/opencv-4.1.1/apps/traincascade/old_ml.hpp:807:43: error: ‘CvFileNode’ has not been declared
     virtual void read( CvFileStorage* fs, CvFileNode* node,
                                           ^
/home/IServer/opencv-4.1.1/apps/traincascade/old_ml.hpp:809:25: error: ‘CvFileStorage’ has not been declared
     virtual void write( CvFileStorage* fs ) const;
                         ^
/home/IServer/opencv-4.1.1/apps/traincascade/old_ml.hpp:846:30: error: ‘CvFileStorage’ has not been declared
     virtual void write_node( CvFileStorage* fs, CvDTreeNode* node ) const;
                              ^
/home/IServer/opencv-4.1.1/apps/traincascade/old_ml.hpp:847:31: error: ‘CvFileStorage’ has not been declared
     virtual void write_split( CvFileStorage* fs, CvDTreeSplit* split ) const;

报错,百度无果,google
在这里插入图片描述
大概意思就是从 4.1.0 版本开始,之前的一些代码被废弃了,所以无法编译,建议换为3.4 版本;
到此,问题解决,爬坑结束。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值