Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Set Blob Size Based On YOLO Config #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions include/ninshiki_cpp/detector/dnn_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class DnnDetector : public Detector
bool myriad;

cv::dnn::Net net;

int width;
int height;
};

} // namespace ninshiki_cpp::detector
Expand Down
15 changes: 13 additions & 2 deletions src/ninshiki_cpp/detector/dnn_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ 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, "="));
}
if (height != 0 && width != 0) {
break;
}
}
}

void DnnDetector::set_computation_method(bool gpu, bool myriad)
Expand Down Expand Up @@ -82,7 +93,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));
Expand Down
Loading