Skip to content

Commit

Permalink
Change Object Detector to display the class name: object id, instea…
Browse files Browse the repository at this point in the history
…d of the confidence score. This is way more useful, so you can find the object in the properties menu. Also, output the visible class names as well, so the property editor can display them in a context menu.
  • Loading branch information
jonoomph committed Feb 26, 2024
1 parent 8f3c324 commit f15c91d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/effects/ObjectDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,10 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
if(display_text) {

Check warning on line 132 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L132

Added line #L132 was not covered by tests
// Draw text label above bounding box
// Get the confidence and classId for the current detection
float conf = detections.confidences.at(i);
int classId = detections.classIds.at(i);

Check warning on line 135 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L135

Added line #L135 was not covered by tests

// Get the label for the class name and its confidence
QString label = QString::number(conf, 'f', 2); // Format confidence to two decimal places
QString label = QString::number(objectId);
if (!classNames.empty()) {
label = QString::fromStdString(classNames[classId]) + ":" + label;

Check warning on line 140 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L138-L140

Added lines #L138 - L140 were not covered by tests
}
Expand Down Expand Up @@ -297,6 +296,7 @@ std::string ObjectDetection::GetVisibleObjects(int64_t frame_number) const{
Json::Value root;
root["visible_objects_index"] = Json::Value(Json::arrayValue);
root["visible_objects_id"] = Json::Value(Json::arrayValue);
root["visible_class_names"] = Json::Value(Json::arrayValue);

Check warning on line 299 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L299

Added line #L299 was not covered by tests

// Check if track data exists for the requested frame
if (detectionsData.find(frame_number) == detectionsData.end()){
Expand All @@ -311,11 +311,21 @@ std::string ObjectDetection::GetVisibleObjects(int64_t frame_number) const{
continue;
}

// Just display selected classes
if( display_classes.size() > 0 &&
std::find(display_classes.begin(), display_classes.end(), classNames[detections.classIds.at(i)]) == display_classes.end()){
continue;
}
// Get class name of tracked object
auto className = classNames[detections.classIds.at(i)];

Check warning on line 315 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L315

Added line #L315 was not covered by tests

// If display_classes is not empty, check if className is in it
if (!display_classes.empty()) {
auto it = std::find(display_classes.begin(), display_classes.end(), className);
if (it == display_classes.end()) {

Check warning on line 320 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L318-L320

Added lines #L318 - L320 were not covered by tests
// If not in display_classes, skip this detection
continue;

Check warning on line 322 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L322

Added line #L322 was not covered by tests
}
root["visible_class_names"].append(className);

Check warning on line 324 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L324

Added line #L324 was not covered by tests
} else {
// include all class names
root["visible_class_names"].append(className);

Check warning on line 327 in src/effects/ObjectDetection.cpp

View check run for this annotation

Codecov / codecov/patch

src/effects/ObjectDetection.cpp#L327

Added line #L327 was not covered by tests
}

int objectId = detections.objectIds.at(i);
// Search for the object in the trackedObjects map
Expand Down

0 comments on commit f15c91d

Please sign in to comment.