Skip to content

Commit 86ed012

Browse files
committed
Added dnnBackend option for the dnn-based detectors
1 parent 512a77b commit 86ed012

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ option(BUILD_CARS_COUNTING "Should compiled Cars counting example?" OFF)
3535
if (BUILD_CARS_COUNTING)
3636
add_subdirectory(cars_counting)
3737
endif(BUILD_CARS_COUNTING)
38-

example/VideoExample.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ class SSDMobileNetExample : public VideoExample
375375
config["confidenceThreshold"] = "0.5";
376376
config["maxCropRatio"] = "3.0";
377377
config["dnnTarget"] = "DNN_TARGET_OPENCL_FP16";
378+
config["dnnBackend"] = "DNN_BACKEND_INFERENCE_ENGINE";
379+
378380
m_detector = std::unique_ptr<BaseDetector>(CreateDetector(tracking::Detectors::SSD_MobileNet, config, m_useLocalTracking, frame));
379381
if (!m_detector.get())
380382
{
@@ -489,6 +491,7 @@ class YoloExample : public VideoExample
489491
config["confidenceThreshold"] = "0.1";
490492
config["maxCropRatio"] = "2.0";
491493
config["dnnTarget"] = "DNN_TARGET_OPENCL";
494+
config["dnnBackend"] = "DNN_BACKEND_INFERENCE_ENGINE";
492495

493496
m_detector = std::unique_ptr<BaseDetector>(CreateDetector(tracking::Detectors::Yolo, config, m_useLocalTracking, frame));
494497
if (!m_detector.get())

src/Detector/SSDMobileNetDetector.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,26 @@ bool SSDMobileNetDetector::Init(const config_t& config)
6161
{
6262
m_net.setPreferableTarget(target->second);
6363
}
64+
}
6465

66+
#if (CV_VERSION_MAJOR >= 4)
67+
auto dnnBackend = config.find("dnnBackend");
68+
if (dnnBackend != config.end())
69+
{
70+
std::map<std::string, cv::dnn::Backend> backends;
71+
backends["DNN_BACKEND_DEFAULT"] = cv::dnn::DNN_BACKEND_DEFAULT;
72+
backends["DNN_BACKEND_HALIDE"] = cv::dnn::DNN_BACKEND_HALIDE;
73+
backends["DNN_BACKEND_INFERENCE_ENGINE"] = cv::dnn::DNN_BACKEND_INFERENCE_ENGINE;
74+
backends["DNN_BACKEND_OPENCV"] = cv::dnn::DNN_BACKEND_OPENCV;
75+
backends["DNN_BACKEND_VKCOM"] = cv::dnn::DNN_BACKEND_VKCOM;
76+
77+
auto backend = backends.find(dnnTarget->second);
78+
if (backend != std::end(backends))
79+
{
80+
m_net.setPreferableBackend(backend->second);
81+
}
6582
}
83+
#endif
6684

6785
auto confidenceThreshold = config.find("confidenceThreshold");
6886
if (confidenceThreshold != config.end())

src/Detector/YoloDetector.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ bool YoloDetector::Init(const config_t& config)
6363
}
6464
}
6565

66+
#if (CV_VERSION_MAJOR >= 4)
67+
auto dnnBackend = config.find("dnnBackend");
68+
if (dnnBackend != config.end())
69+
{
70+
std::map<std::string, cv::dnn::Backend> backends;
71+
backends["DNN_BACKEND_DEFAULT"] = cv::dnn::DNN_BACKEND_DEFAULT;
72+
backends["DNN_BACKEND_HALIDE"] = cv::dnn::DNN_BACKEND_HALIDE;
73+
backends["DNN_BACKEND_INFERENCE_ENGINE"] = cv::dnn::DNN_BACKEND_INFERENCE_ENGINE;
74+
backends["DNN_BACKEND_OPENCV"] = cv::dnn::DNN_BACKEND_OPENCV;
75+
backends["DNN_BACKEND_VKCOM"] = cv::dnn::DNN_BACKEND_VKCOM;
76+
77+
auto backend = backends.find(dnnTarget->second);
78+
if (backend != std::end(backends))
79+
{
80+
m_net.setPreferableBackend(backend->second);
81+
}
82+
}
83+
#endif
84+
6685
auto classNames = config.find("classNames");
6786
if (classNames != config.end())
6887
{

0 commit comments

Comments
 (0)