From 5fdb3acfaf334172dd1df06f5e2b5ca9e68c6d6f Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Fri, 14 Apr 2023 14:32:48 -0500 Subject: [PATCH] - Removed possible black background from Tracker and Object Detector effects when using a child clip - Small refactor to Tracker and Object Detector drawImage code when drawing a Child Clip ID - Some light code clean-up --- src/Clip.cpp | 17 ++++------------- src/TrackedObjectBBox.cpp | 7 +------ src/effects/ObjectDetection.cpp | 14 ++------------ src/effects/Tracker.cpp | 5 ++--- 4 files changed, 9 insertions(+), 34 deletions(-) diff --git a/src/Clip.cpp b/src/Clip.cpp index 8a2a7796..5ba99056 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -253,19 +253,16 @@ void Clip::AttachToObject(std::string object_id) SetAttachedClip(clipObject); } } - return; } // Set the pointer to the trackedObject this clip is attached to void Clip::SetAttachedObject(std::shared_ptr trackedObject){ parentTrackedObject = trackedObject; - return; } // Set the pointer to the clip this clip is attached to void Clip::SetAttachedClip(Clip* clipObject){ parentClipObject = clipObject; - return; } /// Set the current reader @@ -754,11 +751,8 @@ std::string Clip::PropertiesJSON(int64_t requested_frame) const { root["display"] = add_property_json("Frame Number", display, "int", "", NULL, 0, 3, false, requested_frame); root["mixing"] = add_property_json("Volume Mixing", mixing, "int", "", NULL, 0, 2, false, requested_frame); root["waveform"] = add_property_json("Waveform", waveform, "int", "", NULL, 0, 1, false, requested_frame); - if (!parentObjectId.empty()) { - root["parentObjectId"] = add_property_json("Parent", 0.0, "string", parentObjectId, NULL, -1, -1, false, requested_frame); - } else { - root["parentObjectId"] = add_property_json("Parent", 0.0, "string", "", NULL, -1, -1, false, requested_frame); - } + root["parentObjectId"] = add_property_json("Parent", 0.0, "string", parentObjectId, NULL, -1, -1, false, requested_frame); + // Add gravity choices (dropdown style) root["gravity"]["choices"].append(add_property_choice_json("Top Left", GRAVITY_TOP_LEFT, gravity)); root["gravity"]["choices"].append(add_property_choice_json("Top Center", GRAVITY_TOP, gravity)); @@ -1438,17 +1432,14 @@ QTransform Clip::get_transform(std::shared_ptr frame, int width, int heig // Get the parentTrackedObject properties if (parentTrackedObject){ - // Convert Clip's frame position to Timeline's frame position long clip_start_position = round(Position() * info.fps.ToDouble()) + 1; long clip_start_frame = (Start() * info.fps.ToDouble()) + 1; double timeline_frame_number = frame->number + clip_start_position - clip_start_frame; // Get parentTrackedObject's parent clip's properties - std::map trackedObjectParentClipProperties; - if (parentClipObject) { - parentTrackedObject->GetParentClipProperties(timeline_frame_number); - } + std::map trackedObjectParentClipProperties = + parentTrackedObject->GetParentClipProperties(timeline_frame_number); // Get the attached object's parent clip's properties if (!trackedObjectParentClipProperties.empty()) diff --git a/src/TrackedObjectBBox.cpp b/src/TrackedObjectBBox.cpp index 9a3c95a2..cefeba0d 100644 --- a/src/TrackedObjectBBox.cpp +++ b/src/TrackedObjectBBox.cpp @@ -382,12 +382,7 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root) // Set the id of the child clip if (!root["child_clip_id"].isNull() && root["child_clip_id"].asString() != Id()){ - Clip* parentClip = (Clip *) ParentClip(); - if (parentClip && root["child_clip_id"].asString() != parentClip->Id()) { - ChildClipId(root["child_clip_id"].asString()); - } else if (parentClip == NULL) { - ChildClipId(root["child_clip_id"].asString()); - } + ChildClipId(root["child_clip_id"].asString()); } // Set the Keyframes by the given JSON object diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index 5055eb6c..63b0610b 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -122,15 +122,6 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i std::vector bg_rgba = trackedObject->background.GetColorRGBA(frame_number); float bg_alpha = trackedObject->background_alpha.GetValue(frame_number); - // Create a rotated rectangle object that holds the bounding box - // cv::RotatedRect box ( cv::Point2f( (int)(trackedBox.cx*fw), (int)(trackedBox.cy*fh) ), - // cv::Size2f( (int)(trackedBox.width*fw), (int)(trackedBox.height*fh) ), - // (int) (trackedBox.angle) ); - - // DrawRectangleRGBA(cv_image, box, bg_rgba, bg_alpha, 1, true); - // DrawRectangleRGBA(cv_image, box, stroke_rgba, stroke_alpha, stroke_width, false); - - cv::Rect2d box( (int)( (trackedBox.cx-trackedBox.width/2)*fw), (int)( (trackedBox.cy-trackedBox.height/2)*fh), @@ -160,9 +151,8 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i Clip* childClip = parentTimeline->GetClip(trackedObject->ChildClipId()); if (childClip){ - std::shared_ptr f(new Frame(1, frame->GetWidth(), frame->GetHeight(), "#00000000")); // Get the image of the child clip for this frame - std::shared_ptr childClipFrame = childClip->GetFrame(f, frame_number); + std::shared_ptr childClipFrame = childClip->GetFrame(frame_number); childClipImages.push_back(childClipFrame->GetImage()); // Set the Qt rectangle with the bounding-box properties @@ -190,7 +180,7 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i // Set a Qt painter to the frame image QPainter painter(&frameImage); // Draw the child clip image inside the bounding-box - painter.drawImage(boxRects[i], *childClipImages[i], QRectF(0, 0, frameImage.size().width(), frameImage.size().height())); + painter.drawImage(boxRects[i], *childClipImages[i]); } // Set the frame image as the composed image frame->AddImage(std::make_shared(frameImage)); diff --git a/src/effects/Tracker.cpp b/src/effects/Tracker.cpp index 82c504b2..4dc4a95a 100644 --- a/src/effects/Tracker.cpp +++ b/src/effects/Tracker.cpp @@ -132,8 +132,7 @@ std::shared_ptr Tracker::GetFrame(std::shared_ptr frame, int64_t f Clip* childClip = parentTimeline->GetClip(trackedData->ChildClipId()); if (childClip){ // Get the image of the child clip for this frame - std::shared_ptr f(new Frame(1, frame->GetWidth(), frame->GetHeight(), "#00000000")); - std::shared_ptr childClipFrame = childClip->GetFrame(f, frame_number); + std::shared_ptr childClipFrame = childClip->GetFrame(frame_number); childClipImage = childClipFrame->GetImage(); // Set the Qt rectangle with the bounding-box properties @@ -160,7 +159,7 @@ std::shared_ptr Tracker::GetFrame(std::shared_ptr frame, int64_t f QPainter painter(&frameImage); // Draw the child clip image inside the bounding-box - painter.drawImage(boxRect, *childClipImage, QRectF(0, 0, frameImage.size().width(), frameImage.size().height())); + painter.drawImage(boxRect, *childClipImage); // Set the frame image as the composed image frame->AddImage(std::make_shared(frameImage));