Skip to content

Commit

Permalink
cpp branch initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
alantrrs committed Jun 3, 2011
1 parent 030c4e1 commit 4d111af
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -59,6 +59,7 @@ xcuserdata/
*.dll
*.exe
*.so
bin/

# Packages #
############
Expand Down
28 changes: 28 additions & 0 deletions CMakeLists.txt
@@ -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})
3 changes: 3 additions & 0 deletions include/tld_utils.h
@@ -0,0 +1,3 @@
#include <opencv2/opencv.hpp>

void drawBox(cv::Mat& image, CvRect box);
82 changes: 82 additions & 0 deletions src/run_tld.cpp
@@ -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;
}
7 changes: 7 additions & 0 deletions src/tld_utils.cpp
@@ -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) );
}

0 comments on commit 4d111af

Please sign in to comment.