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 1 commit
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
13 changes: 11 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,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;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop assumes that width is always above height in the cfg. You can do something like this in case the cfg is written otherwise:

Suggested change
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;
}
}
int flag = 0;
while (std::getline(ifs_cfg, cfg_line)) {
if (flag >= 2) break;
if (cfg_line.find("width") != std::string::npos) {
width = std::stoi(jitsuyo::split_string(cfg_line, "="));
flag++;
} else if (cfg_line.find("height") != std::string::npos) {
height = std::stoi(jitsuyo::split_string(cfg_line, "="));
flag++;
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (height != 0 && width != 0) {
  break;
}

instead of flag, what about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ow yeah, that's better

}

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