VS2010+MATLAB2010b运行TLD

来源:互联网 发布:雷石世纪软件 编辑:程序博客网 时间:2024/06/06 00:52

转载自http://www.cnblogs.com/moondark/archive/2012/04/10/2441081.html以及

http://www.cnblogs.com/moondark/archive/2012/04/12/2444602.html

感谢原作者的无私奉献!

TLD即Tracking Learning Detection,Zdenek Kalal大神在其主页上给出的代码http://info.ee.surrey.ac.uk/Personal/Z.Kalal/tld.html,根据网上看到的视频,ZK大神的idea和程序真是amazing,我也想拿来研究一下~
  先说一下,我电脑的程序配置吧:WIN7+VS2010+MATLAB2010b+OpenCV2.3,事实上,这个程序在我电脑上始终没有跑起来,我通过各方面找到的提示进行成功编译了,却仍然不能正常运行,后来我在其它电脑上用WIN7+VS2005+MATLAB2011a+OpenCV2.2成功的运行起来了。

  好吧,废话不多说,来看看如何进行配置吧:

  跑此程序,首先应该运行compile.m程序,然后再运行run_TLD.m,在任何机器上,首先得保证matlab的mex命令设置正确,其可通过

mex -setup

  命令实现,然后打开compile.m文件:

复制代码
源代码中:include = ' -Ic:\OpenCV2.2\include\opencv\ -Ic:\OpenCV2.2\include\';libpath = 'c:\OpenCV2.2\lib\';需改为自己电脑中的路径,如我的就是: include = ' -ID:\OpenCV2.3\vs2010\install\include\opencv\ -ID:\OpenCV2.3\vs2010\install\include\ -ID:\OpenCV2.3\vs2010\install\include\opencv2\'; libpath = 'D:\OpenCV2.3\vs2010\install\lib\';当然这些只是针对windows pc改的,若换成其它系统环境,则在相应的地方更改
复制代码

  这样改好了,一般就是能够正常编译运行了,然而,若用VS2010则又有不同,根据作者的说法https://github.com/zk00006/OpenTLD/wiki/Installation:

复制代码
You will need some extension toolboxes for Matlab, see below.1) Install OpenCV2.2: compile OpenCV, set system PATH variable to link to OpenCV DLLs2) Setup mex compiler in Matlab: run: mex -setup, select Visual Studio 2010 compiler from the list3) Compilation of mex files: check paths in 'compile.m' file, run 'compile.m'3.1) If you are using Matlab 2011a, in TLD source, comment out the following lines in lk.cpp, fern.cpp, and bb_overlap.cpp (Otherwise, you will get an error about int being undefined which is a no-no in 2010):#ifdef _CHAR16_T #define CHAR16_T #endif 4) run 'run_TLD.m', TLD should track a motorbike
复制代码

  即如红色部分所示,你需要把

复制代码
lk.cpp, fern.cpp, and bb_overlap.cpp这几个文件中的这几行代码#ifdef _CHAR16_T #define CHAR16_T #endif 注释掉
复制代码

  好吧,按照以上方法做了,我的能成功编译了~

  但在run_TLD.m的时候还是出现了一些莫名奇妙的错误,我正在努力debug中,实在不行,就将就着VS2005了

  调别人代码最郁闷的事,就是按照别人说的做了,却得不到预期的结果……

   唔, 后来成功了, see:

在环境WIN7+VS2010+MATLAB2010b+OpenCV2.3.1,我一直没能跑起来,极度郁闷……

  今天在搜索matrix.hpp的时候,突然发现GitHub上面,居然有人碰到的问题跟我一样,之前遇到的error如下:

复制代码
 1 ??? Unexpected Standard exception from MEX file. 2 What() is:/Users/liam/projects/OpenCV-2.3.1/modules/core/src/matrix.cpp:1305: 3 error: (-27) create() called for the missing output array in function create 4  5 Error in ==> tldTracking at 30 6 xFJ = lk(2,tld.img{I}.input,tld.img{J}.input,xFI,xFI); % track all points by 7 Lucas-Kanade tracker from frame I to frame J, estimate Forward-Backward error, 8 and NCC for each point 9 10 Error in ==> tldProcessFrame at 2511 [tBB tConf tValid tld] = tldTracking(tld,tld.bb(:,I-1),I-1,I); % frame-to-frame12 tracking (MedianFlow)13 14 Error in ==> tldExample at 4115 tld = tldProcessFrame(tld,i); % process frame i16 17 Error in ==> run_TLD at 4318 [bb,conf] = tldExample(opt);
复制代码

  居然在混编下出错,我当时已经放弃了,因为我根本就不知道是什么问题,但今天偶然看到了,解决办法是对于lk.cpp文件中的186行,这里看仔细了,是这一行:

      cvCalcOpticalFlowPyrLK( IMG[J], IMG[I], PYR[J], PYR[I], points[1], points[2], nPts, cvSize(win_size,win_size), Level, 0     , 0, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), CV_LKFLOW_INITIAL_GUESSES | CV_LKFLOW_PYR_A_READY | CV_LKFLOW_PYR_B_READY );

  将上述红色的0改为status,如下:

 cvCalcOpticalFlowPyrLK( IMG[J], IMG[I], PYR[J], PYR[I], points[1], points[2], nPts, cvSize(win_size,win_size), Level, status     , 0, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), CV_LKFLOW_INITIAL_GUESSES | CV_LKFLOW_PYR_A_READY | CV_LKFLOW_PYR_B_READY );

  这样修改之后,注意,需要重新运行compile.m,然后运行run_TLD.m即可,得到的结果还是有点奇怪的,在VS2005+OPENCV2.2中,是存在跟丢的情况,每秒处理的帧数有16帧左右,在VS2010+OPENCV2.3中,不存在跟丢的情况,但每秒处理的帧数为12帧左右~~

  我的源码下载: 请重击我



0 0
原创粉丝点击