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

patchgenerator.cpp in folder src

#include "opencv2/opencv.hpp"
#include "patchgenerator.h"
namespace cv
{ const int progressBarSize = ; //////////////////////////// Patch Generator ////////////////////////////////// static const double DEFAULT_BACKGROUND_MIN = ;
static const double DEFAULT_BACKGROUND_MAX = ;
static const double DEFAULT_NOISE_RANGE = ;
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(, , CV_64F);
Mat_<double>& T = (Mat_<double>&)transform;
T(,) = A*ct - B*st;
T(,) = B*ct - C*st;
T(,) = -ct*Ax_plus_By + st*Bx_plus_Cy + dstCenter.x;
T(,) = A*st + B*ct;
T(,) = B*st + C*ct;
T(,) = -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[];
Mat_<double> T(, , buffer); generateRandomTransform(pt, Point2f((patchSize.width-)*0.5f, (patchSize.height-)*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);
}
else
warpAffine(image, patch, T, patchSize, INTER_LINEAR, BORDER_CONSTANT, Scalar::all(backgroundMin)); int ksize = randomBlur ? (unsigned)rng % - : ;
if( ksize > )
{
ksize = ksize* + ;
GaussianBlur(patch, patch, Size(ksize, ksize), , );
} if( noiseRange > )
{
AutoBuffer<uchar> _noiseBuf( patchSize.width*patchSize.height*image.elemSize() );
Mat noise(patchSize, image.type(), (uchar*)_noiseBuf);
int delta = image.depth() == CV_8U ? : image.depth() == CV_16U ? : ;
rng.fill(noise, RNG::NORMAL, Scalar::all(delta), Scalar::all(noiseRange));
if( backgroundMin != backgroundMax ) addWeighted(patch, , noise, , -delta, patch);
else
{
for( int i = ; i <patchSize.height; i++ )
{
uchar* prow = patch.ptr<uchar>(i);
const uchar* nrow = noise.ptr<uchar>(i);
for( int j = ; 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 = ; k <; k++ )
{
Point2f pt0, pt1;
pt0.x = (float)(k == || k == ? : image.cols);
pt0.y = (float)(k < ? : image.rows);
pt1.x = (float)(T(,)*pt0.x + T(,)*pt0.y + T(,));
pt1.y = (float)(T(,)*pt0.x + T(,)*pt0.y + T(,)); 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 - ;
roi.height -= roi.y - ;
int dx = border - roi.x;
int dy = border - roi.y; if( (roi.width+border*)*(roi.height+border*) > buf.cols )
buf.create(, (roi.width+border*)*(roi.height+border*), image.type()); warped = Mat(roi.height + border*, roi.width + border*,
image.type(), buf.data); T(,) += dx;
T(,) += 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. 0
void PatchGenerator::setAffineParam(double lambda, double theta, double phi)
{
lambdaMin = . - lambda;
lambdaMax = . + lambda;
thetaMin = -theta;
thetaMax = theta;
phiMin = -phi;
phiMax = phi;
}
};

CMakeLists.txt

#Set minimum version requered
cmake_minimum_required(VERSION 2.4.)
#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. 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:: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
frame[y1:y2,x1:x2]=(,,)
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

[]TLD code run的更多相关文章

  1. Thread的run()与start()的区别

    Java的线程是通过java.lang.Thread类来实现的.VM启动时会有一个由主方法所定义的线程.可以通过创建Thread的实例来创建新的线程.每个线程都是通过某个特定Thread对象所对应的方 ...

  2. Thread’s start method and run method

    工作中用到了Thread,一开始用错了,仔细研究了一下,稍作整理. 前言,今天写代码居然这样写的 new Thread() { @Override public void run() { System ...

  3. OPENGL: WHY IS YOUR CODE PRODUCING A BLACK WINDOW?

      Introduction One of the most common problems for novice, and sometimes experienced, OpenGL program ...

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

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

  5. 基于Visual Studio Code搭建Vue开发环境

    安装node.js最新版 这里安装的是8.11.4版   image.png 更新npm至最新版 安装node.js后, npm默认版本为: 6.1.0   image.png 使用npm insta ...

  6. node.js运行配置(vs code非控制台输出)

    node.js运行配置(vs code非控制台输出) node  配置 简化  vs code 是非常强大的编译器,皆因它有有各种各样好用的插件. 在没有安装code runner插件之前,想要执行n ...

  7. 线程中start和run方法的区别

    先说java中实现多线程常用的两种方式:   1:继承Thread类,并重写run()方法   2:实现Runnable接口,实现run方法实际上Thread类也是实现了Runnable接口 [Jav ...

  8. 多线程爬坑之路-Thread和Runable源码解析

    多线程:(百度百科借一波定义) 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提 ...

  9. XSS 前端防火墙 —— 无懈可击的钩子

    昨天尝试了一系列的可疑模块拦截试验,尽管最终的方案还存在着一些兼容性问题,但大体思路已经明确了: 静态模块:使用 MutationObserver 扫描. 动态模块:通过 API 钩子来拦截路径属性. ...

随机推荐

  1. Jenkins结合shell脚本实现(gitLab/gitHub)前端项目自动打包部署服务器

    原始发布部署: 石器时代的我们,先是本地打包好项目,在去服务器上把原来的文件删了,然后回到本地copy到服务器: 这操看起来简单,实际部署的人就知道多烦了,假如来几个项目都要重新发布:那就爽了: 今天 ...

  2. Response重定向实现参数隐藏

    最近在弄一个SSH项目,前期已经做好了,现在的需求是进行单点登陆实现,涉及到重定向跳转(带有参数那种)情况,但是不能在地址栏上出现参数的信息,需要进行参数的隐藏跳转.由于时间比较急,本人没来得及开发一 ...

  3. C# 多线程 类构造函数 类方法之间的关系

    先定一个类,既有构造函数又有类方法: public class WriteNumber { /// <summary> /// 构造函数 /// </summary> publ ...

  4. ClientDataSet应用

    最近维护一个项目,里面用到ClientDataSet,由于之前接触ClientDataSet比较少,所以这个星期补了一下关于ClientDataSet的知识,并在此记录下我所了解到的并应用到实际项目中 ...

  5. echarts 去掉 x轴坐标

    symbol:'none', //这句就是去掉点的 smooth:true,

  6. Oralce数据库的优化

    Oralce数据库的优化(面试必问) (1) 选择最有效率的表名顺序(只在基于规则的优化器中有效):ORACLE 的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 ...

  7. FORTH 发展(部分)

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  8. JavaScript中事件委托(事件代理)详解

    在JavaScript的事件中,存在事件委托(事件代理),那么什么是事件委托呢? 事件委托在生活中的例子: 有三个同事预计会在周一收到快递.为签收快递,有两种办法:一是三个人在公司门口等快递:二是委托 ...

  9. 外网win10 64位环境下 为内网win7 32位安装三方包的最靠谱手段:python64位、32位全安装。

    经过一周的各种折磨,如题.以下是我的经验和教训. 我的外网是win10 64位,内网环境win7 32位.由于未知原因,anaconda无法安装!!! 其实最靠谱的安装三方包的还是whl包.但是很有可 ...

  10. Get teststep of specific type

    SoapUI Groovy : Check if test step is of specific type, such as : Wsdl, Rest, Jdbc, HTTP, Groovy etc ...