OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
CVTracker.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_CVTRACKER_H
15#define OPENSHOT_CVTRACKER_H
16
17#include "OpenCVUtilities.h"
18
19#define int64 int64_t
20#define uint64 uint64_t
21#include <opencv2/opencv.hpp>
22#include <opencv2/tracking.hpp>
23#include <opencv2/core.hpp>
24#undef uint64
25#undef int64
26
27#include "Clip.h"
28#include "KeyFrame.h"
29#include "Frame.h"
30#include "Json.h"
31
33
34#include "sort_filter/sort.hpp"
35
36// Forward decl
37namespace pb_tracker {
38 class Frame;
39}
40
41namespace openshot
42{
43
44 // Store the tracked object information for one frame
45 struct FrameData{
46 size_t frame_id = -1;
47 float rotation = 0;
48 float x1 = -1;
49 float y1 = -1;
50 float x2 = -1;
51 float y2 = -1;
52
53 // Constructors
55 {}
56
57 FrameData( size_t _frame_id)
58 {frame_id = _frame_id;}
59
60 FrameData( size_t _frame_id , float _rotation, float _x1, float _y1, float _x2, float _y2)
61 {
62 frame_id = _frame_id;
63 rotation = _rotation;
64 x1 = _x1;
65 y1 = _y1;
66 x2 = _x2;
67 y2 = _y2;
68 }
69 };
70
75 class CVTracker {
76 private:
77 std::map<size_t, FrameData> trackedDataById; // Save tracked data
78 std::string trackerType; // Name of the chosen tracker
79 cv::Ptr<OPENCV_TRACKER_TYPE> tracker; // Pointer of the selected tracker
80
81 cv::Rect2d bbox; // Bounding box coords
82 SortTracker sort;
83
84 std::string protobuf_data_path; // Path to protobuf data file
85
86 uint progress; // Pre-processing effect progress
87
89 ProcessingController *processingController;
90
91 bool json_interval;
92 size_t start;
93 size_t end;
94
95 bool error = false;
96
97 // Initialize the tracker
98 bool initTracker(cv::Mat &frame, size_t frameId);
99
100 // Update the object tracker according to frame
101 bool trackFrame(cv::Mat &frame, size_t frameId);
102
103 public:
104
105 // Constructor
106 CVTracker(std::string processInfoJson, ProcessingController &processingController);
107
108 // Set desirable tracker method
109 cv::Ptr<OPENCV_TRACKER_TYPE> selectTracker(std::string trackerType);
110
114 void trackClip(openshot::Clip& video, size_t _start=0, size_t _end=0, bool process_interval=false);
115
117 cv::Rect2d filter_box_jitter(size_t frameId);
118
120 FrameData GetTrackedData(size_t frameId);
121
122 // Protobuf Save and Load methods
124 bool SaveTrackedData();
126 void AddFrameDataToProto(pb_tracker::Frame* pbFrameData, FrameData& fData);
127
128 // Get and Set JSON methods
129 void SetJson(const std::string value);
130 void SetJsonValue(const Json::Value root);
131
132 // Load protobuf file (ONLY FOR MAKE TEST)
133 bool _LoadTrackedData();
134 };
135}
136
137#endif
Header file for Clip class.
Header file for Frame class.
Header file for JSON class.
Header file for the Keyframe class.
Header file for OpenCVUtilities (set some common macros)
This is a message class for thread safe comunication between ClipProcessingJobs and OpenCV classes.
The tracker class will receive one bounding box provided by the user and then iterate over the clip f...
Definition CVTracker.h:75
void trackClip(openshot::Clip &video, size_t _start=0, size_t _end=0, bool process_interval=false)
Definition CVTracker.cpp:58
bool SaveTrackedData()
Save protobuf file.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void SetJson(const std::string value)
Load JSON string into this object.
cv::Rect2d filter_box_jitter(size_t frameId)
Filter current bounding box jitter.
void AddFrameDataToProto(pb_tracker::Frame *pbFrameData, FrameData &fData)
Add frame tracked data into protobuf message.
FrameData GetTrackedData(size_t frameId)
Get tracked data for a given frame.
cv::Ptr< OPENCV_TRACKER_TYPE > selectTracker(std::string trackerType)
Definition CVTracker.cpp:37
This class represents a clip (used to arrange readers on the timeline)
Definition Clip.h:89
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
FrameData(size_t _frame_id)
Definition CVTracker.h:57
FrameData(size_t _frame_id, float _rotation, float _x1, float _y1, float _x2, float _y2)
Definition CVTracker.h:60