Skip to content

Commit 5fdb3ac

Browse files
committed
- 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
1 parent 38ab27e commit 5fdb3ac

File tree

4 files changed

+9
-34
lines changed

4 files changed

+9
-34
lines changed

src/Clip.cpp

+4-13
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,16 @@ void Clip::AttachToObject(std::string object_id)
253253
SetAttachedClip(clipObject);
254254
}
255255
}
256-
return;
257256
}
258257

259258
// Set the pointer to the trackedObject this clip is attached to
260259
void Clip::SetAttachedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject){
261260
parentTrackedObject = trackedObject;
262-
return;
263261
}
264262

265263
// Set the pointer to the clip this clip is attached to
266264
void Clip::SetAttachedClip(Clip* clipObject){
267265
parentClipObject = clipObject;
268-
return;
269266
}
270267

271268
/// Set the current reader
@@ -754,11 +751,8 @@ std::string Clip::PropertiesJSON(int64_t requested_frame) const {
754751
root["display"] = add_property_json("Frame Number", display, "int", "", NULL, 0, 3, false, requested_frame);
755752
root["mixing"] = add_property_json("Volume Mixing", mixing, "int", "", NULL, 0, 2, false, requested_frame);
756753
root["waveform"] = add_property_json("Waveform", waveform, "int", "", NULL, 0, 1, false, requested_frame);
757-
if (!parentObjectId.empty()) {
758-
root["parentObjectId"] = add_property_json("Parent", 0.0, "string", parentObjectId, NULL, -1, -1, false, requested_frame);
759-
} else {
760-
root["parentObjectId"] = add_property_json("Parent", 0.0, "string", "", NULL, -1, -1, false, requested_frame);
761-
}
754+
root["parentObjectId"] = add_property_json("Parent", 0.0, "string", parentObjectId, NULL, -1, -1, false, requested_frame);
755+
762756
// Add gravity choices (dropdown style)
763757
root["gravity"]["choices"].append(add_property_choice_json("Top Left", GRAVITY_TOP_LEFT, gravity));
764758
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> frame, int width, int heig
14381432

14391433
// Get the parentTrackedObject properties
14401434
if (parentTrackedObject){
1441-
14421435
// Convert Clip's frame position to Timeline's frame position
14431436
long clip_start_position = round(Position() * info.fps.ToDouble()) + 1;
14441437
long clip_start_frame = (Start() * info.fps.ToDouble()) + 1;
14451438
double timeline_frame_number = frame->number + clip_start_position - clip_start_frame;
14461439

14471440
// Get parentTrackedObject's parent clip's properties
1448-
std::map<std::string, float> trackedObjectParentClipProperties;
1449-
if (parentClipObject) {
1450-
parentTrackedObject->GetParentClipProperties(timeline_frame_number);
1451-
}
1441+
std::map<std::string, float> trackedObjectParentClipProperties =
1442+
parentTrackedObject->GetParentClipProperties(timeline_frame_number);
14521443

14531444
// Get the attached object's parent clip's properties
14541445
if (!trackedObjectParentClipProperties.empty())

src/TrackedObjectBBox.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,7 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root)
382382

383383
// Set the id of the child clip
384384
if (!root["child_clip_id"].isNull() && root["child_clip_id"].asString() != Id()){
385-
Clip* parentClip = (Clip *) ParentClip();
386-
if (parentClip && root["child_clip_id"].asString() != parentClip->Id()) {
387-
ChildClipId(root["child_clip_id"].asString());
388-
} else if (parentClip == NULL) {
389-
ChildClipId(root["child_clip_id"].asString());
390-
}
385+
ChildClipId(root["child_clip_id"].asString());
391386
}
392387

393388
// Set the Keyframes by the given JSON object

src/effects/ObjectDetection.cpp

+2-12
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
122122
std::vector<int> bg_rgba = trackedObject->background.GetColorRGBA(frame_number);
123123
float bg_alpha = trackedObject->background_alpha.GetValue(frame_number);
124124

125-
// Create a rotated rectangle object that holds the bounding box
126-
// cv::RotatedRect box ( cv::Point2f( (int)(trackedBox.cx*fw), (int)(trackedBox.cy*fh) ),
127-
// cv::Size2f( (int)(trackedBox.width*fw), (int)(trackedBox.height*fh) ),
128-
// (int) (trackedBox.angle) );
129-
130-
// DrawRectangleRGBA(cv_image, box, bg_rgba, bg_alpha, 1, true);
131-
// DrawRectangleRGBA(cv_image, box, stroke_rgba, stroke_alpha, stroke_width, false);
132-
133-
134125
cv::Rect2d box(
135126
(int)( (trackedBox.cx-trackedBox.width/2)*fw),
136127
(int)( (trackedBox.cy-trackedBox.height/2)*fh),
@@ -160,9 +151,8 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
160151
Clip* childClip = parentTimeline->GetClip(trackedObject->ChildClipId());
161152

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

168158
// Set the Qt rectangle with the bounding-box properties
@@ -190,7 +180,7 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
190180
// Set a Qt painter to the frame image
191181
QPainter painter(&frameImage);
192182
// Draw the child clip image inside the bounding-box
193-
painter.drawImage(boxRects[i], *childClipImages[i], QRectF(0, 0, frameImage.size().width(), frameImage.size().height()));
183+
painter.drawImage(boxRects[i], *childClipImages[i]);
194184
}
195185
// Set the frame image as the composed image
196186
frame->AddImage(std::make_shared<QImage>(frameImage));

src/effects/Tracker.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ std::shared_ptr<Frame> Tracker::GetFrame(std::shared_ptr<Frame> frame, int64_t f
132132
Clip* childClip = parentTimeline->GetClip(trackedData->ChildClipId());
133133
if (childClip){
134134
// Get the image of the child clip for this frame
135-
std::shared_ptr<Frame> f(new Frame(1, frame->GetWidth(), frame->GetHeight(), "#00000000"));
136-
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(f, frame_number);
135+
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(frame_number);
137136
childClipImage = childClipFrame->GetImage();
138137

139138
// Set the Qt rectangle with the bounding-box properties
@@ -160,7 +159,7 @@ std::shared_ptr<Frame> Tracker::GetFrame(std::shared_ptr<Frame> frame, int64_t f
160159
QPainter painter(&frameImage);
161160

162161
// Draw the child clip image inside the bounding-box
163-
painter.drawImage(boxRect, *childClipImage, QRectF(0, 0, frameImage.size().width(), frameImage.size().height()));
162+
painter.drawImage(boxRect, *childClipImage);
164163

165164
// Set the frame image as the composed image
166165
frame->AddImage(std::make_shared<QImage>(frameImage));

0 commit comments

Comments
 (0)