forked from bilderbuchi/OpenTLD
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ xcuserdata/ | |
*.dll | ||
*.exe | ||
*.so | ||
bin/ | ||
|
||
# Packages # | ||
############ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
cmake_minimum_required(VERSION 2.4.6) | ||
|
||
#just to avoid the warning | ||
if(COMMAND cmake_policy) | ||
cmake_policy(SET CMP0003 NEW) | ||
endif(COMMAND cmake_policy) | ||
|
||
#set project name | ||
project(TLD) | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) | ||
#OpenCV | ||
find_package(OpenCV 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 directory | ||
include_directories ( | ||
${PROJECT_SOURCE_DIR}/include | ||
${OpenCV_INCLUDE_DIRS} | ||
) | ||
#libraries | ||
add_library(tld_utils src/tld_utils.cpp) | ||
#executables | ||
add_executable(run_tld src/run_tld.cpp) | ||
#link the libraries | ||
target_link_libraries(run_tld tld_utils ${OpenCV_LIBS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <opencv2/opencv.hpp> | ||
|
||
void drawBox(cv::Mat& image, CvRect box); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <opencv2/opencv.hpp> | ||
#include <tld_utils.h> | ||
#include <iostream> | ||
using namespace cv; | ||
|
||
CvRect box; | ||
bool drawing_box = false; | ||
bool gotBB = false; | ||
Mat gray; | ||
//bounding box mouse callback | ||
void mouseHandler(int event, int x, int y, int flags, void *param){ | ||
switch( event ){ | ||
case CV_EVENT_MOUSEMOVE: | ||
if( drawing_box ){ | ||
box.width = x-box.x; | ||
box.height = y-box.y; | ||
} | ||
break; | ||
case CV_EVENT_LBUTTONDOWN: | ||
drawing_box = true; | ||
box = cvRect( x, y, 0, 0 ); | ||
break; | ||
case CV_EVENT_LBUTTONUP: | ||
drawing_box = false; | ||
if( box.width < 0 ){ | ||
box.x += box.width; | ||
box.width *= -1; | ||
} | ||
if( box.height < 0 ){ | ||
box.y += box.height; | ||
box.height *= -1; | ||
} | ||
gotBB = true; | ||
break; | ||
} | ||
} | ||
|
||
int main(int argc, char * argv[]){ | ||
//Init camera | ||
VideoCapture capture; | ||
capture.open(0); | ||
if (!capture.isOpened()) | ||
{ | ||
cout << "capture device failed to open!" << endl; | ||
return 1; | ||
} | ||
|
||
Mat frame; | ||
//Register mouse callback to draw the bounding box | ||
cvNamedWindow("TLD",CV_WINDOW_AUTOSIZE); | ||
cvSetMouseCallback( "TLD", mouseHandler, NULL ); | ||
//Initialization | ||
while(!gotBB) | ||
{ | ||
//get frame | ||
capture >> frame; | ||
cvtColor(frame, gray, CV_RGB2GRAY); | ||
drawBox(gray,box); | ||
imshow("TLD", gray); | ||
if (cvWaitKey(33) == 'q') | ||
break; | ||
} | ||
//save init frame | ||
imwrite("init.jpg",gray); | ||
//train classifier | ||
//train(gray,box,params); | ||
//Run-time | ||
while(true) | ||
{ | ||
//get frame | ||
capture >> frame; | ||
cvtColor(frame, gray, CV_RGB2GRAY); | ||
//evaluate classifier | ||
//estimate errors | ||
//update classifier | ||
//display | ||
imshow("TLD", gray); | ||
if (cvWaitKey(33) == 'q') | ||
break; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <tld_utils.h> | ||
using namespace cv; | ||
|
||
void drawBox(Mat& image, CvRect box){ | ||
rectangle( image, cvPoint(box.x, box.y), cvPoint(box.x+box.width,box.y+box.height),cvScalarAll(255) ); | ||
} | ||
|