You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Added support to attach clip to detected object (ObjectDetection) effect
This feature let's the user attach a clip to an object detected by the Object Detection effect, in the same way it is done with the Tracker Effect.
This commit is contained in:
@@ -101,7 +101,6 @@ void CVObjectDetection::detectObjectsClip(openshot::Clip &video, size_t _start,
|
||||
// Update progress
|
||||
processingController->SetProgress(uint(100*(frame_number-start)/(end-start)));
|
||||
|
||||
// std::cout<<"Frame: "<<frame_number<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +133,7 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector
|
||||
std::vector<int> classIds;
|
||||
std::vector<float> confidences;
|
||||
std::vector<cv::Rect> boxes;
|
||||
std::vector<int> objectIds;
|
||||
|
||||
for (size_t i = 0; i < outs.size(); ++i)
|
||||
{
|
||||
@@ -176,13 +176,14 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector
|
||||
sort.update(sortBoxes, frameId, sqrt(pow(frameDims.width,2) + pow(frameDims.height, 2)), confidences, classIds);
|
||||
|
||||
// Clear data vectors
|
||||
boxes.clear(); confidences.clear(); classIds.clear();
|
||||
boxes.clear(); confidences.clear(); classIds.clear(); objectIds.clear();
|
||||
// Get SORT predicted boxes
|
||||
for(auto TBox : sort.frameTrackingResult){
|
||||
if(TBox.frame == frameId){
|
||||
boxes.push_back(TBox.box);
|
||||
confidences.push_back(TBox.confidence);
|
||||
classIds.push_back(TBox.classId);
|
||||
objectIds.push_back(TBox.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,12 +199,14 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector
|
||||
boxes.erase(boxes.begin() + j);
|
||||
classIds.erase(classIds.begin() + j);
|
||||
confidences.erase(confidences.begin() + j);
|
||||
objectIds.erase(objectIds.begin() + j);
|
||||
break;
|
||||
}
|
||||
else{
|
||||
boxes.erase(boxes.begin() + i);
|
||||
classIds.erase(classIds.begin() + i);
|
||||
confidences.erase(confidences.begin() + i);
|
||||
objectIds.erase(objectIds.begin() + i);
|
||||
i = 0;
|
||||
break;
|
||||
}
|
||||
@@ -222,12 +225,14 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector
|
||||
boxes.erase(boxes.begin() + j);
|
||||
classIds.erase(classIds.begin() + j);
|
||||
confidences.erase(confidences.begin() + j);
|
||||
objectIds.erase(objectIds.begin() + j);
|
||||
break;
|
||||
}
|
||||
else{
|
||||
boxes.erase(boxes.begin() + i);
|
||||
classIds.erase(classIds.begin() + i);
|
||||
confidences.erase(confidences.begin() + i);
|
||||
objectIds.erase(objectIds.begin() + i);
|
||||
i = 0;
|
||||
break;
|
||||
}
|
||||
@@ -247,7 +252,7 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector
|
||||
normalized_boxes.push_back(normalized_box);
|
||||
}
|
||||
|
||||
detectionsData[frameId] = CVDetectionData(classIds, confidences, normalized_boxes, frameId);
|
||||
detectionsData[frameId] = CVDetectionData(classIds, confidences, normalized_boxes, frameId, objectIds);
|
||||
}
|
||||
|
||||
// Compute IOU between 2 boxes
|
||||
@@ -355,6 +360,7 @@ void CVObjectDetection::AddFrameDataToProto(pb_objdetect::Frame* pbFrameData, CV
|
||||
box->set_h(dData.boxes.at(i).height);
|
||||
box->set_classid(dData.classIds.at(i));
|
||||
box->set_confidence(dData.confidences.at(i));
|
||||
box->set_objectid(dData.objectIds.at(i));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -457,7 +463,10 @@ bool CVObjectDetection::_LoadObjDetectdData(){
|
||||
const google::protobuf::RepeatedPtrField<pb_objdetect::Frame_Box > &pBox = pbFrameData.bounding_box();
|
||||
|
||||
// Construct data vectors related to detections in the current frame
|
||||
std::vector<int> classIds; std::vector<float> confidences; std::vector<cv::Rect_<float>> boxes;
|
||||
std::vector<int> classIds;
|
||||
std::vector<float> confidences;
|
||||
std::vector<cv::Rect_<float>> boxes;
|
||||
std::vector<int> objectIds;
|
||||
|
||||
for(int i = 0; i < pbFrameData.bounding_box_size(); i++){
|
||||
// Get bounding box coordinates
|
||||
@@ -468,13 +477,15 @@ bool CVObjectDetection::_LoadObjDetectdData(){
|
||||
|
||||
// Get class Id (which will be assign to a class name) and prediction confidence
|
||||
int classId = pBox.Get(i).classid(); float confidence = pBox.Get(i).confidence();
|
||||
// Get object Id
|
||||
int objectId = pBox.Get(i).objectid();
|
||||
|
||||
// Push back data into vectors
|
||||
boxes.push_back(box); classIds.push_back(classId); confidences.push_back(confidence);
|
||||
}
|
||||
|
||||
// Assign data to object detector map
|
||||
detectionsData[id] = CVDetectionData(classIds, confidences, boxes, id);
|
||||
detectionsData[id] = CVDetectionData(classIds, confidences, boxes, id, objectIds);
|
||||
}
|
||||
|
||||
// Show the time stamp from the last update in object detector data file
|
||||
|
||||
Reference in New Issue
Block a user