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

add (demo, test) added demo code and the test #67

Merged
merged 3 commits into from
Mar 3, 2021

Conversation

Erol444
Copy link
Member

@Erol444 Erol444 commented Feb 25, 2021

added cpp example and test

Copy link
Collaborator

@themarpe themarpe left a 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);
Copy link
Collaborator

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.;
Copy link
Collaborator

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;
 ....

Copy link
Collaborator

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;
Copy link
Collaborator

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);
Copy link
Collaborator

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];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

Copy link
Collaborator

@themarpe themarpe left a 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])) {
Copy link
Collaborator

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])) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above

@Erol444 Erol444 changed the base branch from gen2_develop to develop March 3, 2021 12:27
@Erol444 Erol444 merged commit 9719f55 into develop Mar 3, 2021
@Erol444 Erol444 deleted the gen2_yolov4_tiny_demo branch March 3, 2021 13:17
@Luxonis-Brandon Luxonis-Brandon added the Gen2 Feature for or issue with Gen2 label Mar 3, 2021
SzabolcsGergely added a commit that referenced this pull request Mar 4, 2021
SzabolcsGergely added a commit that referenced this pull request Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gen2 Feature for or issue with Gen2
Development

Successfully merging this pull request may close these issues.

None yet

4 participants