diff --git a/include/CVTracker.h b/include/CVTracker.h index d971c2a97..0acc1cf6d 100644 --- a/include/CVTracker.h +++ b/include/CVTracker.h @@ -1,3 +1,6 @@ +#ifndef OPENSHOT_CVTRACKER_H +#define OPENSHOT_CVTRACKER_H + #include #define int64 opencv_broken_int @@ -9,13 +12,19 @@ #undef int64 #include - +#include "Clip.h" +#include "KeyFrame.h" +#include "Frame.h" #include "trackerdata.pb.h" // using namespace cv; using namespace std; using google::protobuf::util::TimeUtil; +// namespace openshot{ +// class Clip; +// } + struct FrameData{ int frame_id = -1; float rotation = 0; @@ -24,6 +33,11 @@ struct FrameData{ int x2 = -1; int y2 = -1; + // Keyframe kf_x1; + // Keyframe kf_y1; + // Keyframe kf_x2; + // Keyframe kf_y2; + // constructor FrameData() {} @@ -38,6 +52,11 @@ struct FrameData{ y1 = _y1; x2 = _x2; y2 = _y2; + + // kf_x1.AddPoint(_frame_id, _x1); + // kf_y1.AddPoint(_frame_id, _y1); + // kf_x2.AddPoint(_frame_id, _x2); + // kf_y2.AddPoint(_frame_id, _y2); } }; @@ -53,6 +72,8 @@ class CVTracker { CVTracker(); cv::Ptr select_tracker(std::string trackerType); + + void trackClip(openshot::Clip& video); bool initTracker(cv::Rect2d bbox, cv::Mat &frame, int frameId); bool trackFrame(cv::Mat &frame, int frameId); @@ -66,3 +87,7 @@ class CVTracker { // Get tracked data for a given frame FrameData GetTrackedData(int frameId); }; + + + +#endif \ No newline at end of file diff --git a/include/Clip.h b/include/Clip.h index 35ead2d1c..a698c5496 100644 --- a/include/Clip.h +++ b/include/Clip.h @@ -59,7 +59,7 @@ namespace openshot { - + class EffectInfo; /// Comparison method for sorting effect pointers (by Position, Layer, and Order). Effects are sorted /// from lowest layer to top layer (since that is sequence clips are combined), and then by @@ -125,14 +125,6 @@ namespace openshot { /// (reader member variable itself may have been replaced) openshot::ReaderBase* allocated_reader; - #ifdef USE_OPENCV - /// Smoothed transformation for all the clip frames - std::vector new_prev_to_cur_transform; - /// apply the smoothed transformation warp when retrieving a frame - bool hasStabilization = false; - void apply_stabilization(std::shared_ptr f, int64_t frame_number); - #endif - /// Adjust frame number minimum value int64_t adjust_frame_number_minimum(int64_t frame_number); @@ -169,6 +161,14 @@ namespace openshot { openshot::FrameDisplayType display; ///< The format to display the frame number (if any) openshot::VolumeMixType mixing; ///< What strategy should be followed when mixing audio with other clips + #ifdef USE_OPENCV + /// Smoothed transformation for all the clip frames + std::vector new_prev_to_cur_transform; + /// apply the smoothed transformation warp when retrieving a frame + bool hasStabilization = false; + void apply_stabilization(std::shared_ptr f, int64_t frame_number); + #endif + /// Default Constructor Clip(); diff --git a/include/ClipProcessingJobs.h b/include/ClipProcessingJobs.h new file mode 100644 index 000000000..a0b323f26 --- /dev/null +++ b/include/ClipProcessingJobs.h @@ -0,0 +1,64 @@ +/** + * @file + * @brief Header for the ClipProcessingJobs class + * @author Jonathan Thomas + * + * @ref License + */ + +/* LICENSE + * + * Copyright (c) 2008-2019 OpenShot Studios, LLC + * . This file is part of + * OpenShot Library (libopenshot), an open-source project dedicated to + * delivering high quality video editing and animation solutions to the + * world. For more information visit . + * + * OpenShot Library (libopenshot) is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * OpenShot Library (libopenshot) is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenShot Library. If not, see . + */ + + +#ifdef USE_OPENCV + #define int64 opencv_broken_int + #define uint64 opencv_broken_uint + #include + #include + #undef uint64 + #undef int64 + + #include "CVStabilization.h" + #include "CVTracker.h" +#endif + +#include "Clip.h" +#include "effects/Tracker.h" + +using namespace openshot; + +class ClipProcessingJobs{ + + private: + + void trackVideo(Clip& videoClip); + void stabilizeVideo(Clip& video); + + + + public: + ClipProcessingJobs(std::string processingType, Clip& videoClip); + + + + +}; \ No newline at end of file diff --git a/include/EffectInfo.h b/include/EffectInfo.h index 0e64327bb..529063899 100644 --- a/include/EffectInfo.h +++ b/include/EffectInfo.h @@ -34,9 +34,10 @@ #include "Effects.h" + namespace openshot { - + class Clip; /** * @brief This class returns a listing of all effects supported by libopenshot * @@ -48,6 +49,10 @@ namespace openshot public: // Create an instance of an effect (factory style) EffectBase* CreateEffect(std::string effect_type); + + // Create an instance of an video effect (require processing the whole clip) + EffectBase* CreateEffect(std::string effect_type, Clip* video_clip); + /// JSON methods static std::string Json(); ///< Generate JSON string of this object diff --git a/include/Timeline.h b/include/Timeline.h index 932b04acf..03c089abf 100644 --- a/include/Timeline.h +++ b/include/Timeline.h @@ -54,6 +54,7 @@ #include "OpenMPUtilities.h" #include "ReaderBase.h" #include "Settings.h" +#include "ClipProcessingJobs.h" namespace openshot { diff --git a/include/effects/Tracker.h b/include/effects/Tracker.h new file mode 100644 index 000000000..c5f39daf9 --- /dev/null +++ b/include/effects/Tracker.h @@ -0,0 +1,150 @@ +/** + * @file + * @brief Header file for Tracker effect class + * @author Jonathan Thomas + * + * @ref License + */ + +/* LICENSE + * + * Copyright (c) 2008-2019 OpenShot Studios, LLC + * . This file is part of + * OpenShot Library (libopenshot), an open-source project dedicated to + * delivering high quality video editing and animation solutions to the + * world. For more information visit . + * + * OpenShot Library (libopenshot) is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * OpenShot Library (libopenshot) is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenShot Library. If not, see . + */ + +#ifndef OPENSHOT_TRACKER_EFFECT_H +#define OPENSHOT_TRACKER_EFFECT_H + +#include "../EffectBase.h" + +#include +#include +#include +#include "../Color.h" +#include "../Json.h" +#include "../KeyFrame.h" +#include "../CVTracker.h" +#include "../Clip.h" +#include "../trackerdata.pb.h" + + +namespace openshot +{ + +// struct FrameData{ +// int frame_id = -1; +// float rotation = 0; +// int x1 = -1; +// int y1 = -1; +// int x2 = -1; +// int y2 = -1; + +// // Keyframe kf_x1; +// // Keyframe kf_y1; +// // Keyframe kf_x2; +// // Keyframe kf_y2; + +// // constructor +// FrameData() +// {} +// FrameData( int _frame_id) +// {frame_id = _frame_id;} + +// FrameData( int _frame_id , float _rotation, int _x1, int _y1, int _x2, int _y2) +// { +// frame_id = _frame_id; +// rotation = _rotation; +// x1 = _x1; +// y1 = _y1; +// x2 = _x2; +// y2 = _y2; + +// // kf_x1.AddPoint(_frame_id, _x1); +// // kf_y1.AddPoint(_frame_id, _y1); +// // kf_x2.AddPoint(_frame_id, _x2); +// // kf_y2.AddPoint(_frame_id, _y2); +// } +// }; + + + //TODO: fix this + /** + * @brief This class draws black bars around your video (from any side), and can be animated with + * openshot::Keyframe curves over time. + * + * Adding bars around your video can be done for cinematic reasons, and creates a fun way to frame + * in the focal point of a scene. The bars can be any color, and each side can be animated independently. + */ + class Tracker : public EffectBase + { + private: + /// Init effect settings + void init_effect_details(); + + + public: + Color color; ///< Color of bars + Keyframe left; ///< Size of left bar + Keyframe top; ///< Size of top bar + Keyframe right; ///< Size of right bar + Keyframe bottom; ///< Size of bottom bar + + std::map trackedDataById; + + /// Blank constructor, useful when using Json to load the effect properties + Tracker(std::string clipTrackerDataPath); + + /// Default constructor, which takes 4 curves and a color. These curves animated the bars over time. + /// + /// @param color The curve to adjust the color of bars + /// @param left The curve to adjust the left bar size (between 0 and 1) + /// @param top The curve to adjust the top bar size (between 0 and 1) + /// @param right The curve to adjust the right bar size (between 0 and 1) + /// @param bottom The curve to adjust the bottom bar size (between 0 and 1) + Tracker(Color color, Keyframe left, Keyframe top, Keyframe right, Keyframe bottom); + + /// @brief This method is required for all derived classes of EffectBase, and returns a + /// modified openshot::Frame object + /// + /// The frame object is passed into this method, and a frame_number is passed in which + /// tells the effect which settings to use from its keyframes (starting at 1). + /// + /// @returns The modified openshot::Frame object + /// @param frame The frame object that needs the effect applied to it + /// @param frame_number The frame number (starting at 1) of the effect on the timeline. + std::shared_ptr GetFrame(std::shared_ptr frame, int64_t frame_number) override; + + bool LoadTrackedData(std::string inputFilePath); + + FrameData GetTrackedData(int frameId); + + /// Get and Set JSON methods + std::string Json() const override; ///< Generate JSON string of this object + void SetJson(const std::string value) override; ///< Load JSON string into this object + Json::Value JsonValue() const override; ///< Generate Json::Value for this object + void SetJsonValue(const Json::Value root) override; ///< Load Json::Value into this object + + /// Get all properties for a specific frame (perfect for a UI to display the current state + /// of all properties at any time) + std::string PropertiesJSON(int64_t requested_frame) const override; + }; + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2df71dad3..6f87d0581 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -190,7 +190,8 @@ set(OPENSHOT_SOURCES # OpenCV related classes set(OPENSHOT_CV_SOURCES CVTracker.cpp - CVStabilization.cpp) + CVStabilization.cpp + ClipProcessingJobs.cpp) # Compiled Protobuf messages set(PROTOBUF_MESSAGES @@ -211,7 +212,8 @@ set(EFFECTS_SOURCES effects/Pixelate.cpp effects/Saturation.cpp effects/Shift.cpp - effects/Wave.cpp) + effects/Wave.cpp + effects/Tracker.cpp) # Qt video player components set(QT_PLAYER_SOURCES diff --git a/src/CVTracker.cpp b/src/CVTracker.cpp index 1a84edc20..42f3bd7ed 100644 --- a/src/CVTracker.cpp +++ b/src/CVTracker.cpp @@ -37,6 +37,52 @@ cv::Ptr CVTracker::select_tracker(std::string trackerType){ return t; } +void CVTracker::trackClip(openshot::Clip& video){ + // Opencv display window + cv::namedWindow("Display Image", cv::WINDOW_NORMAL ); + // Create Tracker + + bool trackerInit = false; + int videoLenght = video.Reader()->info.video_length; + for (long int frame = 0; frame < videoLenght; frame++) + { + std::cout<<"frame: "< f = video.GetFrame(frame_number); + + // Grab Mat image + cv::Mat cvimage = f->GetImageCV(); + + if(!trackerInit){ + cv::Rect2d bbox = cv::selectROI("Display Image", cvimage); + + initTracker(bbox, cvimage, frame_number); + cv::rectangle(cvimage, bbox, cv::Scalar( 255, 0, 0 ), 2, 1 ); + + trackerInit = true; + } + else{ + trackerInit = trackFrame(cvimage, frame_number); + + // Draw box on image + FrameData fd = GetTrackedData(frame_number); + + cv::Rect2d box(fd.x1, fd.y1, fd.x2-fd.x1, fd.y2-fd.y1); + cv::rectangle(cvimage, box, cv::Scalar( 255, 0, 0 ), 2, 1 ); + } + + cv::imshow("Display Image", cvimage); + // Press ESC on keyboard to exit + char c=(char)cv::waitKey(1); + if(c==27) + break; + + } + + +} + + bool CVTracker::initTracker(cv::Rect2d initial_bbox, cv::Mat &frame, int frameId){ bbox = initial_bbox; diff --git a/src/ClipProcessingJobs.cpp b/src/ClipProcessingJobs.cpp new file mode 100644 index 000000000..d21446487 --- /dev/null +++ b/src/ClipProcessingJobs.cpp @@ -0,0 +1,73 @@ +#include "../include/ClipProcessingJobs.h" + + +// get the clip to add a preprocessing job + +// run the preprocessing job on the clip + +// create a new effect with the processed result + +// modify the clip to include the correspondent processed effect + + +ClipProcessingJobs::ClipProcessingJobs(std::string processingType, Clip& videoClip){ + + if(processingType == "Stabilize"){ + stabilizeVideo(videoClip); + } + if(processingType == "Track") + trackVideo(videoClip); + +} + + +void ClipProcessingJobs::trackVideo(Clip& videoClip){ + + // Opencv display window + cv::namedWindow("Display Image", cv::WINDOW_NORMAL ); + // Create Tracker + CVTracker tracker; + tracker.trackClip(videoClip); + + tracker.SaveTrackedData("kcf_tracker.data"); + + // Create new Tracker Effect + EffectBase* trackerEffect = new Tracker("kcf_tracker.data"); + videoClip.AddEffect(trackerEffect); + + + // + +} + + +void ClipProcessingJobs::stabilizeVideo(Clip& video){ + // create CVStabilization object + CVStabilization stabilizer; + + // Get total number of frames + int videoLenght = video.Reader()->info.video_length; + + // Extract and track opticalflow features for each frame + for (long int frame_number = 0; frame_number <= videoLenght; frame_number++) + { + std::shared_ptr f = video.GetFrame(frame_number); + + // Grab Mat image + cv::Mat cvimage = f->GetImageCV(); + cv::cvtColor(cvimage, cvimage, cv::COLOR_RGB2GRAY); + stabilizer.TrackFrameFeatures(cvimage, frame_number); + } + + vector trajectory = stabilizer.ComputeFramesTrajectory(); + + vector smoothed_trajectory = stabilizer.SmoothTrajectory(trajectory); + + // Get the smoothed trajectory + std::vector new_prev_to_cur_transform = stabilizer.GenNewCamPosition(smoothed_trajectory); + + // Will apply the smoothed transformation warp when retrieving a frame + video.hasStabilization = true; + video.new_prev_to_cur_transform = new_prev_to_cur_transform; + +} \ No newline at end of file diff --git a/src/EffectInfo.cpp b/src/EffectInfo.cpp index 6829f4eb5..d2c0b30c8 100644 --- a/src/EffectInfo.cpp +++ b/src/EffectInfo.cpp @@ -29,6 +29,7 @@ */ #include "../include/EffectInfo.h" +// #include "../include/Clip.h" using namespace openshot; diff --git a/src/effects/Tracker.cpp b/src/effects/Tracker.cpp new file mode 100644 index 000000000..d38c71db2 --- /dev/null +++ b/src/effects/Tracker.cpp @@ -0,0 +1,232 @@ +/** + * @file + * @brief Source file for Tracker effect class + * @author Jonathan Thomas + * + * @ref License + */ + +/* LICENSE + * + * Copyright (c) 2008-2019 OpenShot Studios, LLC + * . This file is part of + * OpenShot Library (libopenshot), an open-source project dedicated to + * delivering high quality video editing and animation solutions to the + * world. For more information visit . + * + * OpenShot Library (libopenshot) is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * OpenShot Library (libopenshot) is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenShot Library. If not, see . + */ + +#include "../../include/effects/Tracker.h" + +using namespace openshot; + +/// Blank constructor, useful when using Json to load the effect properties +Tracker::Tracker(std::string clipTrackerDataPath) +{ + // Init effect properties + init_effect_details(); + + // Tries to load the tracker data from protobuf + LoadTrackedData(clipTrackerDataPath); + std::cout<<"passou0\n"; + +} + +// Default constructor +Tracker::Tracker(Color color, Keyframe left, Keyframe top, Keyframe right, Keyframe bottom) : + color(color), left(left), top(top), right(right), bottom(bottom) +{ + // Init effect properties + init_effect_details(); + +} + +// Init effect settings +void Tracker::init_effect_details() +{ + /// Initialize the values of the EffectInfo struct. + InitEffectInfo(); + + /// Set the effect info + info.class_name = "Tracker"; + info.name = "Tracker"; + info.description = "Track the selected bounding box through the video."; + info.has_audio = false; + info.has_video = true; +} + +// This method is required for all derived classes of EffectBase, and returns a +// modified openshot::Frame object +std::shared_ptr Tracker::GetFrame(std::shared_ptr frame, int64_t frame_number) +{ + std::cout<<"passou1\n"; + // Get the frame's image + cv::Mat frame_image = frame->GetImageCV(); + std::cout<<"passou2\n"; + // Draw box on image + FrameData fd = trackedDataById[frame_number]; + std::cout<<"passou3\n"; + cv::Rect2d box(fd.x1, fd.y1, fd.x2-fd.x1, fd.y2-fd.y1); + std::cout<<"passou4\n"; + cv::rectangle(frame_image, box, cv::Scalar( 255, 0, 0 ), 2, 1 ); + std::cout<<"passou5\n"; + frame->SetImageCV(frame_image); + std::cout<<"passou6\n"; + + return frame; +} + +bool Tracker::LoadTrackedData(std::string inputFilePath){ + + libopenshottracker::Tracker trackerMessage; + + { + // Read the existing tracker message. + fstream input(inputFilePath, ios::in | ios::binary); + if (!trackerMessage.ParseFromIstream(&input)) { + cerr << "Failed to parse protobuf message." << endl; + return false; + } + } + + // Make sure the trackedData is empty + trackedDataById.clear(); + + // Iterate over all frames of the saved message + for (int i = 0; i < trackerMessage.frame_size(); i++) { + const libopenshottracker::Frame& pbFrameData = trackerMessage.frame(i); + + int id = pbFrameData.id(); + float rotation = pbFrameData.rotation(); + + const libopenshottracker::Frame::Box& box = pbFrameData.bounding_box(); + int x1 = box.x1(); + int y1 = box.y1(); + int x2 = box.x2(); + int y2 = box.y2(); + + trackedDataById[id] = FrameData(id, rotation, x1, y1, x2, y2); + } + + if (trackerMessage.has_last_updated()) { + cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString(trackerMessage.last_updated()) << endl; + } + + // Delete all global objects allocated by libprotobuf. + google::protobuf::ShutdownProtobufLibrary(); + + return true; +} + +FrameData Tracker::GetTrackedData(int frameId){ + + if ( trackedDataById.find(frameId) == trackedDataById.end() ) { + + return FrameData(); + } else { + + return trackedDataById[frameId]; + } + +} + + + + + +// Generate JSON string of this object +std::string Tracker::Json() const { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::Value for this object +Json::Value Tracker::JsonValue() const { + + // Create root json object + Json::Value root = EffectBase::JsonValue(); // get parent properties + root["type"] = info.class_name; + root["color"] = color.JsonValue(); + root["left"] = left.JsonValue(); + root["top"] = top.JsonValue(); + root["right"] = right.JsonValue(); + root["bottom"] = bottom.JsonValue(); + + // return JsonValue + return root; +} + +// Load JSON string into this object +void Tracker::SetJson(const std::string value) { + + // Parse JSON string into JSON objects + try + { + const Json::Value root = openshot::stringToJson(value); + // Set all values that match + SetJsonValue(root); + } + catch (const std::exception& e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)"); + } +} + +// Load Json::Value into this object +void Tracker::SetJsonValue(const Json::Value root) { + + // Set parent data + EffectBase::SetJsonValue(root); + + // Set data from Json (if key is found) + if (!root["color"].isNull()) + color.SetJsonValue(root["color"]); + if (!root["left"].isNull()) + left.SetJsonValue(root["left"]); + if (!root["top"].isNull()) + top.SetJsonValue(root["top"]); + if (!root["right"].isNull()) + right.SetJsonValue(root["right"]); + if (!root["bottom"].isNull()) + bottom.SetJsonValue(root["bottom"]); +} + +// Get all properties for a specific frame +std::string Tracker::PropertiesJSON(int64_t requested_frame) const { + + // Generate JSON properties list + Json::Value root; + root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame); + root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame); + root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame); + root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame); + root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame); + root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame); + + // Keyframes + root["color"] = add_property_json("Bar Color", 0.0, "color", "", NULL, 0, 255, false, requested_frame); + root["color"]["red"] = add_property_json("Red", color.red.GetValue(requested_frame), "float", "", &color.red, 0, 255, false, requested_frame); + root["color"]["blue"] = add_property_json("Blue", color.blue.GetValue(requested_frame), "float", "", &color.blue, 0, 255, false, requested_frame); + root["color"]["green"] = add_property_json("Green", color.green.GetValue(requested_frame), "float", "", &color.green, 0, 255, false, requested_frame); + root["left"] = add_property_json("Left Size", left.GetValue(requested_frame), "float", "", &left, 0.0, 0.5, false, requested_frame); + root["top"] = add_property_json("Top Size", top.GetValue(requested_frame), "float", "", &top, 0.0, 0.5, false, requested_frame); + root["right"] = add_property_json("Right Size", right.GetValue(requested_frame), "float", "", &right, 0.0, 0.5, false, requested_frame); + root["bottom"] = add_property_json("Bottom Size", bottom.GetValue(requested_frame), "float", "", &bottom, 0.0, 0.5, false, requested_frame); + + // Return formatted string + return root.toStyledString(); +} diff --git a/src/examples/Example_opencv.cpp b/src/examples/Example_opencv.cpp index c808ef23a..54333be4f 100644 --- a/src/examples/Example_opencv.cpp +++ b/src/examples/Example_opencv.cpp @@ -46,10 +46,54 @@ void trackVideo(openshot::Clip &r9){ // Opencv display window cv::namedWindow("Display Image", cv::WINDOW_NORMAL ); // Create Tracker - CVTracker kcfTracker; - bool trackerInit = false; - for (long int frame = 1200; frame <= 1600; frame++) + ClipProcessingJobs clipProcessing("Track", r9); + + // CVTracker kcfTracker; + + // kcfTracker.trackClip(r9); + // bool trackerInit = false; + // int videoLenght = r9.Reader()->info.video_length; + // for (long int frame = 0; frame < videoLenght; frame++) + // { + // int frame_number = frame; + // std::shared_ptr f = r9.GetFrame(frame_number); + + // // Grab Mat image + // cv::Mat cvimage = f->GetImageCV(); + + // if(!trackerInit){ + // cv::Rect2d bbox = cv::selectROI("Display Image", cvimage); + + // kcfTracker.initTracker(bbox, cvimage, frame_number); + // cv::rectangle(cvimage, bbox, cv::Scalar( 255, 0, 0 ), 2, 1 ); + + // trackerInit = true; + // } + // else{ + // trackerInit = kcfTracker.trackFrame(cvimage, frame_number); + + // // Draw box on image + // FrameData fd = kcfTracker.GetTrackedData(frame_number); + // // std::cout<< "fd: "<< fd.x1<< " "<< fd.y1 <<" "<info.video_length; + for (long int frame = 0; frame < videoLenght; frame++) { int frame_number = frame; std::shared_ptr f = r9.GetFrame(frame_number); @@ -57,35 +101,12 @@ void trackVideo(openshot::Clip &r9){ // Grab Mat image cv::Mat cvimage = f->GetImageCV(); - if(!trackerInit){ - cv::Rect2d bbox = cv::selectROI("Display Image", cvimage); - - kcfTracker.initTracker(bbox, cvimage, frame_number); - cv::rectangle(cvimage, bbox, cv::Scalar( 255, 0, 0 ), 2, 1 ); - - trackerInit = true; - } - else{ - trackerInit = kcfTracker.trackFrame(cvimage, frame_number); - - // Draw box on image - FrameData fd = kcfTracker.GetTrackedData(frame_number); - // std::cout<< "fd: "<< fd.x1<< " "<< fd.y1 <<" "<