From adaf479bc0d1c2d25ef451ab02e2371bd38b1507 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Thu, 11 Jul 2024 00:41:06 +0700 Subject: [PATCH 1/2] feat: read size from cfg --- include/ninshiki_cpp/detector/dnn_detector.hpp | 3 +++ src/ninshiki_cpp/detector/dnn_detector.cpp | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/ninshiki_cpp/detector/dnn_detector.hpp b/include/ninshiki_cpp/detector/dnn_detector.hpp index 3153a3f..a3d15be 100644 --- a/include/ninshiki_cpp/detector/dnn_detector.hpp +++ b/include/ninshiki_cpp/detector/dnn_detector.hpp @@ -54,6 +54,9 @@ class DnnDetector : public Detector bool myriad; cv::dnn::Net net; + + int width; + int height; }; } // namespace ninshiki_cpp::detector diff --git a/src/ninshiki_cpp/detector/dnn_detector.cpp b/src/ninshiki_cpp/detector/dnn_detector.cpp index 19d0b85..fd7991a 100644 --- a/src/ninshiki_cpp/detector/dnn_detector.cpp +++ b/src/ninshiki_cpp/detector/dnn_detector.cpp @@ -46,7 +46,16 @@ DnnDetector::DnnDetector() classes.push_back(line); } - + std::ifstream ifs_cfg(config.c_str()); + std::string cfg_line; + while (std::getline(ifs_cfg, cfg_line)) { + if (cfg_line.find("width") != std::string::npos) { + width = std::stoi(jitsuyo::split_string(cfg_line, "=")); + } else if (cfg_line.find("height") != std::string::npos) { + height = std::stoi(jitsuyo::split_string(cfg_line, "=")); + break; + } + } } void DnnDetector::set_computation_method(bool gpu, bool myriad) @@ -82,7 +91,7 @@ void DnnDetector::detect_darknet(const cv::Mat & image, float conf_threshold, fl // Create a 4D blob from a frame static cv::Mat blob; - cv::Size input_size = cv::Size(320, 320); + cv::Size input_size = cv::Size(width, height); cv::dnn::blobFromImage(image, blob, 1.0, input_size, cv::Scalar(), false, false, CV_8U); net.setInput(blob, "", 0.00392, cv::Scalar(0, 0, 0, 0)); From 45834c3de84e055008a5e8dca79e6424d12b6a0a Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Sun, 14 Jul 2024 22:17:45 +0700 Subject: [PATCH 2/2] fix: break when height and width filled --- src/ninshiki_cpp/detector/dnn_detector.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ninshiki_cpp/detector/dnn_detector.cpp b/src/ninshiki_cpp/detector/dnn_detector.cpp index fd7991a..5c91564 100644 --- a/src/ninshiki_cpp/detector/dnn_detector.cpp +++ b/src/ninshiki_cpp/detector/dnn_detector.cpp @@ -53,6 +53,8 @@ DnnDetector::DnnDetector() width = std::stoi(jitsuyo::split_string(cfg_line, "=")); } else if (cfg_line.find("height") != std::string::npos) { height = std::stoi(jitsuyo::split_string(cfg_line, "=")); + } + if (height != 0 && width != 0) { break; } }