Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ endif(SILENT_WORK)
include(CheckIncludeFileCXX)
check_include_file_cxx(filesystem HAVE_FILESYSTEM)
if(HAVE_FILESYSTEM)
add_definitions(-DHAVE_FILESYSTEM)
message("Founded filesystem header")
else(HAVE_FILESYSTEM)
add_definitions(-DHAVE_EXPERIMENTAL_FILESYSTEM)
message("Do not found filesystem header")
endif(HAVE_FILESYSTEM)

Expand Down
2 changes: 1 addition & 1 deletion async_detector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(HEADERS AsyncDetector.h
# добавляем include директории
# ----------------------------------------------------------------------------
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/../src
${PROJECT_SOURCE_DIR}/../src/common
${PROJECT_SOURCE_DIR}/../src/mtracking
${PROJECT_SOURCE_DIR}/../src/Detector
${PROJECT_SOURCE_DIR}/../src/Detector/vibe_src
${PROJECT_SOURCE_DIR}/../src/Detector/Subsense
Expand Down
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif(BUILD_CARS_COUNTING)
# добавляем include директории
# ----------------------------------------------------------------------------
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/../src
${PROJECT_SOURCE_DIR}/../src/common
${PROJECT_SOURCE_DIR}/../src/mtracking
${PROJECT_SOURCE_DIR}/../src/Detector
${PROJECT_SOURCE_DIR}/../src/Detector/vibe_src
${PROJECT_SOURCE_DIR}/../src/Detector/Subsense
Expand Down
11 changes: 6 additions & 5 deletions example/MotionDetectorExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MotionDetectorExample final : public VideoExample
m_logger->info("MotionDetectorExample::InitDetector");

//m_minObjWidth = frame.cols / 20;
m_minObjWidth = 2;
m_minObjWidth = 4;

config_t config;
config.emplace("useRotatedRect", "0");
Expand All @@ -56,7 +56,7 @@ class MotionDetectorExample final : public VideoExample
config.emplace("updateFactor", "16");
break;
case tracking::Detectors::Motion_MOG:
config.emplace("history", std::to_string(cvRound(50 * m_fps)));
config.emplace("history", std::to_string(cvRound(5000 * m_fps)));
config.emplace("nmixtures", "3");
config.emplace("backgroundRatio", "0.7");
config.emplace("noiseSigma", "0");
Expand Down Expand Up @@ -97,7 +97,7 @@ class MotionDetectorExample final : public VideoExample

if (!m_trackerSettingsLoaded)
{
m_trackerSettings.SetDistance(tracking::DistCenters);
m_trackerSettings.SetDistance(tracking::DistJaccard);
m_trackerSettings.m_kalmanType = tracking::KalmanLinear;
m_trackerSettings.m_filterGoal = tracking::FilterCenter;
m_trackerSettings.m_lostTrackType = tracking::TrackNone; // Use visual objects tracker for collisions resolving. Used if m_filterGoal == tracking::FilterRect
Expand Down Expand Up @@ -197,8 +197,9 @@ class MotionDetectorExample final : public VideoExample
auto velocity = sqrt(sqr(track.m_velocity[0]) + sqr(track.m_velocity[1]));
if (track.IsRobust(4, // Minimal trajectory size
0.3f, // Minimal ratio raw_trajectory_points / trajectory_lenght
cv::Size2f(0.2f, 5.0f))) // Min and max ratio: width / height
//velocity > 30 // Velocity more than 30 pixels per second
cv::Size2f(0.2f, 5.0f), // Min and max ratio: width / height
2))
//velocity > 30 // Velocity more than 30 pixels per second
{
//track_t mean = 0;
//track_t stddev = 0;
Expand Down
9 changes: 8 additions & 1 deletion example/VideoExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,14 @@ void VideoExample::SyncProcess()

int64 startLoopTime = cv::getTickCount();

//double fps = capture.get(cv::CAP_PROP_FPS);
//double readPeriodSeconds = 2.;
//int readPeriodFrames = cvRound(readPeriodSeconds * fps);

for (;;)
{
//int currFramesPos = cvRound(capture.get(cv::CAP_PROP_POS_FRAMES));

size_t i = 0;
for (; i < m_batchSize; ++i)
{
Expand All @@ -177,6 +183,8 @@ void VideoExample::SyncProcess()
if (i < m_batchSize)
break;

//capture.set(cv::CAP_PROP_POS_FRAMES, currFramesPos + readPeriodFrames);

if (!m_isDetectorInitialized || !m_isTrackerInitialized)
{
cv::UMat ufirst = frameInfo.m_frames[0].GetUMatBGR();
Expand All @@ -202,7 +210,6 @@ void VideoExample::SyncProcess()

int64 t1 = cv::getTickCount();

regions_t regions;
Detection(frameInfo);
Tracking(frameInfo);
int64 t2 = cv::getTickCount();
Expand Down
6 changes: 5 additions & 1 deletion example/VideoExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ class VideoExample
bool m_isDetectorInitialized = false;
std::string m_inFile;
std::string m_outFile;
int m_fourcc = cv::VideoWriter::fourcc('h', '2', '6', '4'); //cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
#if 0
int m_fourcc = cv::VideoWriter::fourcc('h', '2', '6', '4');
#else
int m_fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
#endif
int m_startFrame = 0;
int m_endFrame = 0;
int m_finishDelay = 0;
Expand Down
66 changes: 29 additions & 37 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,39 @@
#include <opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>

// ----------------------------------------------------------------------

static void Help()
{
printf("\nExamples of the Multitarget tracking algorithm\n"
"Usage: \n"
" ./MultitargetTracker <path to movie file> [--example]=<number of example 0..7> [--start_frame]=<start a video from this position> [--end_frame]=<play a video to this position> [--end_delay]=<delay in milliseconds after video ending> [--out]=<name of result video file> [--show_logs]=<show logs> [--async]=<async pipeline> [--res]=<csv log file> [--settings]=<ini file> [--batch_size=<number of frames>] \n\n"
"Press:\n"
"\'m\' key for change mode: play|pause. When video is paused you can press any key for get next frame. \n\n"
"Press Esc to exit from video \n\n"
);
}

const char* keys =
{
"{ @1 |../data/atrium.avi | movie file | }"
"{ e example |1 | number of example 0 - MouseTracking, 1 - MotionDetector, 3 - YOLO TensorRT Detector, 4 - Cars counting | }"
"{ sf start_frame |0 | Start a video from this position | }"
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
"{ o out | | Name of result video file | }"
"{ show_logs |info | Show Trackers logs: trace, debug, info, warning, error, critical, off | }"
"{ g gpu |0 | Use OpenCL acceleration | }"
"{ a async |1 | Use 2 theads for processing pipeline | }"
"{ r log_res | | Path to the csv file with tracking result | }"
"{ cvat_res | | Path to the xml file in cvat format with tracking result | }"
"{ s settings | | Path to the ini file with tracking settings | }"
"{ bs batch_size |1 | Batch size - frames count for processing | }"
"{ wf write_n_frame |1 | Write logs on each N frame: 1 for writing each frame | }"
"{ hm heat_map |0 | For CarsCounting: Draw heat map | }"
"{ geo_bind |geo_bind.ini | For CarsCounting: ini file with geographical binding | }"
"{ contrast_adjustment |0 | Use contrast adjustment for frames before detection | }"
};

// ----------------------------------------------------------------------

///----------------------------------------------------------------------
int main(int argc, char** argv)
{
const char* keys =
{
"{ @1 |../data/atrium.avi | movie file | }"
"{ e example |1 | number of example 0 - MouseTracking, 1 - MotionDetector, 3 - YOLO TensorRT Detector, 4 - Cars counting | }"
"{ sf start_frame |0 | Start a video from this position | }"
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
"{ o out | | Name of result video file | }"
"{ show_logs |info | Show Trackers logs: trace, debug, info, warning, error, critical, off | }"
"{ g gpu |0 | Use OpenCL acceleration | }"
"{ a async |1 | Use 2 theads for processing pipeline | }"
"{ r log_res | | Path to the csv file with tracking result | }"
"{ cvat_res | | Path to the xml file in cvat format with tracking result | }"
"{ s settings | | Path to the ini file with tracking settings | }"
"{ bs batch_size |1 | Batch size - frames count for processing | }"
"{ wf write_n_frame |1 | Write logs on each N frame: 1 for writing each frame | }"
"{ hm heat_map |0 | For CarsCounting: Draw heat map | }"
"{ geo_bind |geo_bind.ini | For CarsCounting: ini file with geographical binding | }"
"{ contrast_adjustment |0 | Use contrast adjustment for frames before detection | }"
};

cv::CommandLineParser parser(argc, argv, keys);

Help();
std::cout << "\nExamples of the Multitarget tracking algorithm\n"
"Usage: \n"
" ./MultitargetTracker <path to movie file> [--example]=<number of example 0..7> [--start_frame]=<start a video from this position> [--end_frame]=<play a video to this position> [--end_delay]=<delay in milliseconds after video ending> [--out]=<name of result video file> [--show_logs]=<show logs> [--async]=<async pipeline> [--res]=<csv log file> [--settings]=<ini file> [--batch_size=<number of frames>] \n\n"
"Press:\n"
"\'m\' key for change mode: play|pause. When video is paused you can press any key for get next frame. \n\n"
"Press Esc to exit from video \n" << std::endl;

parser.printMessage();

bool useOCL = parser.get<int>("gpu") != 0;
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ else()
set(LIB_PTHREAD pthread)
endif()

include_directories(common)
include_directories(mtracking)

pybind11_add_module(pymtracking ${mtracker_python_src} ${mtracker_python_inc})
target_link_libraries(pymtracking PRIVATE mtracking mdetection ${OpenCV_LIBS} ${PYTHON_LIBRARY} pybind11::module)
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/BackgroundSubtract.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "defines.h"
#include "mtracking/defines.h"
#include "vibe_src/vibe.hpp"

#ifdef USE_OCV_BGFG
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/BaseDetector.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <memory>
#include "defines.h"
#include "mtracking/defines.h"

///
/// \brief The KeyVal struct
Expand Down
8 changes: 4 additions & 4 deletions src/Detector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ endif(USE_OCV_BGFG)

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/../src)
include_directories(${PROJECT_SOURCE_DIR}/../common)
include_directories(${PROJECT_SOURCE_DIR}/..)

if (CMAKE_COMPILER_IS_GNUCXX)
add_library(${PROJECT_NAME} SHARED
Expand All @@ -76,8 +76,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${detector_headers}")
install(TARGETS ${PROJECT_NAME}
EXPORT MTTrackingExports
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME})
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME})

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "libs")
2 changes: 1 addition & 1 deletion src/Detector/OCVDNNDetector.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fstream>
#include "OCVDNNDetector.h"
#include "nms.h"
#include "mtracking/nms.h"

///
/// \brief OCVDNNDetector::OCVDNNDetector
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/ONNXTensorRTDetector.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fstream>
#include "ONNXTensorRTDetector.h"
#include "nms.h"
#include "mtracking/nms.h"

///
/// \brief ONNXTensorRTDetector::ONNXTensorRTDetector
Expand Down
10 changes: 5 additions & 5 deletions src/Detector/tensorrt_onnx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${CUDA_INCLUDE_DIRS})
include_directories(${CUDNN_INCLUDE_DIR})
include_directories(${TensorRT_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/../../common)
include_directories(${PROJECT_SOURCE_DIR}/../../mtracking)

file(GLOB TENSORRT_SOURCE_FILES *.cpp common/*.cpp)
file(GLOB TENSORRT_HEADER_FILES *.h* common/*.h*)
Expand Down Expand Up @@ -91,9 +91,9 @@ target_link_libraries(${libname_rt} ${TENSORRT_LIBS})

install(TARGETS ${libname_rt}
EXPORT MTTrackingExports
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME})
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME})

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "libs")
2 changes: 1 addition & 1 deletion src/Detector/tensorrt_onnx/YoloONNX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define DEFINE_TRT_ENTRYPOINTS 1

#include "YoloONNX.hpp"
#include "../../common/defines.h"
#include "../../mtracking/defines.h"

//!
//! \brief Creates the network, configures the builder and creates the network engine
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/tensorrt_onnx/YoloONNXv11_instance.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "YoloONNX.hpp"
#include "../../common/defines.h"
#include "../../mtracking/defines.h"

///
/// \brief The YOLOv11_instance_onnx class
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/tensorrt_onnx/YoloONNXv7_instance.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "YoloONNX.hpp"
#include "../../common/defines.h"
#include "../../mtracking/defines.h"

///
/// \brief The YOLOv7_instance_onnx class
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/tensorrt_onnx/YoloONNXv8_instance.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "YoloONNX.hpp"
#include "../../common/defines.h"
#include "../../mtracking/defines.h"

///
/// \brief The YOLOv8_instance_onnx class
Expand Down
24 changes: 12 additions & 12 deletions src/Tracker/BaseTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ void CTracker::UpdateTrackingState(const regions_t& regions,
std::cout << "CTracker::UpdateTrackingState: m_tracks = " << colsTracks << ", regions = " << rowsRegions << std::endl;

int fontType = cv::FONT_HERSHEY_TRIPLEX;
double fontSize = 0.6;
cv::Scalar colorRegionEllow(0, 255, 255);
double fontSize = (currFrame.cols < 1000) ? 0.4 : 0.6;
cv::Scalar colorRegionEllow(100, 100, 100);
cv::Scalar colorMatchedAboveThreshRed(0, 0, 255);
cv::Scalar colorMatchedGreen(0, 255, 0);
cv::Scalar colorMatchedNearMargenta(255, 0, 255);
Expand Down Expand Up @@ -217,12 +217,7 @@ void CTracker::UpdateTrackingState(const regions_t& regions,
CreateDistaceMatrix(regions, regionEmbeddings, costMatrix, maxPossibleCost, maxCost);
#if DRAW_DBG_ASSIGNMENT
std::cout << "CTracker::UpdateTrackingState: maxPossibleCost = " << maxPossibleCost << ", maxCost = " << maxCost << std::endl;
std::cout << "costMatrix: ";
for (auto costv : costMatrix)
{
std::cout << costv << " ";
}
std::cout << std::endl;
std::cout << "costMatrix: " << cv::Mat_<track_t>(rowsRegions, colsTracks, costMatrix.data()) << std::endl;
#endif

// Solving assignment problem (shortest paths)
Expand Down Expand Up @@ -332,7 +327,9 @@ void CTracker::UpdateTrackingState(const regions_t& regions,
m_tracks[i]->IsStaticTimeout(frameTime, m_settings.m_maxStaticTime - m_settings.m_minStaticTime))
{
m_removedObjects.push_back(m_tracks[i]->GetID());
//std::cout << "Remove: " << m_tracks[i]->GetID().ID2Str() << ": lost = " << m_tracks[i]->GetLostPeriod(frameTime) << ", maximumAllowedLostTime = " << m_settings.m_maximumAllowedLostTime << ", out of frame " << m_tracks[i]->IsOutOfTheFrame() << std::endl;
#if DRAW_DBG_ASSIGNMENT
std::cout << "Remove: " << m_tracks[i]->GetID().ID2Str() << ": lost = " << m_tracks[i]->GetLostPeriod(frameTime) << ", maximumAllowedLostTime = " << m_settings.m_maximumAllowedLostTime << ", out of frame " << m_tracks[i]->IsOutOfTheFrame() << std::endl;
#endif
m_tracks.erase(m_tracks.begin() + i);
assignmentT2R.erase(assignmentT2R.begin() + i);
}
Expand All @@ -349,8 +346,9 @@ void CTracker::UpdateTrackingState(const regions_t& regions,
#endif
for (size_t i = 0; i < regions.size(); ++i)
{
//std::cout << "CTracker::update: regions[" << i << "].m_rrect: " << regions[i].m_rrect.center << ", " << regions[i].m_rrect.angle << ", " << regions[i].m_rrect.size << std::endl;

#if DRAW_DBG_ASSIGNMENT
std::cout << "CTracker::update: regions[" << i << "].m_rrect: " << regions[i].m_rrect.center << ", " << regions[i].m_rrect.angle << ", " << regions[i].m_rrect.size << std::endl;
#endif
if (std::find(assignmentT2R.begin(), assignmentT2R.end(), i) == assignmentT2R.end())
{
if (regionEmbeddings.empty())
Expand Down Expand Up @@ -391,7 +389,9 @@ void CTracker::UpdateTrackingState(const regions_t& regions,
if (assignmentT2R[i] != -1) // If we have assigned detect, then update using its coordinates,
{
m_tracks[i]->ResetLostTime(frameTime);
// std::cout << "Update track " << i << " for " << assignment[i] << " region, regionEmbeddings.size = " << regionEmbeddings.size() << std::endl;
#if DRAW_DBG_ASSIGNMENT
std::cout << "Update track " << i << " for " << assignmentT2R[i] << " region, regionEmbeddings.size = " << regionEmbeddings.size() << std::endl;
#endif
if (regionEmbeddings.empty())
m_tracks[i]->Update(regions[assignmentT2R[i]],
true, m_settings.m_maxTraceLength,
Expand Down
Loading
Loading