You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Fixed attaching a clip to Tracker and ObjectDetection
Some problems still persists - Saved projects are not loading properly - There is an aspect ratio issue when attaching an emoji to the ObjectDetection
This commit is contained in:
@@ -135,13 +135,11 @@ void EffectBase::SetJsonValue(Json::Value root) {
|
||||
// TODO: Fix recursive call for Object Detection
|
||||
|
||||
// // Loop through the effects and check if we have a child effect linked to this effect
|
||||
// for (auto const& effect : effects){
|
||||
// // Set the properties of all effects which parentEffect points to this
|
||||
// if ((effect->info.parent_effect_id == this->Id()) && (effect->Id() != this->Id()))
|
||||
// std::cout<<"passou3 \n";
|
||||
|
||||
// effect->SetJsonValue(root);
|
||||
// }
|
||||
for (auto const& effect : effects){
|
||||
// Set the properties of all effects which parentEffect points to this
|
||||
if ((effect->info.parent_effect_id == this->Id()) && (effect->Id() != this->Id()))
|
||||
effect->SetJsonValue(root);
|
||||
}
|
||||
}
|
||||
|
||||
// Set this effect properties with the parent effect properties (except the id and parent_effect_id)
|
||||
|
||||
@@ -394,10 +394,9 @@ void TrackedObjectBBox::SetJsonValue(const Json::Value root)
|
||||
protobufDataPath = root["protobuf_data_path"].asString();
|
||||
|
||||
// Set the id of the child clip
|
||||
// Does not allow to link to the parent clip
|
||||
if (!root["child_clip_id"].isNull() && root["box_id"].asString() != ""){
|
||||
if (!root["child_clip_id"].isNull() && root["child_clip_id"].asString() != ""){
|
||||
Clip* parentClip = (Clip *) ParentClip();
|
||||
|
||||
|
||||
if(parentClip && (root["child_clip_id"].asString() != parentClip->Id())){
|
||||
ChildClipId(root["child_clip_id"].asString());
|
||||
}
|
||||
|
||||
@@ -31,7 +31,11 @@
|
||||
#include "effects/ObjectDetection.h"
|
||||
#include "effects/Tracker.h"
|
||||
#include "Exceptions.h"
|
||||
#include "Timeline.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <QRectF>
|
||||
using namespace std;
|
||||
using namespace openshot;
|
||||
|
||||
@@ -86,6 +90,11 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
|
||||
return frame;
|
||||
}
|
||||
|
||||
// Initialize the Qt rectangle that will hold the positions of the bounding-box
|
||||
std::vector<QRectF> boxRects;
|
||||
// Initialize the image of the TrackedObject child clip
|
||||
std::vector<std::shared_ptr<QImage>> childClipImages;
|
||||
|
||||
// Check if track data exists for the requested frame
|
||||
if (detectionsData.find(frame_number) != detectionsData.end()) {
|
||||
float fw = cv_image.size().width;
|
||||
@@ -144,6 +153,30 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
|
||||
box, cv_image, detections.objectIds.at(i), bg_rgba, bg_alpha, 1, true, draw_text);
|
||||
drawPred(detections.classIds.at(i), detections.confidences.at(i),
|
||||
box, cv_image, detections.objectIds.at(i), stroke_rgba, stroke_alpha, stroke_width, false, draw_text);
|
||||
|
||||
|
||||
// Get the Detected Object's child clip
|
||||
if (trackedObject->ChildClipId() != ""){
|
||||
// Cast the parent timeline of this effect
|
||||
Timeline* parentTimeline = (Timeline *) ParentTimeline();
|
||||
if (parentTimeline){
|
||||
// Get the Tracked Object's child clip
|
||||
Clip* childClip = parentTimeline->GetClip(trackedObject->ChildClipId());
|
||||
if (childClip){
|
||||
// Get the image of the child clip for this frame
|
||||
std::shared_ptr<Frame> childClipFrame = childClip->GetFrame(frame_number);
|
||||
childClipImages.push_back(childClipFrame->GetImage());
|
||||
|
||||
// Set the Qt rectangle with the bounding-box properties
|
||||
QRectF boxRect;
|
||||
boxRect.setRect((int)((trackedBox.cx-trackedBox.width/2)*fw),
|
||||
(int)((trackedBox.cy - trackedBox.height/2)*fh),
|
||||
(int)(trackedBox.width*fw),
|
||||
(int)(trackedBox.height*fh));
|
||||
boxRects.push_back(boxRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,6 +184,20 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
|
||||
// Update Qt image with new Opencv frame
|
||||
frame->SetImageCV(cv_image);
|
||||
|
||||
// Set the bounding-box image with the Tracked Object's child clip image
|
||||
if(boxRects.size() > 0){
|
||||
// Get the frame image
|
||||
QImage frameImage = *(frame->GetImage());
|
||||
for(int i; i < boxRects.size();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()));
|
||||
}
|
||||
// Set the frame image as the composed image
|
||||
frame->AddImage(std::make_shared<QImage>(frameImage));
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
@@ -254,7 +301,6 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Make sure classNames, detectionsData and trackedObjects are empty
|
||||
classNames.clear();
|
||||
detectionsData.clear();
|
||||
@@ -340,18 +386,6 @@ bool ObjectDetection::LoadObjDetectdData(std::string inputFilePath){
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get tracker info for the desired frame
|
||||
DetectionData ObjectDetection::GetTrackedData(size_t frameId){
|
||||
|
||||
// Check if the tracker info for the requested frame exists
|
||||
if ( detectionsData.find(frameId) == detectionsData.end() ) {
|
||||
return DetectionData();
|
||||
} else {
|
||||
return detectionsData[frameId];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Get the indexes and IDs of all visible objects in the given frame
|
||||
std::string ObjectDetection::GetVisibleObjects(int64_t frame_number) const{
|
||||
|
||||
|
||||
@@ -121,9 +121,6 @@ namespace openshot
|
||||
/// Load protobuf data file
|
||||
bool LoadObjDetectdData(std::string inputFilePath);
|
||||
|
||||
/// Get tracker info for the desired frame
|
||||
DetectionData GetTrackedData(size_t frameId);
|
||||
|
||||
/// Get the indexes and IDs of all visible objects in the given frame
|
||||
std::string GetVisibleObjects(int64_t frame_number) const override;
|
||||
|
||||
|
||||
@@ -144,7 +144,10 @@ std::shared_ptr<Frame> Tracker::GetFrame(std::shared_ptr<Frame> frame, int64_t f
|
||||
childClipImage = childClipFrame->GetImage();
|
||||
|
||||
// Set the Qt rectangle with the bounding-box properties
|
||||
boxRect.setRect( (int)((fd.cx-fd.width/2)*fw), (int)((fd.cy - fd.height/2)*fh), (int)(fd.width*fw), (int)(fd.height*fh) );
|
||||
boxRect.setRect((int)((fd.cx-fd.width/2)*fw),
|
||||
(int)((fd.cy - fd.height/2)*fh),
|
||||
(int)(fd.width*fw),
|
||||
(int)(fd.height*fh) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user