opencv3.3.1

https://github.com/alantrrs/OpenTLD

https://github.com/arthurv/OpenTLD

problem

opencv3.0以及后续版本弃用legacy模块了;

solution

write cv::PatchGenerator module by yourself.

patchgenerator.h in folder include

//#pragma once
#ifndef PATCH_GENERATOR_H
#define PATCH_GENERATOR_H
#include "opencv2/opencv.hpp"namespace cv{
class CV_EXPORTS PatchGenerator
//class PatchGenerator
{
public:PatchGenerator();PatchGenerator(double _backgroundMin, double _backgroundMax,double _noiseRange, bool _randomBlur=true,double _lambdaMin=0.6, double _lambdaMax=1.5,double _thetaMin=-CV_PI, double _thetaMax=CV_PI,double _phiMin=-CV_PI, double _phiMax=CV_PI );void operator()(const Mat& image, Point2f pt, Mat& patch, Size patchSize, RNG& rng) const;void operator()(const Mat& image, const Mat& transform, Mat& patch,Size patchSize, RNG& rng) const;void warpWholeImage(const Mat& image, Mat& matT, Mat& buf,CV_OUT Mat& warped, int border, RNG& rng) const;void generateRandomTransform(Point2f srcCenter, Point2f dstCenter,CV_OUT Mat& transform, RNG& rng,bool inverse=false) const;void setAffineParam(double lambda, double theta, double phi);double backgroundMin, backgroundMax;double noiseRange;bool randomBlur;double lambdaMin, lambdaMax;double thetaMin, thetaMax;double phiMin, phiMax;
};};
#endif

View Code

patchgenerator.cpp in folder src

#include "opencv2/opencv.hpp"
#include "patchgenerator.h"
namespace cv
{const int progressBarSize = 50;//// Patch Generator //static const double DEFAULT_BACKGROUND_MIN = 0;static const double DEFAULT_BACKGROUND_MAX = 256;static const double DEFAULT_NOISE_RANGE = 5;static const double DEFAULT_LAMBDA_MIN = 0.6;static const double DEFAULT_LAMBDA_MAX = 1.5;static const double DEFAULT_THETA_MIN = -CV_PI;static const double DEFAULT_THETA_MAX = CV_PI;static const double DEFAULT_PHI_MIN = -CV_PI;static const double DEFAULT_PHI_MAX = CV_PI;PatchGenerator::PatchGenerator(): backgroundMin(DEFAULT_BACKGROUND_MIN), backgroundMax(DEFAULT_BACKGROUND_MAX),noiseRange(DEFAULT_NOISE_RANGE), randomBlur(true), lambdaMin(DEFAULT_LAMBDA_MIN),lambdaMax(DEFAULT_LAMBDA_MAX), thetaMin(DEFAULT_THETA_MIN),thetaMax(DEFAULT_THETA_MAX), phiMin(DEFAULT_PHI_MIN),phiMax(DEFAULT_PHI_MAX){}PatchGenerator::PatchGenerator(double _backgroundMin, double _backgroundMax,double _noiseRange, bool _randomBlur,double _lambdaMin, double _lambdaMax,double _thetaMin, double _thetaMax,double _phiMin, double _phiMax ): backgroundMin(_backgroundMin), backgroundMax(_backgroundMax),noiseRange(_noiseRange), randomBlur(_randomBlur),lambdaMin(_lambdaMin), lambdaMax(_lambdaMax),thetaMin(_thetaMin), thetaMax(_thetaMax),phiMin(_phiMin), phiMax(_phiMax){}void PatchGenerator::generateRandomTransform(Point2f srcCenter, Point2f dstCenter,Mat& transform, RNG& rng, bool inverse) const{double lambda1 = rng.uniform(lambdaMin, lambdaMax);double lambda2 = rng.uniform(lambdaMin, lambdaMax);double theta = rng.uniform(thetaMin, thetaMax);double phi = rng.uniform(phiMin, phiMax);// Calculate random parameterized affine transformation A,// A = T(patch center) * R(theta) * R(phi)' *// S(lambda1, lambda2) * R(phi) * T(-pt)double st = sin(theta);double ct = cos(theta);double sp = sin(phi);double cp = cos(phi);double c2p = cp*cp;double s2p = sp*sp;double A = lambda1*c2p + lambda2*s2p;double B = (lambda2 - lambda1)*sp*cp;double C = lambda1*s2p + lambda2*c2p;double Ax_plus_By = A*srcCenter.x + B*srcCenter.y;double Bx_plus_Cy = B*srcCenter.x + C*srcCenter.y;transform.create(2, 3, CV_64F);Mat_<double>& T = (Mat_<double>&)transform;T(0,0) = A*ct - B*st;T(0,1) = B*ct - C*st;T(0,2) = -ct*Ax_plus_By + st*Bx_plus_Cy + dstCenter.x;T(1,0) = A*st + B*ct;T(1,1) = B*st + C*ct;T(1,2) = -st*Ax_plus_By - ct*Bx_plus_Cy + dstCenter.y;if( inverse ) invertAffineTransform(T, T);}void PatchGenerator::operator ()(const Mat& image, Point2f pt, Mat& patch, Size patchSize, RNG& rng) const{double buffer[6];Mat_<double> T(2, 3, buffer);generateRandomTransform(pt, Point2f((patchSize.width-1)*0.5f, (patchSize.height-1)*0.5f), T, rng);(*this)(image, T, patch, patchSize, rng);}void PatchGenerator::operator ()(const Mat& image, const Mat& T,Mat& patch, Size patchSize, RNG& rng) const{patch.create( patchSize, image.type() );if( backgroundMin != backgroundMax ){rng.fill(patch, RNG::UNIFORM, Scalar::all(backgroundMin), Scalar::all(backgroundMax));warpAffine(image, patch, T, patchSize, INTER_LINEAR, BORDER_TRANSPARENT);}elsewarpAffine(image, patch, T, patchSize, INTER_LINEAR, BORDER_CONSTANT, Scalar::all(backgroundMin));int ksize = randomBlur ? (unsigned)rng % 9 - 5 : 0;if( ksize > 0 ){ksize = ksize*2 + 1;GaussianBlur(patch, patch, Size(ksize, ksize), 0, 0);}if( noiseRange > 0 ){AutoBuffer<uchar> _noiseBuf( patchSize.width*patchSize.height*image.elemSize() );Mat noise(patchSize, image.type(), (uchar*)_noiseBuf);int delta = image.depth() == CV_8U ? 128 : image.depth() == CV_16U ? 32768 : 0;rng.fill(noise, RNG::NORMAL, Scalar::all(delta), Scalar::all(noiseRange));if( backgroundMin != backgroundMax ) addWeighted(patch, 1, noise, 1, -delta, patch);else{for( int i = 0; i <patchSize.height; i++ ){uchar* prow = patch.ptr<uchar>(i);const uchar* nrow = noise.ptr<uchar>(i);for( int j = 0; j <patchSize.width; j++ )if( prow[j] != backgroundMin )prow[j] = saturate_cast<uchar>(prow[j] + nrow[j] - delta);}}}}void PatchGenerator::warpWholeImage(const Mat& image, Mat& matT, Mat& buf,Mat& warped, int border, RNG& rng) const{Mat_<double> T = matT;Rect roi(INT_MAX, INT_MAX, INT_MIN, INT_MIN);for( int k = 0; k <4; k++ ){Point2f pt0, pt1;pt0.x = (float)(k == 0 || k == 3 ? 0 : image.cols);pt0.y = (float)(k <2 ? 0 : image.rows);pt1.x = (float)(T(0,0)*pt0.x + T(0,1)*pt0.y + T(0,2));pt1.y = (float)(T(1,0)*pt0.x + T(1,1)*pt0.y + T(1,2));roi.x = std::min(roi.x, cvFloor(pt1.x));roi.y = std::min(roi.y, cvFloor(pt1.y));roi.width = std::max(roi.width, cvCeil(pt1.x));roi.height = std::max(roi.height, cvCeil(pt1.y));}roi.width -= roi.x - 1;roi.height -= roi.y - 1;int dx = border - roi.x;int dy = border - roi.y;if( (roi.width+border*2)*(roi.height+border*2) > buf.cols )buf.create(1, (roi.width+border*2)*(roi.height+border*2), image.type());warped = Mat(roi.height + border*2, roi.width + border*2,image.type(), buf.data);T(0,2) += dx;T(1,2) += dy;(*this)(image, T, warped, warped.size(), rng);if( T.data != matT.data ) T.convertTo(matT, matT.type());}// Params are assumed to be symmetrical: lambda w.r.t. 1, theta and phi w.r.t. 0void PatchGenerator::setAffineParam(double lambda, double theta, double phi){lambdaMin = 1. - lambda;lambdaMax = 1. + lambda;thetaMin = -theta;thetaMax = theta;phiMin = -phi;phiMax = phi;}
};

View Code

CMakeLists.txt

#Set minimum version requered
cmake_minimum_required(VERSION 2.4.6)
#just to avoid the warning
if(COMMAND cmake_policy)cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
#set project name
project(TLD)
#Append path to the module path
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
#OpenCV
find_package(OpenCV 3.3.1 REQUIRED)
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../lib)
#set the include directories
include_directories (${PROJECT_SOURCE_DIR}/../include    ${OpenCV_INCLUDE_DIRS})
#libraries
add_library(tld_utils tld_utils.cpp)
add_library(LKTracker LKTracker.cpp)
add_library(ferNN FerNNClassifier.cpp)
add_library(tld TLD.cpp patchgenerator.cpp)
#add_library(tld TLD.cpp)
#executables
add_executable(run_tld run_tld.cpp)
#link the libraries
target_link_libraries(run_tld tld LKTracker ferNN tld_utils ${OpenCV_LIBS})
#set optimization level
set(CMAKE_BUILD_TYPE Release)

run

cd OpenTLD
mkdir build
cd build
cmake ../src/
make
cd ../bin/
%To run from camera
./run_tld -p ../parameters.yml -tl
%To run from file
./run_tld -p ../parameters.yml -s ../datasets/06_car/car.mpg -tl
%To init bounding box from file
./run_tld -p ../parameters.yml -s ../datasets/06_car/car.mpg -b ../datasets/06_car/init.txt -tl
%To train only in the firs frame (no tracking, no learning)
./run_tld -p ../parameters.yml -s ../datasets/06_car/car.mpg -b ../datasets/06_car/init.txt
%To test the final detector (Repeat the video, first time learns, second time detects)
./run_tld -p ../parameters.yml -s ../datasets/06_car/car.mpg -b ../datasets/06_car/init.txt -tl -r

choose a bbox as one tracking object.

evaluation

=====================================
Evaluation
=====================================
The output of the program is a file called bounding_boxes.txt which contains all the detections made through the video. This file should be compared with the ground truth file to evaluate the performance of the algorithm. This is done using a python script:
python ../datasets/evaluate_vis.py ../datasets/06_car/car.mpg bounding_boxes.txt ../datasets/06_car/gt.txt

result

$python2 ../datasets/evaluate_vis.py ../datasets/06_car/car.mpg bounding_boxes.txt ../datasets/06_car/gt.txt
../datasets/evaluate_vis.py:22: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the futureframe[y1:y2,x1:x2]=(100,200,100)
detections = 916.000000
true detections = 860.000000
correct detections = 850.000000
precision=0.927948
recall=0.988372
f-measure= 0.957207

re:

1. https://github.com/alantrrs/OpenTLD

2. https://github.com/arthurv/OpenTLD

3. http://blog.sina.com.cn/s/blog_b30296270102wbbw.html;

end

转载于:https://www.cnblogs.com/happyamyhope/p/10694057.html

[]TLD code run相关推荐

  1. 如何在Visual Studio Code中编译C ++代码

    PS: This was published on my Blog here. PS:这已发布在我的Blog 此处 . C++ is a statically-typed, free-form, (u ...

  2. 【VS Code】vue.js ESLint + vscode 代码格式配置

    文章目录 VS Code 安装扩展 全局 setting.json 安装 ESlint 依赖 两种方式: 方式一:全局安装 方式二:项目安装 配置eslint .eslintrc.json VS Co ...

  3. Thread 中的run() 与start() 方法

    将类声明为 Thread 的子类是创建线程的方式之一,如果我们想要在线程内定义任务那么就要重写Thread 中的run() 方法.start() 方法使我们定义的线程执行,我们已经将线程的任务定义在了 ...

  4. c# vscode 配置_[VSCode插件推荐] Code Runner: 代码一键运行,支持超过40种语言

    记得两年多前,笔者那时还在写 PHP,同时需要写 Python 和 Node.js .所以在那时,支持多种语言的 VS Code 已经是笔者的主力编辑器了.唯一不足的是,笔者希望在VS Code里,能 ...

  5. 线程的run()方法带参情况

    首先看一下Runnable接口的源码,整个方法体里就只有一个run的抽象方法,所以才创建实现类实现该接口的时候是肯定要重写接口内的抽象方法的(也就是run()方法),按照重写规则(不能是抽象,参数要和 ...

  6. Reverse-engineer Source Code into UML Diagrams

    今天同事需要反向生成类图,用PowerDesigner 转了一份,不甚满意,在网上逛了逛,发现在这篇文章挺不错. I have been on several teams where we studi ...

  7. Visual Studio Code搭建NodeJs的开发环境

    一.Visual Studio Code搭建NodeJs的开发环境 1.下载安装NodeJs并配置环境变量 可以参考:NodeJs的安装和环境变量配置 2.下载安装 VS Code编辑器 可以参考:V ...

  8. VS Code 神器插件:代码一键运行,支持超过 40 种语言!

    程序员转行学什么语言? https://edu.csdn.net/topic/ai30?utm_source= csdn_bw 记得两年多前,笔者那时还在写 PHP,同时需要写 Python 和 No ...

  9. [翻译Joel On Software]Joel测试:12步写出更高质量代码/The Joel Test: 12 Steps to Better Code

    Joel on Software The Joel Test: 12 Steps to Better Code Joel测试:12步写出更高质量代码 byJoel Spolsky Wednesday, ...

  10. 101 Ruby Code Factoids

    101 Ruby Code Factoids 0) 'methods' method Since almost everything in Ruby is an Object you can type ...

最新文章

  1. 基于css3 transform实现散乱的照片排列
  2. VO 1 先弄明白在干什么
  3. proxmox超融合集群用户授权
  4. Leetcode 583.两个字符串的删除操作
  5. 公司那些事-关于领导
  6. python安装scipy出现红字_windows下安装numpy,scipy遇到的问题总结
  7. 【BZOJ1568】【Tyvj3490】Blue Mary开公司 李超线段树
  8. TechSmith Camtasia Mac v2021屏幕录制剪辑软件
  9. R语言TCGA数据下载及处理biolinks包的学习与使用(一)数据下载
  10. 互联网的发展简史—web
  11. 【3D视觉】深度摄像头与3D重建
  12. 小区门口的健身房,就是韭菜收割厂
  13. 深度学习论文阅读目标检测篇(四)中英文对照版:YOLOv1《 You Only Look Once: Unified, Real-Time Object Detection》
  14. OpenStack私有云安装配置虚拟机
  15. python输入n个数、输出最小的数字_程序查找最少的斐波纳契数以在Python中加到n?...
  16. kubernetes之volumes使用
  17. 急!程序员夫妻结婚了,婚戒上刻什么字好?
  18. 【Linux学习】如何编写Shell脚本调用企业微信api来发消息给企业微信成员?
  19. [通信 组成架构]AP是什么 WLAN及无线网络的结构
  20. Java二叉树和红黑树

热门文章

  1. Java之常用函数笔记
  2. AttributeError: ‘torch.return_types.max‘ object has no attribute ‘dim‘
  3. DevOps使用教程 华为云(10)GitHub git Pull Request 合并请求
  4. Hyperledger Fabric教程(8)--byfn.sh分析-script.sh
  5. 微信小程序云开发教程-小程序代码发布和上线运行
  6. java bigdecimal取余_BigDecimal求余操作
  7. php如何删除zip文件内容,删除php中的zip文件夹
  8. php 会话 写入浏览器,创建PHP会话变量会挂起我的浏览器
  9. java多线程-基础知识
  10. Centos7.x 安装Kubernetes(K8s) 1.14.3 nginx 部署 案例