This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object
| 60 | // This method is required for all derived classes of EffectBase, and returns a |
| 61 | // modified openshot::Frame object |
| 62 | std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) { |
| 63 | // Get the frame's QImage |
| 64 | std::shared_ptr<QImage> frame_image = frame->GetImage(); |
| 65 | |
| 66 | // Check if frame isn't NULL |
| 67 | if(!frame_image || frame_image->isNull()) { |
| 68 | return frame; |
| 69 | } |
| 70 | |
| 71 | QPainter painter(frame_image.get()); |
| 72 | painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); |
| 73 | |
| 74 | if (detectionsData.find(frame_number) != detectionsData.end()) { |
| 75 | DetectionData detections = detectionsData[frame_number]; |
| 76 | for (int i = 0; i < detections.boxes.size(); i++) { |
| 77 | if (detections.confidences.at(i) < confidence_threshold || |
| 78 | (!display_classes.empty() && |
| 79 | std::find(display_classes.begin(), display_classes.end(), classNames[detections.classIds.at(i)]) == display_classes.end())) { |
| 80 | continue; |
| 81 | } |
| 82 | |
| 83 | int objectId = detections.objectIds.at(i); |
| 84 | auto trackedObject_it = trackedObjects.find(objectId); |
| 85 | |
| 86 | if (trackedObject_it != trackedObjects.end()) { |
| 87 | std::shared_ptr<TrackedObjectBBox> trackedObject = std::static_pointer_cast<TrackedObjectBBox>(trackedObject_it->second); |
| 88 | |
| 89 | Clip* parentClip = (Clip*) trackedObject->ParentClip(); |
| 90 | if (parentClip && trackedObject->Contains(frame_number) && trackedObject->visible.GetValue(frame_number) == 1) { |
| 91 | BBox trackedBox = trackedObject->GetBox(frame_number); |
| 92 | QRectF boxRect((trackedBox.cx - trackedBox.width / 2) * frame_image->width(), |
| 93 | (trackedBox.cy - trackedBox.height / 2) * frame_image->height(), |
| 94 | trackedBox.width * frame_image->width(), |
| 95 | trackedBox.height * frame_image->height()); |
| 96 | |
| 97 | // Get properties of tracked object (i.e. colors, stroke width, etc...) |
| 98 | std::vector<int> stroke_rgba = trackedObject->stroke.GetColorRGBA(frame_number); |
| 99 | std::vector<int> bg_rgba = trackedObject->background.GetColorRGBA(frame_number); |
| 100 | int stroke_width = trackedObject->stroke_width.GetValue(frame_number); |
| 101 | float stroke_alpha = trackedObject->stroke_alpha.GetValue(frame_number); |
| 102 | float bg_alpha = trackedObject->background_alpha.GetValue(frame_number); |
| 103 | float bg_corner = trackedObject->background_corner.GetValue(frame_number); |
| 104 | |
| 105 | // Set the pen for the border |
| 106 | QPen pen(QColor(stroke_rgba[0], stroke_rgba[1], stroke_rgba[2], 255 * stroke_alpha)); |
| 107 | pen.setWidth(stroke_width); |
| 108 | painter.setPen(pen); |
| 109 | |
| 110 | // Set the brush for the background |
| 111 | QBrush brush(QColor(bg_rgba[0], bg_rgba[1], bg_rgba[2], 255 * bg_alpha)); |
| 112 | painter.setBrush(brush); |
| 113 | |
| 114 | if (display_boxes.GetValue(frame_number) == 1 && trackedObject->draw_box.GetValue(frame_number) == 1) { |
| 115 | // Only draw boxes if both properties are set to YES (draw all boxes, and draw box of the selected box) |
| 116 | painter.drawRoundedRect(boxRect, bg_corner, bg_corner); |
| 117 | } |
| 118 | |
| 119 | if(display_box_text.GetValue(frame_number) == 1) { |
nothing calls this directly
no test coverage detected