diff --git a/src/EffectBase.cpp b/src/EffectBase.cpp index 97e1ef5e..e22283fe 100644 --- a/src/EffectBase.cpp +++ b/src/EffectBase.cpp @@ -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) diff --git a/src/TrackedObjectBBox.cpp b/src/TrackedObjectBBox.cpp index 447efaf2..dbf6efb9 100644 --- a/src/TrackedObjectBBox.cpp +++ b/src/TrackedObjectBBox.cpp @@ -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()); } diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index a85d807a..ae1ab3c3 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -31,7 +31,11 @@ #include "effects/ObjectDetection.h" #include "effects/Tracker.h" #include "Exceptions.h" +#include "Timeline.h" +#include +#include +#include using namespace std; using namespace openshot; @@ -86,6 +90,11 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i return frame; } + // Initialize the Qt rectangle that will hold the positions of the bounding-box + std::vector boxRects; + // Initialize the image of the TrackedObject child clip + std::vector> 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 ObjectDetection::GetFrame(std::shared_ptr 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 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 ObjectDetection::GetFrame(std::shared_ptr 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(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{ diff --git a/src/effects/ObjectDetection.h b/src/effects/ObjectDetection.h index bf778230..3866bd2f 100644 --- a/src/effects/ObjectDetection.h +++ b/src/effects/ObjectDetection.h @@ -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; diff --git a/src/effects/Tracker.cpp b/src/effects/Tracker.cpp index c4373d66..2e72c6d1 100644 --- a/src/effects/Tracker.cpp +++ b/src/effects/Tracker.cpp @@ -144,7 +144,10 @@ std::shared_ptr Tracker::GetFrame(std::shared_ptr 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) ); } } }