OpenShot Library | libopenshot  0.7.0
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 #include "TrackedObjectBBox.h"
26 
27 namespace openshot {
28  class TrackedObjectBBox;
29 }
30 
31 // Struct that stores the detected bounding boxes for all the clip frames
35  std::vector<int> _classIds,
36  std::vector<float> _confidences,
37  std::vector<cv::Rect_<float>> _boxes,
38  size_t _frameId,
39  std::vector<int> _objectIds,
40  std::vector<openshot::ObjectMaskData> _masks = {})
41  {
42  classIds = _classIds;
43  confidences = _confidences;
44  boxes = _boxes;
45  frameId = _frameId;
46  objectIds = _objectIds;
47  masks = _masks;
48  }
49  size_t frameId;
50  std::vector<int> classIds;
51  std::vector<float> confidences;
52  std::vector<cv::Rect_<float>> boxes;
53  std::vector<int> objectIds;
54  std::vector<openshot::ObjectMaskData> masks;
55 };
56 
57 namespace openshot
58 {
59  // Forward decls
60  class Frame;
61 
65  class ObjectDetection : public EffectBase
66  {
67  private:
68  std::string protobuf_data_path;
69  std::map<size_t, DetectionData> detectionsData;
70  std::vector<std::string> classNames;
71  std::vector<cv::Scalar> classesColor;
72 
74  Keyframe display_box_text;
75 
77  Keyframe display_boxes;
78 
80  float confidence_threshold = 0.25;
81 
83  std::vector<std::string> display_classes;
84  std::string class_filter;
85 
87  std::shared_ptr<TrackedObjectBBox> allObjectsProperties;
88 
90  void init_effect_details();
91 
92  public:
95 
98 
108  std::shared_ptr<Frame> GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) override;
109 
110  std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override { return GetFrame(std::make_shared<Frame>(), frame_number); }
111 
113  bool LoadObjDetectdData(std::string inputFilePath);
114 
116  std::string GetVisibleObjects(int64_t frame_number) const override;
117 
119  std::shared_ptr<QImage> TrackedObjectMask(std::shared_ptr<QImage> target_image, int64_t frame_number) const override;
120 
121  // Get and Set JSON methods
122  std::string Json() const override;
123  void SetJson(const std::string value) override;
124  Json::Value JsonValue() const override;
125  void SetJsonValue(const Json::Value root) override;
126 
129  std::string PropertiesJSON(int64_t requested_frame) const override;
130  };
131 
132 }
133 
134 #endif
openshot::ObjectDetection::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: ObjectDetection.cpp:541
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:152
openshot::EffectBase
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:56
openshot::ObjectDetection::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: ObjectDetection.cpp:516
DetectionData
Definition: ObjectDetection.h:32
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AnimatedCurve.h:24
DetectionData::objectIds
std::vector< int > objectIds
Definition: ObjectDetection.h:53
EffectBase.h
Header file for EffectBase class.
KeyFrame.h
Header file for the Keyframe class.
openshot::ObjectDetection::ObjectDetection
ObjectDetection()
Default constructor.
Definition: ObjectDetection.cpp:124
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:110
DetectionData::masks
std::vector< openshot::ObjectMaskData > masks
Definition: ObjectDetection.h:54
openshot::ObjectDetection::Json
std::string Json() const override
Generate JSON string of this object.
Definition: ObjectDetection.cpp:509
DetectionData::classIds
std::vector< int > classIds
Definition: ObjectDetection.h:50
DetectionData::confidences
std::vector< float > confidences
Definition: ObjectDetection.h:51
openshot::ObjectDetection
This effect displays all the detected objects on a clip.
Definition: ObjectDetection.h:65
DetectionData::DetectionData
DetectionData()
Definition: ObjectDetection.h:33
openshot::ObjectDetection::LoadObjDetectdData
bool LoadObjDetectdData(std::string inputFilePath)
Load protobuf data file.
Definition: ObjectDetection.cpp:266
openshot::ObjectDetection::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: ObjectDetection.cpp:660
DetectionData::boxes
std::vector< cv::Rect_< float > > boxes
Definition: ObjectDetection.h:52
openshot::ObjectDetection::TrackedObjectMask
std::shared_ptr< QImage > TrackedObjectMask(std::shared_ptr< QImage > target_image, int64_t frame_number) const override
Generate a black/white mask from visible detected bounding boxes.
Definition: ObjectDetection.cpp:436
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:375
TrackedObjectBBox.h
Header file for the TrackedObjectBBox class.
DetectionData::frameId
size_t frameId
Definition: ObjectDetection.h:49
Json.h
Header file for JSON class.
DetectionData::DetectionData
DetectionData(std::vector< int > _classIds, std::vector< float > _confidences, std::vector< cv::Rect_< float >> _boxes, size_t _frameId, std::vector< int > _objectIds, std::vector< openshot::ObjectMaskData > _masks={})
Definition: ObjectDetection.h:34
openshot::ObjectDetection::selectedObjectIndex
int selectedObjectIndex
Index of the Tracked Object that was selected to modify it's properties.
Definition: ObjectDetection.h:94
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:558