Skip to content

Commit

Permalink
Speedup tracking with KCF etc with OpenMP (Smorodov#111)
Browse files Browse the repository at this point in the history
* Added hough3d sources

* Calculate 3D hough trajectory lines

* Added fps

* Some warnings removing

* Fixed warning

* Added small crops in DNN detector for High resolution videos and small objects

* Small refactoring

* Some fix for single tracking

* Added openmp flags to the compiler

* Draw trajectory option

* Update Readme

* Fixed link

* Hough3D disabled now in CMake

* Added Yolo (and Tiny Yolo) detector

* Update Readme

* Remove unused Hybrid face detector

* Extract Capture+Detection into the separate thread

* Fixed potential deadlock

* Points visualization

* Control out the frame moving

* Remove hough3d from master

* Fixed NMS for object with different types

* Fix in Readme and TODO

* OpenCV 4.0 ready

* Added YOLO v3 tiny

* Added compute target for DNN examples (default is OpenCL_FP16)

* Fixed compatible bug with OpenCV version < 4.0

* Fixed project name in CMake

* Simple implementation of the Abandoned detection

* Increased timeout

* Fixed help message

* Added Abandoned to the Readme

* Fixed Readme

* Switch travis to the latest OpenCV 3.4.1 version

* Set timeouts to 60 sec

* Fixed travis script for OpenCV 3.4.1

* Fixed travis for gcc6

* Fixed linker error

* Fixed compiler in travis

* Fixed travis and CMakeLists for C++14 support

* Capture for webcams

* Fix bug with ROI for local tracking

* Automatic inertia correction in linear Kalman filter

* Update TODO

* Yolo eample refactoring

* Refactoring: split project to share library and example

* Added cars counting example

* Fix for OpenCV 4.0

* Single threaded cars counting example

* Added lines class

* Added API for road lines

* Added cars counting code

* Changed road line caption

* Fixed bug with roi rect clamping

* To Linear Kalman filter added speed for rectangle size

* Improved quality of line intersection algorithm

* Fixed bug with Kalman width and height correction

* Return MOSSE tracker

* Temporal correction object size when selected only points filter

* Some small improvements

* Compilation on Windows MSVC 2017 with OpenCV 4.0

* Added new CSRT tracker from opencv_contrib

* Fixed some warnings

* Fixed type conversion warnings

* In CMake added options for enable|disable building cars counting and all other examples

* Speedup tracking with KCF etc with OpenMP

* Added dnnBackend option for the dnn-based detectors

* Fixed Readme
  • Loading branch information
Nuzhny007 authored and Smorodov committed Dec 12, 2018
1 parent 98ba77e commit 1fe4188
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ option(BUILD_CARS_COUNTING "Should compiled Cars counting example?" OFF)
if (BUILD_CARS_COUNTING)
add_subdirectory(cars_counting)
endif(BUILD_CARS_COUNTING)

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Hungarian algorithm + Kalman filter multitarget tracker implementation.
3. Matching: Hungrian algorithm or algorithm based on weighted bipartite graphs
4. Tracking: Linear or Unscented Kalman filter for objects center or for object coordinates and size
5. Use or not local tracker (LK optical flow) for smooth trajectories
6. KCF, MIL, MedianFlow, GOTURN or MOSSE tracking for lost objects and collision resolving
6. KCF, MIL, MedianFlow, GOTURN, MOSSE or CSRT tracking for lost objects and collision resolving
7. Haar face detector from OpenCV
8. HOG and C4 pedestrian detectors
9. SSD detector from OpenCV and models from chuanqi305/MobileNet-SSD
Expand Down
3 changes: 3 additions & 0 deletions example/VideoExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ class SSDMobileNetExample : public VideoExample
config["confidenceThreshold"] = "0.5";
config["maxCropRatio"] = "3.0";
config["dnnTarget"] = "DNN_TARGET_OPENCL_FP16";
config["dnnBackend"] = "DNN_BACKEND_INFERENCE_ENGINE";

m_detector = std::unique_ptr<BaseDetector>(CreateDetector(tracking::Detectors::SSD_MobileNet, config, m_useLocalTracking, frame));
if (!m_detector.get())
{
Expand Down Expand Up @@ -489,6 +491,7 @@ class YoloExample : public VideoExample
config["confidenceThreshold"] = "0.1";
config["maxCropRatio"] = "2.0";
config["dnnTarget"] = "DNN_TARGET_OPENCL";
config["dnnBackend"] = "DNN_BACKEND_INFERENCE_ENGINE";

m_detector = std::unique_ptr<BaseDetector>(CreateDetector(tracking::Detectors::Yolo, config, m_useLocalTracking, frame));
if (!m_detector.get())
Expand Down
18 changes: 18 additions & 0 deletions src/Detector/SSDMobileNetDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,26 @@ bool SSDMobileNetDetector::Init(const config_t& config)
{
m_net.setPreferableTarget(target->second);
}
}

#if (CV_VERSION_MAJOR >= 4)
auto dnnBackend = config.find("dnnBackend");
if (dnnBackend != config.end())
{
std::map<std::string, cv::dnn::Backend> backends;
backends["DNN_BACKEND_DEFAULT"] = cv::dnn::DNN_BACKEND_DEFAULT;
backends["DNN_BACKEND_HALIDE"] = cv::dnn::DNN_BACKEND_HALIDE;
backends["DNN_BACKEND_INFERENCE_ENGINE"] = cv::dnn::DNN_BACKEND_INFERENCE_ENGINE;
backends["DNN_BACKEND_OPENCV"] = cv::dnn::DNN_BACKEND_OPENCV;
backends["DNN_BACKEND_VKCOM"] = cv::dnn::DNN_BACKEND_VKCOM;

auto backend = backends.find(dnnTarget->second);
if (backend != std::end(backends))
{
m_net.setPreferableBackend(backend->second);
}
}
#endif

auto confidenceThreshold = config.find("confidenceThreshold");
if (confidenceThreshold != config.end())
Expand Down
19 changes: 19 additions & 0 deletions src/Detector/YoloDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ bool YoloDetector::Init(const config_t& config)
}
}

#if (CV_VERSION_MAJOR >= 4)
auto dnnBackend = config.find("dnnBackend");
if (dnnBackend != config.end())
{
std::map<std::string, cv::dnn::Backend> backends;
backends["DNN_BACKEND_DEFAULT"] = cv::dnn::DNN_BACKEND_DEFAULT;
backends["DNN_BACKEND_HALIDE"] = cv::dnn::DNN_BACKEND_HALIDE;
backends["DNN_BACKEND_INFERENCE_ENGINE"] = cv::dnn::DNN_BACKEND_INFERENCE_ENGINE;
backends["DNN_BACKEND_OPENCV"] = cv::dnn::DNN_BACKEND_OPENCV;
backends["DNN_BACKEND_VKCOM"] = cv::dnn::DNN_BACKEND_VKCOM;

auto backend = backends.find(dnnTarget->second);
if (backend != std::end(backends))
{
m_net.setPreferableBackend(backend->second);
}
}
#endif

auto classNames = config.find("classNames");
if (classNames != config.end())
{
Expand Down
11 changes: 6 additions & 5 deletions src/Tracker/Ctracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void CTracker::UpdateHungrian(
// -----------------------------------
// Треки уже есть, составим матрицу расстояний
// -----------------------------------
const track_t maxPossibleCost = grayFrame.cols * grayFrame.rows;
const track_t maxPossibleCost = static_cast<track_t>(grayFrame.cols * grayFrame.rows);
track_t maxCost = 0;
switch (m_settings.m_distType)
{
Expand Down Expand Up @@ -149,7 +149,7 @@ void CTracker::UpdateHungrian(

if (currCost < m_settings.m_distThres)
{
int weight = maxCost - currCost + 1;
int weight = static_cast<int>(maxCost - currCost + 1);
G.set_edge_weight(e, weight);
weights[e] = weight;
}
Expand All @@ -170,7 +170,7 @@ void CTracker::UpdateHungrian(
{
node a = it->source();
node b = it->target();
assignment[b.id()] = a.id() - N;
assignment[b.id()] = static_cast<assignments_t::value_type>(a.id() - N);
}
}

Expand Down Expand Up @@ -227,8 +227,9 @@ void CTracker::UpdateHungrian(
}

// Update Kalman Filters state

for (size_t i = 0; i < assignment.size(); i++)
const int stop_i = static_cast<int>(assignment.size());
#pragma omp parallel for
for (int i = 0; i < stop_i; ++i)
{
// If track updated less than one time, than filter state is not correct.

Expand Down

0 comments on commit 1fe4188

Please sign in to comment.