在TX1上配置TLD算法环境遇到的问题(二)
来源:互联网 发布:python安装教程 编辑:程序博客网 时间:2024/05/20 22:00
安装完opencv3.1,正式开始编译TLD,一开始就遇到了之前的问题,TLD中的算法,新版opencv不包含,更重要的是,在opencv2.4.8中,我们可以利用include legacy.hpp来使编译通过,但是在opencv3.1 中,完全移除了legacy.hpp,下图是官网上的介绍。
即使复制一个legacy文件夹过来,也无法编译通过,会报错
error: 'cv::EM' has not been declares通过在网上的寻找,找到了解决方法,来自于http://blog.csdn.net/j10527/article/details/51305087
首先建立一个头文件PatchGenerator.h
#include <opencv2/opencv.hpp> #ifndef PATCHGENERATOR_H #define PATCHGENERATOR_H 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
1
2
然后,需要在TLD.cpp开头加入如下代码
#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 UsingRandom Ferns,"
IEEE Transactions on Pattern Analysis andMachine Intelligence, 15 Jan. 2009.
2. Vincent Lepetit, Pascal Fua,
"Towards Recognizing Feature PointsUsing Classification Trees,"
Technical Report IC/2004/74, EPFL, 2004.
*/
const intprogressBarSize = 50;
////////////////////////////Patch Generator //////////////////////////////////
static const doubleDEFAULT_BACKGROUND_MIN = 0;
static const doubleDEFAULT_BACKGROUND_MAX = 256;
static const doubleDEFAULT_NOISE_RANGE = 5;
static const doubleDEFAULT_LAMBDA_MIN = 0.6;
static const doubleDEFAULT_LAMBDA_MAX = 1.5;
static const doubleDEFAULT_THETA_MIN = -CV_PI;
static const doubleDEFAULT_THETA_MAX = CV_PI;
static const doubleDEFAULT_PHI_MIN = -CV_PI;
static const doubleDEFAULT_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)
{
}
voidPatchGenerator::generateRandomTransform(Point2f srcCenter, Point2fdstCenter,
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 affinetransformation 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);
}
voidPatchGenerator::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);
}
voidPatchGenerator::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);
}
}
}
}
voidPatchGenerator::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 - r.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 areassumed to be symmetrical: lambda w.r.t. 1, theta and phi w.r.t. 0 voidPatchGenerator::setAffineParam(double lambda, double theta, double phi) {lambdaMin = 1. - lambda; lambdaMax = 1. + lambda; thetaMin = -theta; thetaMax =theta; phiMin = -phi; phiMax = phi; } };
这样就能解决第一个错误,第二个错误是在LKTtacker.cpp中的,错误是
error: 'vector' has not been declared
解决方法很简单,就在在LKTtacker.cpp文件开头加入
using namespace std;
这样就能通过TLD的编译。
通过编译之后就可以按照作者的步骤运行了,此时有个大问题要注意!!!!!
.run_tld -p ../parameters.yml
这句话一定哪里都不能落下,博主因为疏忽少加了后面的.yml,导致一大堆问题的出现,研究了好几天,发现是命令输入错了,浪费好多时间,气的想砸电脑!!!如下的两个报错,可能就是命令输入错误的原因。
init done
Initial Bounding Box = x:140 y:83 h:23 w:31
terminate called after throwing an instanceof 'std::bad_alloc'
what(): std::bad_alloc
Aborted
init done
Initial Bounding Box = x:559 y:281 h:52w:36
Created 2020024 bounding boxes
Found 0 good boxes, 0 bad boxes
Best Box: 557 281 52 36
Bounding box hull: 2147483647 2147483647-2147483647 -2147483647
OpenCV Error: Assertion failed(dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0)) inresize, file/tmp/binarydeb/ros-kinetic-opencv3-3.2.0/modules/imgproc/src/imgwarp.cpp, line3493
terminate called after throwing an instanceof 'cv::Exception'
what(): /tmp/binarydeb/ros-kinetic-opencv3-3.2.0/modules/imgproc/src/imgwarp.cpp:3493:error: (-215) dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y> 0) in function resize
Aborted
另外,如果报错如下
VIDEOIO ERROR: V4L2: Pixel format ofincoming image is unsupported by OpenCV
Unable to stop the stream: Invalid argument
capture device failed to open!
说明程序没有找到对应的摄像头设备,此时先拔出摄像头,通过命令
ls /dev/
查看当前有什么设备,然后再插入摄像头,再用之前的命令,查看多了video几,一般是video1,再将run_tld.cpp文件中的main函数第二行改为
capture.open(1);
就解决了问题。
1 0
- 在TX1上配置TLD算法环境遇到的问题(二)
- 在TX1上配置TLD算法环境遇到的问题(一)
- Lua 在VS上的环境配置(二)
- 在Tomcat上配置struts2环境时遇到 “Error filterstart” 问题的解决方法
- tx1调试车辆检测遇到的问题
- TX1上使用Faster-RCNN训练自己的训练集遇到的问题与解决
- 在linux上搭建hadoop环境所遇到的问题
- NVIDIA TX1环境配置(一)---刷机
- TLD算法概述(二)
- TLD算法的崩溃问题
- 在eclipse中配置struts2环境遇到的问题
- 在centos7上配置caffe所遇到的一些问题
- 在Ubuntu上配置TensorFlow,Eclipse+PyDev遇到的问题
- 总结在云服务器上配置tomcat遇到的问题
- tld使用中遇到的问题
- 在windows server 2008 R2上配置PHP(zend framework框架)遇到的问题
- 在156环境上搭建满配环境时遇到的问题和解决办法
- TLD算法环境搭建
- POJ
- 不挂科第二章 C++重载构造函数
- 如何精读一本书
- nginx负载均衡【nginx】
- TensorFlow升级到1.0版本的问题
- 在TX1上配置TLD算法环境遇到的问题(二)
- 迪克特斯拉最短路算法的C实现
- Cooking Competition
- C语言入门简单例题
- HD 2438 Turn the corner (三分&&计算几何&&经典问题)
- ACMjavaP2011
- 正则表达式
- 进制的相互转换
- 大梦