OpenShot Library | libopenshot  0.2.7
Tracker.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for Tracker effect class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  * @author Brenno Caldato <brenno.caldato@outlook.com>
6  *
7  * @ref License
8  */
9 
10 /* LICENSE
11  *
12  * Copyright (c) 2008-2019 OpenShot Studios, LLC
13  * <http://www.openshotstudios.com/>. This file is part of
14  * OpenShot Library (libopenshot), an open-source project dedicated to
15  * delivering high quality video editing and animation solutions to the
16  * world. For more information visit <http://www.openshot.org/>.
17  *
18  * OpenShot Library (libopenshot) is free software: you can redistribute it
19  * and/or modify it under the terms of the GNU Lesser General Public License
20  * as published by the Free Software Foundation, either version 3 of the
21  * License, or (at your option) any later version.
22  *
23  * OpenShot Library (libopenshot) is distributed in the hope that it will be
24  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU Lesser General Public License for more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License
29  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
30  */
31 
32 #ifndef OPENSHOT_TRACKER_EFFECT_H
33 #define OPENSHOT_TRACKER_EFFECT_H
34 
35 #include <string>
36 #include <memory>
37 #include <map>
38 
39 #include "../EffectBase.h"
40 
41 #include "../Json.h"
42 #include "../KeyFrame.h"
43 
44 #include "protobuf_messages/trackerdata.pb.h"
45 #include "../TrackedObjectBBox.h"
46 #include "../Clip.h"
47 
48 namespace openshot
49 {
50  /**
51  * @brief This class tracks a given object through the clip, draws a box around it and allow
52  * the user to attach another clip (image or video) to the tracked object.
53  *
54  * Tracking is useful to better visualize, follow the movement of an object through video
55  * and attach an image or video to it.
56  */
57  class Tracker : public EffectBase
58  {
59  private:
60  /// Init effect settings
61  void init_effect_details();
62 
63  Fraction BaseFPS;
64  double TimeScale;
65 
66  public:
67  std::string protobuf_data_path; ///< Path to the protobuf file that holds the bounding-box data
68  std::shared_ptr<TrackedObjectBBox> trackedData; ///< Pointer to an object that holds the bounding-box data and it's Keyframes
69 
70  /// Blank constructor, useful when using Json to load the effect properties
71  Tracker(std::string clipTrackerDataPath);
72 
73  /// Default constructor
74  Tracker();
75 
76  /// @brief This method is required for all derived classes of EffectBase, and returns a
77  /// modified openshot::Frame object
78  ///
79  /// The frame object is passed into this method, and a frame_number is passed in which
80  /// tells the effect which settings to use from its keyframes (starting at 1).
81  ///
82  /// @returns The modified openshot::Frame object
83  /// @param frame The frame object that needs the effect applied to it
84  /// @param frame_number The frame number (starting at 1) of the effect on the timeline.
85  std::shared_ptr<Frame> GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) override;
86  std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override { return GetFrame(std::shared_ptr<Frame> (new Frame()), frame_number); }
87 
88  /// Get the indexes and IDs of all visible objects in the given frame
89  std::string GetVisibleObjects(int64_t frame_number) const override;
90 
91  void DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect box, std::vector<int> color, float alpha, int thickness, bool is_background);
92 
93  // Get and Set JSON methods
94  std::string Json() const override; ///< Generate JSON string of this object
95  void SetJson(const std::string value) override; ///< Load JSON string into this object
96  Json::Value JsonValue() const override; ///< Generate Json::Value for this object
97  void SetJsonValue(const Json::Value root) override; ///< Load Json::Value into this object
98 
99  /// Get all properties for a specific frame (perfect for a UI to display the current state
100  /// of all properties at any time)
101  std::string PropertiesJSON(int64_t requested_frame) const override;
102  };
103 
104 }
105 
106 #endif
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:71
This class represents a fraction.
Definition: Fraction.h:48
This class represents a single frame of video (i.e. image & audio data)
Definition: Frame.h:108
This class tracks a given object through the clip, draws a box around it and allow the user to attach...
Definition: Tracker.h:58
std::string Json() const override
Generate JSON string of this object.
Definition: Tracker.cpp:252
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
Definition: Tracker.h:86
std::string GetVisibleObjects(int64_t frame_number) const override
Get the indexes and IDs of all visible objects in the given frame.
Definition: Tracker.cpp:230
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Tracker.cpp:259
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: Tracker.cpp:285
std::shared_ptr< Frame > GetFrame(std::shared_ptr< Frame > frame, int64_t frame_number) override
This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame...
Definition: Tracker.cpp:103
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Tracker.cpp:359
std::shared_ptr< TrackedObjectBBox > trackedData
Pointer to an object that holds the bounding-box data and it's Keyframes.
Definition: Tracker.h:68
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Tracker.cpp:303
Tracker()
Default constructor.
Definition: Tracker.cpp:69
void DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect box, std::vector< int > color, float alpha, int thickness, bool is_background)
Definition: Tracker.cpp:189
std::string protobuf_data_path
Path to the protobuf file that holds the bounding-box data.
Definition: Tracker.h:67
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47