From d87a1260f39195197a046b0b39b2c1a85016e74c Mon Sep 17 00:00:00 2001 From: Brenno Date: Thu, 23 Jul 2020 20:06:10 -0300 Subject: [PATCH] Added interval to apply OpenCV effects --- include/CVTracker.h | 1 + src/CVTracker.cpp | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/CVTracker.h b/include/CVTracker.h index e88169978..40fdbec66 100644 --- a/include/CVTracker.h +++ b/include/CVTracker.h @@ -64,6 +64,7 @@ class CVTracker { /// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes ProcessingController *processingController; + bool json_interval; size_t start; size_t end; diff --git a/src/CVTracker.cpp b/src/CVTracker.cpp index aabc79b4b..a2a0e5dbf 100644 --- a/src/CVTracker.cpp +++ b/src/CVTracker.cpp @@ -32,7 +32,7 @@ // Constructor CVTracker::CVTracker(std::string processInfoJson, ProcessingController &processingController) -: processingController(&processingController){ +: processingController(&processingController), json_interval(false){ SetJson(processInfoJson); } @@ -63,19 +63,25 @@ cv::Ptr CVTracker::selectTracker(std::string trackerType){ // Track object in the hole clip or in a given interval void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, bool process_interval){ - start = _start; end = _end; - video.Open(); - - bool trackerInit = false; - size_t frame; - if(!process_interval || end == 0 || end-start <= 0){ - // Get total number of frames in video - start = video.Start() * video.Reader()->info.fps.ToInt(); + if(!json_interval){ + start = _start; end = _end; + + if(!process_interval || end <= 0 || end-start <= 0){ + // Get total number of frames in video + start = video.Start() * video.Reader()->info.fps.ToInt(); + end = video.End() * video.Reader()->info.fps.ToInt(); + } + } + else{ + start = start + video.Start() * video.Reader()->info.fps.ToInt(); end = video.End() * video.Reader()->info.fps.ToInt(); } + bool trackerInit = false; + + size_t frame; // Loop through video for (frame = start; frame <= end; frame++) { @@ -291,4 +297,8 @@ void CVTracker::SetJsonValue(const Json::Value root) { cv::Rect2d prev_bbox(x,y,w,h); bbox = prev_bbox; } + if (!root["first_frame"].isNull()){ + start = root["first_frame"].asInt64(); + json_interval = true; + } } \ No newline at end of file