Skip to content

Commit

Permalink
- Removed possible black background from Tracker and Object Detector …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jonoomph committed Apr 14, 2023
1 parent 38ab27e commit 5fdb3ac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 34 deletions.
17 changes: 4 additions & 13 deletions src/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<openshot::TrackedObjectBase> 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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -1438,17 +1432,14 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> 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<std::string, float> trackedObjectParentClipProperties;
if (parentClipObject) {
parentTrackedObject->GetParentClipProperties(timeline_frame_number);
}
std::map<std::string, float> trackedObjectParentClipProperties =
parentTrackedObject->GetParentClipProperties(timeline_frame_number);

// Get the attached object's parent clip's properties
if (!trackedObjectParentClipProperties.empty())
Expand Down
7 changes: 1 addition & 6 deletions src/TrackedObjectBBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions src/effects/ObjectDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
std::vector<int> 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),
Expand Down Expand Up @@ -160,9 +151,8 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
Clip* childClip = parentTimeline->GetClip(trackedObject->ChildClipId());

if (childClip){
std::shared_ptr<Frame> f(new Frame(1, frame->GetWidth(), frame->GetHeight(), "#00000000"));
// Get the image of the child clip for this frame
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(f, frame_number);
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(frame_number);
childClipImages.push_back(childClipFrame->GetImage());

// Set the Qt rectangle with the bounding-box properties
Expand Down Expand Up @@ -190,7 +180,7 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> 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<QImage>(frameImage));
Expand Down
5 changes: 2 additions & 3 deletions src/effects/Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ std::shared_ptr<Frame> Tracker::GetFrame(std::shared_ptr<Frame> 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<Frame> f(new Frame(1, frame->GetWidth(), frame->GetHeight(), "#00000000"));
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(f, frame_number);
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(frame_number);
childClipImage = childClipFrame->GetImage();

// Set the Qt rectangle with the bounding-box properties
Expand All @@ -160,7 +159,7 @@ std::shared_ptr<Frame> Tracker::GetFrame(std::shared_ptr<Frame> 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<QImage>(frameImage));
Expand Down

0 comments on commit 5fdb3ac

Please sign in to comment.