Get the indexes and IDs of all visible objects in the given frame
| 252 | |
| 253 | // Get the indexes and IDs of all visible objects in the given frame |
| 254 | std::string ObjectDetection::GetVisibleObjects(int64_t frame_number) const{ |
| 255 | |
| 256 | // Initialize the JSON objects |
| 257 | Json::Value root; |
| 258 | root["visible_objects_index"] = Json::Value(Json::arrayValue); |
| 259 | root["visible_objects_id"] = Json::Value(Json::arrayValue); |
| 260 | root["visible_class_names"] = Json::Value(Json::arrayValue); |
| 261 | |
| 262 | // Check if track data exists for the requested frame |
| 263 | if (detectionsData.find(frame_number) == detectionsData.end()){ |
| 264 | return root.toStyledString(); |
| 265 | } |
| 266 | DetectionData detections = detectionsData.at(frame_number); |
| 267 | |
| 268 | // Iterate through the tracked objects |
| 269 | for(int i = 0; i<detections.boxes.size(); i++){ |
| 270 | // Does not show boxes with confidence below the threshold |
| 271 | if(detections.confidences.at(i) < confidence_threshold){ |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Get class name of tracked object |
| 276 | auto className = classNames[detections.classIds.at(i)]; |
| 277 | |
| 278 | // If display_classes is not empty, check if className is in it |
| 279 | if (!display_classes.empty()) { |
| 280 | auto it = std::find(display_classes.begin(), display_classes.end(), className); |
| 281 | if (it == display_classes.end()) { |
| 282 | // If not in display_classes, skip this detection |
| 283 | continue; |
| 284 | } |
| 285 | root["visible_class_names"].append(className); |
| 286 | } else { |
| 287 | // include all class names |
| 288 | root["visible_class_names"].append(className); |
| 289 | } |
| 290 | |
| 291 | int objectId = detections.objectIds.at(i); |
| 292 | // Search for the object in the trackedObjects map |
| 293 | auto trackedObject = trackedObjects.find(objectId); |
| 294 | |
| 295 | // Get the tracked object JSON properties for this frame |
| 296 | Json::Value trackedObjectJSON = trackedObject->second->PropertiesJSON(frame_number); |
| 297 | |
| 298 | if (trackedObjectJSON["visible"]["value"].asBool() && |
| 299 | trackedObject->second->ExactlyContains(frame_number)){ |
| 300 | // Save the object's index and ID if it's visible in this frame |
| 301 | root["visible_objects_index"].append(trackedObject->first); |
| 302 | root["visible_objects_id"].append(trackedObject->second->Id()); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | return root.toStyledString(); |
| 307 | } |
| 308 | |
| 309 | // Generate JSON string of this object |
| 310 | std::string ObjectDetection::Json() const { |
nothing calls this directly
no test coverage detected