OpenShot Library | libopenshot 1.1.1
ObjectMask.h
Go to the documentation of this file.
1
9// Copyright (c) 2026 OpenShot Studios, LLC
10//
11// SPDX-License-Identifier: LGPL-3.0-or-later
12
13#ifndef OPENSHOT_OBJECT_MASK_EFFECT_H
14#define OPENSHOT_OBJECT_MASK_EFFECT_H
15
16#include "Color.h"
17#include "EffectBase.h"
18#include "KeyFrame.h"
19#include "TrackedObjectBBox.h"
20
21#include <map>
22
23namespace openshot
24{
25 class Frame;
26
28 int width = 0;
29 int height = 0;
30 std::vector<uint32_t> rle;
32 float score = 0.0f;
33
34 bool HasData() const { return width > 0 && height > 0 && !rle.empty(); }
35 };
36
40 class ObjectMask : public EffectBase
41 {
42 private:
43 std::string protobuf_data_path;
44 std::map<size_t, ObjectMaskFrameData> masksData;
45
46 void init_effect_details();
47
48 public:
55
56 ObjectMask();
57
58 std::shared_ptr<Frame> GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) override;
59 std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override { return GetFrame(std::make_shared<Frame>(), frame_number); }
60
61 bool LoadObjMaskData(std::string inputFilePath);
62 std::shared_ptr<QImage> TrackedObjectMask(std::shared_ptr<QImage> target_image, int64_t frame_number) const override;
63
64 std::string Json() const override;
65 void SetJson(const std::string value) override;
66 Json::Value JsonValue() const override;
67 void SetJsonValue(const Json::Value root) override;
68
69 std::string PropertiesJSON(int64_t requested_frame) const override;
70 };
71}
72
73#endif
Header file for Color class.
Header file for EffectBase class.
Header file for the Keyframe class.
Header file for the TrackedObjectBBox class.
This class represents a color (used on the timeline and clips)
Definition: Color.h:27
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:57
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
Display and expose a preprocessed segmentation mask for an object.
Definition: ObjectMask.h:41
Keyframe stroke_width
Definition: ObjectMask.h:54
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: ObjectMask.cpp:275
Keyframe stroke_alpha
Definition: ObjectMask.h:53
std::shared_ptr< QImage > TrackedObjectMask(std::shared_ptr< QImage > target_image, int64_t frame_number) const override
Generate a black/white mask from tracked object data.
Definition: ObjectMask.cpp:226
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: ObjectMask.h:59
std::shared_ptr< Frame > GetFrame(std::shared_ptr< Frame > frame, int64_t frame_number) override
Definition: ObjectMask.cpp:122
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: ObjectMask.cpp:252
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: ObjectMask.cpp:266
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: ObjectMask.cpp:304
std::string Json() const override
Generate JSON string of this object.
Definition: ObjectMask.cpp:247
bool LoadObjMaskData(std::string inputFilePath)
Definition: ObjectMask.cpp:170
This namespace is the default namespace for all code in the openshot library.
Definition: AnimatedCurve.h:24
This struct holds the information of a bounding-box.
std::vector< uint32_t > rle
Definition: ObjectMask.h:30