Skip to content

Instantly share code, notes, and snippets.

@yxiao1996
Last active January 20, 2024 01:14
Show Gist options
  • Save yxiao1996/bbdd364ed081d8c24c32af5d0cf8ee54 to your computer and use it in GitHub Desktop.
Save yxiao1996/bbdd364ed081d8c24c32af5d0cf8ee54 to your computer and use it in GitHub Desktop.
工作指南:OpenCV Cascade Classifier

How to Train Detection Model with OpenCV

  • get OpenCV

    • 请从OpenCV的官方网站获取源程序(版本2.4以上即可):

      https://opencv.org/releases.html
      
    • 按照官方指导安装OpenCV:

      https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
      
    • 熟悉一下级联分类器的训练流程:

      https://docs.opencv.org/2.4.11/doc/user_guide/ug_traincascade.html
      
  • get scripts

  • 分类器训练流程

    • 准备数据

      input:None; output:VOC格式数据标注

      • 从FTP服务器上将标注好的数据块下载到本地;
      • 将数据整理好(确保数据标注和正例数据的对应关系)
    • 数据格式转换

      input:VOC格式数据标注; output:OpenCV格式数据标注

      • VOC格式为每个正例数据标注都创建独立的文件,而OpenCV分类器有自己的格式(info.dat, bg.txt);

      • 使用annoCvt.py和bgGen.py创建info.dat和bg.txt

      • 使用方法:

        1. 在annoCvt.py和bgGen.py种修改源路径和目标路径;
        2. 运行annoCvt.py;(如果成功,可以看到和ftp上示例info.dat相似和格式)

        python annoCvt.py

        1. 运行bgGen.py;(同上)

        python bgGen.py

    • 训练分类器

      input:960X640图像,OpenCV格式数据标注; output:分类器模型

      • 训练分类器分为生成数据文件(.vec)和训练模型两步;

      • 训练之前一定要保证你的路径结构和ftp上示例object_detector下结构完全相同;

      • 使用方法:

        python TrainCascade.py

    • 测试分类器

      input:分类器模型; output:测试结果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment