본문 바로가기

Tracking

OpenTLD 설정

OpenTLD는 Matlab과 C++로 구성되어 있다.

나의 컴퓨터 환경은 MatlabR2011a와 visual studio2010 그리고 opencv2.4.2이며 64Bit 환경이다.

1. 먼저 OpenCV를 컴퓨터에 설치한다. OpenVC설치에 대해서는 생략한다.

2. 64Bit Matlab을 실행시켜서 OpenTLD가 있는 폴더로 이동한다.

3. Matlab 화면에서 mex -setup을 실행시킨다.

  위 그림에서 붉은색 원에 표시된 부분이 내가 직접 입력한 부분이다. 이와 같이 하면 Matlab이 Visual studio 컴파일러를 사용할 수 있다.

4. 지금 compile.m을 run시키면 아래와 같은 에러가 출력된다.


PC
lk.cpp
lk.cpp(18) : fatal error C1083: 포함 파일을 열 수 없습니다. 'cv.h': No such file or directory
 
  C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Compile of 'lk.cpp' failed.
 
??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> compile at 32
    eval(['mex lk.cpp -O' include lib]);
 
>>

 OpenCV가 Matlab에 연결이 안되어서 발생하는 문제이다. 이를 해결하기 위해서 compile.m 파일을 수정하여야 한다.

if ispc
    disp('PC');
    include = ' -IC:\opencv_2.4.2\include\opencv\ -IC:\opencv_2.4.2\include\ -IC:\opencv_2.4.2\build\include\';
    libpath = 'C:\opencv_2.4.2\build\x64\vc10\lib';
    files = dir([libpath '*.lib']);

위와 같이 compile.m에서 붉은색에 표시된 바와같이 OpenCV의 경로를 설정해 주어야 한다. 나는 64Bit환경이기 때문에 라이브러리 경로를 x64라이브러리로 연결하였다.

5. 다시 compile.m을 실행하면 또 에러가 발생한다.

´PC
lk.cpp
c:\program files\matlab\r2011a\extern\include\matrix.h(337) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
lk.cpp(175) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
lk.cpp(175) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
lk.cpp(176) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
lk.cpp(176) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
lk.cpp(177) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
lk.cpp(177) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data

C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Compile of 'lk.cpp' failed.

??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> compile at 32
eval(['mex lk.cpp -O' include lib]);

문제 해결을 위해서 lk.cpp, fern.cpp, and bb_overlap.cpp 각 파일의 아래 해당 코드에 주석처리를 해야 한다.

//#ifdef _CHAR16_T

//#define CHAR16_T

//#endif

6. 다시 compile.m을 실행하면 다음 에러 발생한다.

PC
   C:\Users\sjhyun\AppData\Local\Temp\mex_3j7TwB\templib.x 라이브러리 및 C:\Users\sjhyun\AppData\Local\Temp\mex_3j7TwB\templib.exp 개체를 생성하고 있습니다.
lk.obj : error LNK2019: _cvReleaseImage 외부 기호(참조 위치: "void __cdecl normCrossCorrelation(struct _IplImage *,struct _IplImage *,struct CvPoint2D32f *,struct CvPoint2D32f *,int,char *,float *,int,int)" (?normCrossCorrelation@@YAXPAU_IplImage@@0PAUCvPoint2D32f@@1HPADPAMHH@Z) 함수)에서 확인하지 못했습니다.
lk.obj : error LNK2019: _cvMatchTemplate 외부 기호(참조 위치: "void __cdecl normCrossCorrelation(struct _IplImage *,struct _IplImage *,struct CvPoint2D32f *,struct CvPoint2D32f *,int,char *,float *,int,int)" (?normCrossCorrelation@@YAXPAU_IplImage@@0PAUCvPoint2D32f@@1HPADPAMHH@Z) 함수)에서 확인하지 못했습니다.
lk.obj : error LNK2019: _cvGetRectSubPix 외부 기호(참조 위치: "void __cdecl normCrossCorrelation(struct _IplImage *,struct _IplImage *,struct CvPoint2D32f *,struct CvPoint2D32f *,int,char *,float *,int,int)" (?normCrossCorrelation@@YAXPAU_IplImage@@0PAUCvPoint2D32f@@1HPADPAMHH@Z) 함수)에서 확인하지 못했습니다.
lk.obj : error LNK2019: _cvCreateImage 외부 기호(참조 위치: "void __cdecl normCrossCorrelation(struct _IplImage *,struct _IplImage *,struct CvPoint2D32f *,struct CvPoint2D32f *,int,char *,float *,int,int)" (?normCrossCorrelation@@YAXPAU_IplImage@@0PAUCvPoint2D32f@@1HPADPAMHH@Z) 함수)에서 확인하지 못했습니다.
lk.obj : error LNK2019: _cvCalcOpticalFlowPyrLK 외부 기호(참조 위치: _mexFunction 함수)에서 확인하지 못했습니다.
lk.obj : error LNK2019: _cvAlloc 외부 기호(참조 위치: _mexFunction 함수)에서 확인하지 못했습니다.
lk.mexw32 : fatal error LNK1120: 6개의 확인할 수 없는 외부 참조입니다.
 
  C:\PROGRA~2\MATLAB\R2011A\BIN\MEX.PL: Error: Link of 'lk.mexw32' failed.
 
??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> compile at 32
    eval(['mex lk.cpp -O' include lib]);

여기서부터 내가 정확히 어떻게 문제를 해결했는지 기억이 나질 않는다. ㅜ.ㅜ 삽질을 너무 많이 해서...기록을 계속 한다고 했는데도 작업한 순서가 꼬여버렸다.

먼저 했던 작업은

http://www.mathworks.co.kr/support/solutions/en/data/1-D5W493/?solution=1-D5W493
에 패치 받아서 c드라이브에 카피

그 다음에 메트램 커맨드 창에 아래 명령 실행

>> unzip c:\VS2010MEXSupport.zip, matlabroot;
>> mex -setup

그런데 문제가 해결되지 않았던것 같다. 아마 여기까지 하면 compile.m까지는 넘어갔는데 run_TLD.m을 run시키면 무슨 파일이 64비트용이 아니라고 하던가 아니면 lk(0)을 실행할 수 없다고 하던가, lk.mexw64가 64비트용 파일이 아니라고 계속 에러를 내뿜었다. 실제 Matlab창에 lk(0)을 호출하면 바로 에러를 벧어버린다. 이걸 내가 어떻게 해결했더라....아...미치겠다..기억이 안난다. ㅜ.ㅜ 바로바로 정리 했어야 하는데...
아무튼 동작이 않되어서 2일동안 엄청나게 삽질을 해대었다.

 

정상적으로 설정이 되었다.면 run_TLD.m을 run시키면 오토바이를 찼는 화면이 출력된다. 그런데 cam으로 직접 받아서 설정하는 방법은 없는 것 같다. 없는건지 내가 몾하는건지...-.-;;

혹시 모르니 성공한 코드를 첨부한다. 

OpenTLD-master_sjh.vol3.egg

OpenTLD-master_sjh.vol2.egg

OpenTLD-master_sjh.vol1.egg