-
Notifications
You must be signed in to change notification settings - Fork 126
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
add (demo, test) added demo code and the test #67
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also try to stick to either snake_case
or camelCase
for variable names consistently through the example
detectionNetwork->setNumClasses(80); | ||
detectionNetwork->setCoordinateSize(4); | ||
std::vector<float> anchors{10, 14, 23, 27, 37, 58, 81, 82, 135, 169, 344, 319}; | ||
detectionNetwork->setAnchors(anchors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use initializer lists for clearer usage
// network specific!!
detectionNetwork->setConfidenceThreshold(0.5f);
detectionNetwork->setNumClasses(80);
detectionNetwork->setCoordinateSize(4);
detectionNetwork->setAnchors({10, 14, 23, 27, 37, 58, 81, 82, 135, 169, 344, 319});
detectionNetwork->setAnchorMasks({{"side13", {1,2,3}}, {"side26", {3,4,5}}});
detectionNetwork->setIouThreshold(0.5f);
|
||
counter++; | ||
auto current_time = std::chrono::steady_clock::now(); | ||
float elapsed_s = std::chrono::duration_cast<std::chrono::milliseconds>(current_time-start_time).count() / 1000.; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with:
auto elapsed = duration_cast<duration<float>>(current_time - start_time);
if (elapsed > seconds(1)){
fps = counter / elapsed;
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above creates a representation of seconds in float format. So below division will work as expected.
Otherwise, counter could be float and then no duration cast would be needed
} | ||
|
||
int main(int argc, char** argv) { | ||
using namespace std; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add:
using namespace std::chrono;
} | ||
cv::putText(frame, label_str, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color); | ||
char conf_str[10]; | ||
snprintf(conf_str, sizeof conf_str, "%.2f", d.confidence*100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preferably C++ish
std::stringstream s;
s << std::fixed << std::setprecision(2) << d.confidence*100;
// s.str();
cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX); | ||
} | ||
|
||
char fps_str[15]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to merge after the extra change.
Thanks for the PR:)
label_str = label_map[label_index]; | ||
int labelIndex = d.label; | ||
std::string labelStr = to_string(labelIndex); | ||
if(labelIndex < sizeof(label_map) / sizeof(label_map[0])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather do:
static const auto labelMap = { ... } // or static const std::vector<std::string> = { ... }
...
if(labelIndex < labelMap.size()) {
...
}
label_str = label_map[label_index]; | ||
int labelIndex = d.label; | ||
std::string labelStr = to_string(labelIndex); | ||
if(labelIndex < sizeof(label_map) / sizeof(label_map[0])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
8b6ea69
to
6988743
Compare
added cpp example and test