Loading...
Searching...
No Matches
ObjectDetection.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_OBJECT_DETECTION_EFFECT_H
#define OPENSHOT_OBJECT_DETECTION_EFFECT_H
#include "EffectBase.h"
#include <memory>
#include "OpenCVUtilities.h"
#include "Json.h"
#include "KeyFrame.h"
// Struct that stores the detected bounding boxes for all the clip frames
struct DetectionData{
DetectionData(){}
DetectionData(
std::vector<int> _classIds,
std::vector<float> _confidences,
std::vector<cv::Rect_<float>> _boxes,
size_t _frameId,
std::vector<int> _objectIds)
{
classIds = _classIds;
confidences = _confidences;
boxes = _boxes;
frameId = _frameId;
objectIds = _objectIds;
}
size_t frameId;
std::vector<int> classIds;
std::vector<float> confidences;
std::vector<cv::Rect_<float>> boxes;
std::vector<int> objectIds;
};
namespace openshot
{
// Forward decls
class Frame;
class ObjectDetection : public EffectBase
{
private:
std::string protobuf_data_path;
std::map<size_t, DetectionData> detectionsData;
std::vector<std::string> classNames;
std::vector<cv::Scalar> classesColor;
Keyframe display_box_text;
float confidence_threshold = 0.5;
std::vector<std::string> display_classes;
std::string class_filter;
void init_effect_details();
void drawPred(int classId, float conf, cv::Rect2d box, cv::Mat& frame, int objectNumber, std::vector<int> color, float alpha,
int thickness, bool is_background, bool draw_text);
void DrawRectangleRGBA(cv::Mat &frame_image, cv::RotatedRect box, std::vector<int> color, float alpha, int thickness, bool is_background);
public:
int selectedObjectIndex;
ObjectDetection(std::string clipTrackerDataPath);
ObjectDetection();
std::shared_ptr<Frame> GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) override;
std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override { return GetFrame(std::make_shared<Frame>(), frame_number); }
bool LoadObjDetectdData(std::string inputFilePath);
std::string GetVisibleObjects(int64_t frame_number) const override;
// Get and Set JSON methods
std::string Json() const override;
void SetJson(const std::string value) override;
Json::Value JsonValue() const override;
void SetJsonValue(const Json::Value root) override;
std::string PropertiesJSON(int64_t requested_frame) const override;
};
}
#endif
EffectBase.h
Header file for EffectBase class.
Json.h
Header file for JSON class.
KeyFrame.h
Header file for the Keyframe class.
OpenCVUtilities.h
Header file for OpenCVUtilities (set some common macros)
openshot::EffectBase
This abstract class is the base class, used by all effects in libopenshot.
Definition EffectBase.h:53
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
This effect displays all the detected objects on a clip.
Definition ObjectDetection.h:58
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:103
openshot::ObjectDetection::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition ObjectDetection.cpp:436
openshot::ObjectDetection::selectedObjectIndex
int selectedObjectIndex
Index of the Tracked Object that was selected to modify it's properties.
Definition ObjectDetection.h:85
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:70
openshot::ObjectDetection::ObjectDetection
ObjectDetection()
Default constructor.
Definition ObjectDetection.cpp:44
openshot::ObjectDetection::LoadObjDetectdData
bool LoadObjDetectdData(std::string inputFilePath)
Load protobuf data file.
Definition ObjectDetection.cpp:280
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:384
openshot::ObjectDetection::Json
std::string Json() const override
Generate JSON string of this object.
Definition ObjectDetection.cpp:429
openshot::ObjectDetection::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition ObjectDetection.cpp:534
openshot::ObjectDetection::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition ObjectDetection.cpp:477
openshot::ObjectDetection::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition ObjectDetection.cpp:460
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
DetectionData
Definition ObjectDetection.h:27
DetectionData::boxes
std::vector< cv::Rect_< float > > boxes
Definition ObjectDetection.h:45
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::confidences
std::vector< float > confidences
Definition ObjectDetection.h:44
DetectionData::classIds
std::vector< int > classIds
Definition ObjectDetection.h:43
DetectionData::objectIds
std::vector< int > objectIds
Definition ObjectDetection.h:46
DetectionData::frameId
size_t frameId
Definition ObjectDetection.h:42
DetectionData::DetectionData
DetectionData()
Definition ObjectDetection.h:28