From 15eef606b8d04d9acf06a22997facd3fdf7ae61a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luka=20=C4=8Cehovin?= Date: Thu, 1 Sep 2016 11:47:00 +0100 Subject: [PATCH] Updating support for TraX protocol. --- CMakeLists.txt | 12 ++++++---- main_trax.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++ main_vot_trax.cpp | 38 ------------------------------- 3 files changed, 65 insertions(+), 43 deletions(-) create mode 100644 main_trax.cpp delete mode 100644 main_vot_trax.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 31e3044..a6c11d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,10 @@ FIND_PACKAGE( OpenCV REQUIRED ) link_directories ( ${OpenCV_LIB_DIR} ) MESSAGE(STATUS "OpenCV_LIB_DIR: ${OpenCV_LIB_DIR}") +IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") +ENDIF () + include_directories ( ${OpenCV_INCLUDE_DIRS} ) MESSAGE(STATUS "OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}") @@ -20,17 +24,15 @@ add_executable(kcf_vot main_vot.cpp vot.hpp) target_link_libraries(kcf_vot ${OpenCV_LIBS} kcf) # Try to find TraX header and library ... -FIND_FILE(TRAX_HEADER NAMES trax.h PATHS /home/vojirtom/qBT_dir/test/vot-toolkit-2016/native) +FIND_FILE(TRAX_HEADER NAMES trax.h) IF (EXISTS ${TRAX_HEADER}) GET_FILENAME_COMPONENT(TRAX_DIR ${TRAX_HEADER} DIRECTORY) ADD_DEFINITIONS(-DTRAX) # Added to enable TraX protocol support LINK_DIRECTORIES(${TRAX_DIR}) # Add library directory INCLUDE_DIRECTORIES(${TRAX_DIR}) # Add includes directory -ENDIF() -IF (EXISTS ${TRAX_HEADER}) - add_executable(kcf_trax main_vot_trax.cpp vot_trax.h) - target_link_libraries(kcf_trax ${OpenCV_LIBS} trax kcf) + add_executable(kcf_trax main_trax.cpp) + target_link_libraries(kcf_trax ${OpenCV_LIBS} kcf trax trax_opencv) ENDIF() diff --git a/main_trax.cpp b/main_trax.cpp new file mode 100644 index 0000000..4ffb24e --- /dev/null +++ b/main_trax.cpp @@ -0,0 +1,58 @@ +#include + +#include +#include "kcf.h" + +int main() +{ + trax::Image img; + trax::Region reg; + + KCF_Tracker tracker; + cv::Mat image; + cv::Rect rectangle; + + trax::Server handle(trax::Configuration(TRAX_IMAGE_PATH | TRAX_IMAGE_MEMORY | TRAX_IMAGE_BUFFER, TRAX_REGION_RECTANGLE), trax_no_log); + + std::cout << handle.configuration().format_region << " " << TRAX_SUPPORTS(handle.configuration().format_region, TRAX_REGION_POLYGON) << std::endl; + + while(true) + { + + trax::Properties prop; + + int tr = handle.wait(img, reg, prop); + + if (tr == TRAX_INITIALIZE) { + + rectangle = trax::region_to_rect(reg); + image = trax::image_to_mat(img); + + // Dynamically configure tracker + tracker.m_use_scale = prop.get("use_scale", true); + tracker.m_use_color = prop.get("use_color", true); + tracker.m_use_subpixel_localization = prop.get("use_subpixel_localization", true); + tracker.m_use_subgrid_scale = prop.get("use_subgrid_scale", true); + tracker.m_use_multithreading = prop.get("use_multithreading", true); + tracker.m_use_cnfeat = prop.get("use_cnfeat", true); + + tracker.init(image, rectangle); + + } else if (tr == TRAX_FRAME) { + + image = trax::image_to_mat(img); + tracker.track(image); + BBox_c bb = tracker.getBBox(); + rectangle = bb.get_rect(); + + } else { + break; + } + + trax::Region status = trax::rect_to_region(rectangle); + handle.reply(status, trax::Properties()); + + } + + return EXIT_SUCCESS; +} diff --git a/main_vot_trax.cpp b/main_vot_trax.cpp deleted file mode 100644 index 2fb4d28..0000000 --- a/main_vot_trax.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#include "kcf.h" - -#define VOT_RECTANGLE -#include "trax.h" -#include "vot_trax.h" - -int main() -{ - VOT vot; // Initialize the communcation - - VOTRegion region = vot.region(); // Get region and first frame - string path = vot.frame(); - - cv::Mat image = cv::imread(path); - - KCF_Tracker tracker; - - cv::Rect init_rect; - region.get(init_rect); - tracker.init(image, init_rect); - - BBox_c bb; - while (true) { - path = vot.frame(); // Get the next frame - if (path.empty()) break; // Are we done? - - image = cv::imread(path); - tracker.track(image); - bb = tracker.getBBox(); - - region.set(bb.get_rect()); - vot.report(region); // Report the position of the tracker - } - - return EXIT_SUCCESS; -} \ No newline at end of file -- 2.39.2