openTLD算法在opencv3的PatchGenerator
由于opencv3的各种版本相对于opencv2的版本已经改变了很多内容,openTLD跟踪算法所依赖的一些函数在opencv3中已经消失了,为此需要对openTLD进行适当修改才能使之在opencv3的各种版本中运行。
加入如下文件,并在对应的地方include头文件即可。
PatchGenerator.h
- #include <opencv2/opencv.hpp>
- #ifndef PATCHGENERATOR_H
- #define <span style="font-family: Arial, Helvetica, sans-serif;">PATCHGENERATOR_H</span>
- namespace cv
- {
- class CV_EXPORTS 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
- #include <opencv2/opencv.hpp>
- #include <PatchGenerator.h>
- namespace cv
- {
- /*
- The code below implements keypoint detector, fern-based point classifier and a planar object detector.
- References:
- 1. Mustafa Özuysal, Michael Calonder, Vincent Lepetit, Pascal Fua,
- "Fast KeyPoint Recognition Using Random Ferns,"
- IEEE Transactions on Pattern Analysis and Machine Intelligence, 15 Jan. 2009.
- 2. Vincent Lepetit, Pascal Fua,
- "Towards Recognizing Feature Points Using Classification Trees,"
- Technical Report IC/2004/74, EPFL, 2004.
- */
- 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);
- }
- else
- warpAffine(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. 0
- void PatchGenerator::setAffineParam(double lambda, double theta, double phi)
- {
- lambdaMin = 1. - lambda;
- lambdaMax = 1. + lambda;
- thetaMin = -theta;
- thetaMax = theta;
- phiMin = -phi;
- phiMax = phi;
- }
- };
原文 http://blog.csdn.net/j10527/article/details/51305087
openTLD算法在opencv3的PatchGenerator相关推荐
- BRISK算法在OpenCV3.0中的使用
BRISK算法在OpenCV3.0中的使用 在OpenCV3.0中一些局部特征相关的接口还是有一些改动的,因为最近在测试BRISK部分内容,所以将OpenCV3.0中BRISK的使用贴出来,其他局部特 ...
- 多个物体轮廓c语言提取算法,C++ opencv-3.4.1 提取不规则物体的轮廓
在学习opencv的时候,对一张照片,需要标注照片上物体的不规则轮廓. 如图: 使用opencv进行物体的轮廓处理,关键在于对照片的理解,前期的照片处理的越好最后调用api出来的结果就越接近理想值. ...
- 在opencv3中的机器学习算法
在opencv3.0中,提供了一个ml.cpp的文件,这里面全是机器学习的算法,共提供了这么几种: 1.正态贝叶斯:normal Bayessian classifier 我已在另外一篇博文中介 ...
- 在opencv3中实现机器学习之:利用svm(支持向量机)分类
svm分类算法在opencv3中有了很大的变动,取消了CvSVMParams这个类,因此在参数设定上会有些改变. opencv中的svm分类代码,来源于libsvm. #include "s ...
- openCV学习笔记(十二) —— 人脸识别算法(1/3)—— 特征脸 EigenFaces
一.原理 opencv支持3种人脸识别的算法,分别是: 1. Eigen Faces PCA(特征脸方法) 2. Fisher Faces LDA(线性判别分析) 3. ...
- 运动目标的背景建模-混合高斯背景建模和KNN模型建模的OpenCV代码实现
图像处理开发需求.图像处理接私活挣零花钱,请加微信/QQ 2487872782 图像处理开发资料.图像处理技术交流请加QQ群,群号 271891601 运动检测通常用于分析视频序列中的移动目标,如车辆 ...
- 一种基于人脸追踪和特征分析的疲劳驾驶预警平台
目录 整体描述 1. 嵌入式端: 2.程序端: 3. 辅助功能: 4. 项目整体工作流程 5. 不足之处 效果演示 程序源码 算法篇 基于AdaBoost级联分类器的人脸/眼睛位置检测算法 基于特征脸 ...
- python 立体匹配算法_OpenCV3.4两种立体匹配算法效果对比
以OpenCV自带的Aloe图像对为例: 1.BM算法(Block Matching) 参数设置如下: int numberOfDisparities = ((imgSize.width / 8) + ...
- OpenCV编程入门——启程前的准备
一.OpenCV官方例程与赏析 1.彩色目标跟踪:Camshift(Continuously Adaptive Mean-SHIFT) 说明:程序的用法是根据鼠标框选区域的色度光谱来进行摄像头读入视频 ...
最新文章
- MYSQL出错代码列表
- 美空管官员:政府停摆致人手不足 危及航空安全
- 中国血液制品行业供给预测与投资风险分析报告2022版
- EasyUI combobox
- 【经验分享】产品、运营人如何告别重复的数据分析工作?
- 前端学习(675):if else if
- Android手势锁实现
- java 数据队列_Java 数据结构 - 队列
- SQLi LABS Less 23 联合注入+报错注入+布尔盲注
- 搜索 + 剪枝 --- POJ 1101 : Sticks
- JAVA中RGB字串转换为颜色
- 系统辨识总论(System Identification)
- 物联网全栈教程(1)——总目录
- Python中的shuffle()函数
- 给本本换硬盘,直接克隆旧盘!
- [HTML] kbd 标签
- 程序自动修复相关工作总结
- php 统计汉字,PHP 统计实时统计汉字个数和区别
- Oracle索引(Index)创建使用
- Android Wi-Fi 修改国家码(QCOM平台)
热门文章
- linux 中断机制的处理过程
- java spring context_java将对象注册到spring context中 | 学步园
- Ubunt php连接oracle,uBuntu PHP Oracle扩展 OCI8安装
- linux 软件装到hone,如何在Linux系统安装Apollo
- php 安装oracle扩展,win PHP7安装oracle扩展
- chrome 适配调试_移动端适配
- 过年回家抢票不求人,试试这个开源抢票神器吧!
- 手下两个应届生,一个踏实喜欢加班,一个技术强挑活,怎么选?
- 皮一皮:我也想做这样的房东,善解人意、为他人着想...
- 人类快感程度体验等级