OpenShot Library | libopenshot  0.3.2
ObjectDetection.h
Go to the documentation of this file.
1 
10 // Copyright (c) 2008-2019 OpenShot Studios, LLC
11 //
12 // SPDX-License-Identifier: LGPL-3.0-or-later
13 
14 #ifndef OPENSHOT_OBJECT_DETECTION_EFFECT_H
15 #define OPENSHOT_OBJECT_DETECTION_EFFECT_H
16 
17 #include "EffectBase.h"
18 
19 #include <memory>
20 
21 #include "OpenCVUtilities.h"
22 
23 #include "Json.h"
24 #include "KeyFrame.h"
25 
26 // Struct that stores the detected bounding boxes for all the clip frames
30  std::vector<int> _classIds,
31  std::vector<float> _confidences,
32  std::vector<cv::Rect_<float>> _boxes,
33  size_t _frameId,
34  std::vector<int> _objectIds)
35  {
36  classIds = _classIds;
37  confidences = _confidences;
38  boxes = _boxes;
39  frameId = _frameId;
40  objectIds = _objectIds;
41  }
42  size_t frameId;
43  std::vector<int> classIds;
44  std::vector<float> confidences;
45  std::vector<cv::Rect_<float>> boxes;
46  std::vector<int> objectIds;
47 };
48 
49 namespace openshot
50 {
51  // Forward decls
52  class Frame;
53 
57  class ObjectDetection : public EffectBase
58  {
59  private:
60  std::string protobuf_data_path;
61  std::map<size_t, DetectionData> detectionsData;
62  std::vector<std::string> classNames;
63  std::vector<cv::Scalar> classesColor;
64 
66  Keyframe display_box_text;
67 
69  Keyframe display_boxes;
70 
72  float confidence_threshold = 0.5;
73 
75  std::vector<std::string> display_classes;
76  std::string class_filter;
77 
79  void init_effect_details();
80 
81  public:
84 
85  ObjectDetection(std::string clipTrackerDataPath);
86 
89 
99  std::shared_ptr<Frame> GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) override;
100 
101  std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override { return GetFrame(std::make_shared<Frame>(), frame_number); }
102 
104  bool LoadObjDetectdData(std::string inputFilePath);
105 
107  std::string GetVisibleObjects(int64_t frame_number) const override;
108 
109  // Get and Set JSON methods
110  std::string Json() const override;
111  void SetJson(const std::string value) override;
112  Json::Value JsonValue() const override;
113  void SetJsonValue(const Json::Value root) override;
114 
117  std::string PropertiesJSON(int64_t requested_frame) const override;
118  };
119 
120 }
121 
122 #endif
openshot::ObjectDetection::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: ObjectDetection.cpp:363
openshot::ObjectDetection::GetFrame
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: ObjectDetection.cpp:74
openshot::EffectBase
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:53
openshot::ObjectDetection::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: ObjectDetection.cpp:338
DetectionData
Definition: ObjectDetection.h:27
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
DetectionData::objectIds
std::vector< int > objectIds
Definition: ObjectDetection.h:46
EffectBase.h
Header file for EffectBase class.
KeyFrame.h
Header file for the Keyframe class.
openshot::ObjectDetection::ObjectDetection
ObjectDetection()
Default constructor.
Definition: ObjectDetection.cpp:47
openshot::Keyframe
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
openshot::ObjectDetection::GetFrame
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: ObjectDetection.h:101
openshot::ObjectDetection::Json
std::string Json() const override
Generate JSON string of this object.
Definition: ObjectDetection.cpp:331
DetectionData::DetectionData
DetectionData(std::vector< int > _classIds, std::vector< float > _confidences, std::vector< cv::Rect_< float >> _boxes, size_t _frameId, std::vector< int > _objectIds)
Definition: ObjectDetection.h:29
DetectionData::classIds
std::vector< int > classIds
Definition: ObjectDetection.h:43
DetectionData::confidences
std::vector< float > confidences
Definition: ObjectDetection.h:44
openshot::ObjectDetection
This effect displays all the detected objects on a clip.
Definition: ObjectDetection.h:57
DetectionData::DetectionData
DetectionData()
Definition: ObjectDetection.h:28
openshot::ObjectDetection::LoadObjDetectdData
bool LoadObjDetectdData(std::string inputFilePath)
Load protobuf data file.
Definition: ObjectDetection.cpp:170
openshot::ObjectDetection::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: ObjectDetection.cpp:446
DetectionData::boxes
std::vector< cv::Rect_< float > > boxes
Definition: ObjectDetection.h:45
openshot::ObjectDetection::GetVisibleObjects
std::string GetVisibleObjects(int64_t frame_number) const override
Get the indexes and IDs of all visible objects in the given frame.
Definition: ObjectDetection.cpp:275
DetectionData::frameId
size_t frameId
Definition: ObjectDetection.h:42
Json.h
Header file for JSON class.
openshot::ObjectDetection::selectedObjectIndex
int selectedObjectIndex
Index of the Tracked Object that was selected to modify it's properties.
Definition: ObjectDetection.h:83
OpenCVUtilities.h
Header file for OpenCVUtilities (set some common macros)
openshot::ObjectDetection::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: ObjectDetection.cpp:380