1 /** 2 * @file 3 * @brief Header file for the TrackedObjectBase 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_TRACKEDOBJECTBASE_H 33 #define OPENSHOT_TRACKEDOBJECTBASE_H 34 35 #include <vector> 36 #include <string> 37 38 #include "KeyFrame.h" 39 #include "Json.h" 40 41 namespace openshot { 42 43 // Forward decls 44 class ClipBase; 45 46 /** 47 * @brief This abstract class is the base class of all Tracked Objects. 48 * 49 * A Tracked Object is an object or a desired set of pixels in a digital image 50 * which properties (such as position, width and height) can be detected and 51 * predicted along the frames of a clip. 52 */ 53 class TrackedObjectBase { 54 protected: 55 std::string id; 56 std::string childClipId; 57 58 ClipBase* parentClip; 59 60 public: 61 62 Keyframe visible; 63 Keyframe draw_box; 64 65 /// Default constructor 66 TrackedObjectBase(); 67 68 /// Constructor which takes an object ID 69 TrackedObjectBase(std::string _id); 70 71 /// Destructor 72 virtual ~TrackedObjectBase() = default; 73 74 /// Get the id of this object Id()75 std::string Id() const { return id; } 76 /// Set the id of this object Id(std::string _id)77 void Id(std::string _id) { id = _id; } 78 /// Get and set the parentClip of this object ParentClip()79 ClipBase* ParentClip() const { return parentClip; } ParentClip(ClipBase * clip)80 void ParentClip(ClipBase* clip) { parentClip = clip; } 81 /// Get and set the Id of the childClip of this object ChildClipId()82 std::string ChildClipId() const { return childClipId; }; ChildClipId(std::string _childClipId)83 void ChildClipId(std::string _childClipId) { childClipId = _childClipId; }; 84 85 /// Check if there is data for the exact frame number ExactlyContains(int64_t frame_number)86 virtual bool ExactlyContains(int64_t frame_number) const { return {}; }; 87 88 /// Scale an object's property ScalePoints(double scale)89 virtual void ScalePoints(double scale) { return; }; 90 /// Return the main properties of a TrackedObjectBBox instance - such as position, size and rotation GetBoxValues(int64_t frame_number)91 virtual std::map<std::string, float> GetBoxValues(int64_t frame_number) const { std::map<std::string, float> ret; return ret; }; 92 /// Return the main properties of the tracked object's parent clip - such as position, size and rotation GetParentClipProperties(int64_t frame_number)93 virtual std::map<std::string, float> GetParentClipProperties(int64_t frame_number) const { std::map<std::string, float> ret; return ret; } 94 /// Add a bounding box to the tracked object's BoxVec map AddBox(int64_t _frame_num,float _cx,float _cy,float _width,float _height,float _angle)95 virtual void AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle) { return; }; 96 97 98 /// Get and Set JSON methods 99 virtual std::string Json() const = 0; ///< Generate JSON string of this object 100 virtual Json::Value JsonValue() const = 0; ///< Generate Json::Value for this object 101 virtual void SetJson(const std::string value) = 0; ///< Load JSON string into this object 102 virtual void SetJsonValue(const Json::Value root) = 0; ///< Load Json::Value into this object 103 104 /// Get all properties for a specific frame (perfect for a UI to display the current state 105 /// of all properties at any time) 106 virtual Json::Value PropertiesJSON(int64_t requested_frame) const = 0; 107 /// Generate JSON choice for a property (dropdown properties) 108 Json::Value add_property_choice_json(std::string name, int value, int selected_value) const; 109 }; 110 } // Namespace openshot 111 112 #endif 113