aihot  2017-05-02 16:16:53  OpenCV |   查看评论   

 TLD(Tracking-Learning-Detection)学习与源码理解之

      下面是自己在看论文和这些大牛的分析过程中,对代码进行了一些理解,但是由于自己接触图像处理和机器视觉没多久,另外由于自己编程能力比较弱,所以分析过程可能会有不少的错误,希望各位不吝指正。而且,因为编程很多地方不懂,所以注释得非常乱,还海涵。

 

TLD.cpp

  1. /*
  2.  * TLD.cpp
  3.  */  
  4.   
  5. #include <TLD.h>  
  6. #include <stdio.h>  
  7. using namespace cv;  
  8. using namespace std;  
  9.   
  10.   
  11. TLD::TLD()  
  12. {  
  13. }  
  14. TLD::TLD(const FileNode& file){  
  15.   read(file);  
  16. }  
  17.   
  18. void TLD::read(const FileNode& file){  
  19.   /// 边界框参数
  20.   min_win = (int)file["min_win"];  
  21.   /// 发电机参数
  22.   // 初步参数为正例
  23.   patch_size = (int)file["patch_size"];  
  24.   num_closest_init = (int)file["num_closest_init"];  
  25.   num_warps_init = (int)file["num_warps_init"];  
  26.   noise_init = (int)file["noise_init"];  
  27.   angle_init = (float)file["angle_init"];  
  28.   shift_init = (float)file["shift_init"];  
  29.   scale_init = (float)file["scale_init"];  
  30.   // 更新参数为正例
  31.   num_closest_update = (int)file["num_closest_update"];  
  32.   num_warps_update = (int)file["num_warps_update"];  
  33.   noise_update = (int)file["noise_update"];  
  34.   angle_update = (float)file["angle_update"];  
  35.   shift_update = (float)file["shift_update"];  
  36.   scale_update = (float)file["scale_update"];  
  37.   // 参数为负例
  38.   bad_overlap = (float)file["overlap"];  
  39.   bad_patches = (int)file["num_patches"];  
  40.   classifier.read(file);  
  41. }  
  42.   
  43. //此函数完成准备工作  
  44. void TLD::init(const Mat& frame1, const Rect& box, FILE* bb_file){  
  45.   //bb_file = fopen("bounding_boxes.txt","w");  
  46.   // 获取边框
  47.   //此函数根据传入的box(目标边界框)在传入的图像frame1中构建全部的扫描窗口,并计算重叠度  
  48.     buildGrid(frame1, box);  
  49.     printf("Created %d bounding boxes\n",(int)grid.size());  //vector的成员size()用于获取向量元素的个数  
  50.       
  51.   /// 制备
  52.   // 分配
  53.   //积分图像,用以计算2bitBP特征(类似于haar特征的计算)  
  54.   //Mat的创建,方式有两种:1.调用create(行,列,类型)2.Mat(行,列,类型(值))。  
  55.   iisum.create(frame1.rows+1, frame1.cols+1, CV_32F);  
  56.   iisqsum.create(frame1.rows+1, frame1.cols+1, CV_64F);  
  57.     
  58.   //Detector data中定义:std::vector<float> dconf;  检测确信度??  
  59.   //vector 的reserve增加了vector的capacity,但是它的size没有改变!而resize改变了vector  
  60.   //的capacity同时也增加了它的size!reserve是容器预留空间,但在空间内不真正创建元素对象,  
  61.   //所以在没有添加新的对象之前,不能引用容器内的元素。  
  62.   //不管是调用resize还是reserve,二者对容器原有的元素都没有影响。  
  63.   //myVec.reserve( 100 );     // 新元素还没有构造, 此时不能用[]访问元素  
  64.   //myVec.resize( 100 );      // 用元素的默认构造函数构造了100个新的元素,可以直接操作新元素  
  65.   dconf.reserve(100);  
  66.   dbb.reserve(100);  
  67.   bbox_step =7;  
  68.     
  69.   //以下在Detector data中定义的容器都给其分配grid.size()大小(这个是一幅图像中全部的扫描窗口个数)的容量  
  70.   //Detector data中定义TempStruct tmp;    
  71.   //tmp.conf.reserve(grid.size());  
  72.   tmp.conf = vector<float>(grid.size());  
  73.   tmp.patt = vector<vector<int> >(grid.size(), vector<int>(10,0));  
  74.   //tmp.patt.reserve(grid.size());  
  75.   dt.bb.reserve(grid.size());  
  76.   good_boxes.reserve(grid.size());  
  77.   bad_boxes.reserve(grid.size());  
  78.     
  79.   //TLD中定义:cv::Mat pEx;  //positive NN example 大小为15*15图像片  
  80.   pEx.create(patch_size, patch_size, CV_64F);  
  81.     
  82.   //Init Generator  
  83.   //TLD中定义:cv::PatchGenerator generator;  //PatchGenerator类用来对图像区域进行仿射变换  
  84.   /*
  85.   cv::PatchGenerator::PatchGenerator (    
  86.       double     _backgroundMin,
  87.       double     _backgroundMax,
  88.       double     _noiseRange,
  89.       bool     _randomBlur = true,
  90.       double     _lambdaMin = 0.6,
  91.       double     _lambdaMax = 1.5,
  92.       double     _thetaMin = -CV_PI,
  93.       double     _thetaMax = CV_PI,
  94.       double     _phiMin = -CV_PI,
  95.       double     _phiMax = CV_PI 
  96.    ) 
  97.    一般的用法是先初始化一个PatchGenerator的实例,然后RNG一个随机因子,再调用()运算符产生一个变换后的正样本。
  98.   */  
  99.   generator = PatchGenerator (0,0,noise_init,true,1-scale_init,1+scale_init,-angle_init*CV_PI/180,  
  100.                                 angle_init*CV_PI/180,-angle_init*CV_PI/180,angle_init*CV_PI/180);  
  101.     
  102.   //此函数根据传入的box(目标边界框),在整帧图像中的全部窗口中寻找与该box距离最小(即最相似,  
  103.   //重叠度最大)的num_closest_init个窗口,然后把这些窗口 归入good_boxes容器  
  104.   //同时,把重叠度小于0.2的,归入 bad_boxes 容器  
  105.   //首先根据overlap的比例信息选出重复区域比例大于60%并且前num_closet_init= 10个的最接近box的RectBox,
     1/10    1 2 3 4 5 6 下一页 尾页
 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自TLD(Tracking-Learning-Detection)学习与源码理解之(六)下

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]