This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object
| 73 | // This method is required for all derived classes of EffectBase, and returns a |
| 74 | // modified openshot::Frame object |
| 75 | std::shared_ptr<Frame> Tracker::GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) |
| 76 | { |
| 77 | // Sanity‐check |
| 78 | if (!frame) return frame; |
| 79 | auto frame_image = frame->GetImage(); |
| 80 | if (!frame_image || frame_image->isNull()) return frame; |
| 81 | if (!trackedData) return frame; |
| 82 | |
| 83 | // 2) Only proceed if we actually have a box and it's visible |
| 84 | if (!trackedData->Contains(frame_number) || |
| 85 | trackedData->visible.GetValue(frame_number) != 1) |
| 86 | return frame; |
| 87 | |
| 88 | QPainter painter(frame_image.get()); |
| 89 | painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); |
| 90 | |
| 91 | // Draw the box |
| 92 | BBox fd = trackedData->GetBox(frame_number); |
| 93 | QRectF boxRect( |
| 94 | (fd.cx - fd.width/2) * frame_image->width(), |
| 95 | (fd.cy - fd.height/2) * frame_image->height(), |
| 96 | fd.width * frame_image->width(), |
| 97 | fd.height * frame_image->height() |
| 98 | ); |
| 99 | |
| 100 | if (trackedData->draw_box.GetValue(frame_number) == 1) |
| 101 | { |
| 102 | auto stroke_rgba = trackedData->stroke.GetColorRGBA(frame_number); |
| 103 | int stroke_width = trackedData->stroke_width.GetValue(frame_number); |
| 104 | float stroke_alpha = trackedData->stroke_alpha.GetValue(frame_number); |
| 105 | auto bg_rgba = trackedData->background.GetColorRGBA(frame_number); |
| 106 | float bg_alpha = trackedData->background_alpha.GetValue(frame_number); |
| 107 | float bg_corner = trackedData->background_corner.GetValue(frame_number); |
| 108 | |
| 109 | QPen pen(QColor( |
| 110 | stroke_rgba[0], stroke_rgba[1], stroke_rgba[2], |
| 111 | int(255 * stroke_alpha) |
| 112 | )); |
| 113 | pen.setWidth(stroke_width); |
| 114 | painter.setPen(pen); |
| 115 | |
| 116 | QBrush brush(QColor( |
| 117 | bg_rgba[0], bg_rgba[1], bg_rgba[2], |
| 118 | int(255 * bg_alpha) |
| 119 | )); |
| 120 | painter.setBrush(brush); |
| 121 | |
| 122 | painter.drawRoundedRect(boxRect, bg_corner, bg_corner); |
| 123 | } |
| 124 | |
| 125 | painter.end(); |
| 126 | return frame; |
| 127 | } |
| 128 | |
| 129 | // Get the indexes and IDs of all visible objects in the given frame |
| 130 | std::string Tracker::GetVisibleObjects(int64_t frame_number) const |