Loading...
Searching...
No Matches
CVTracker.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_CVTRACKER_H
#define OPENSHOT_CVTRACKER_H
#include "OpenCVUtilities.h"
#define int64 int64_t
#define uint64 uint64_t
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/core.hpp>
#undef uint64
#undef int64
#include "Clip.h"
#include "KeyFrame.h"
#include "Frame.h"
#include "Json.h"
#include "ProcessingController.h"
#include "sort_filter/sort.hpp"
// Forward decl
namespace pb_tracker {
class Frame;
}
namespace openshot
{
// Store the tracked object information for one frame
struct FrameData{
size_t frame_id = -1;
float rotation = 0;
float x1 = -1;
float y1 = -1;
float x2 = -1;
float y2 = -1;
// Constructors
FrameData()
{}
FrameData( size_t _frame_id)
{frame_id = _frame_id;}
FrameData( size_t _frame_id , float _rotation, float _x1, float _y1, float _x2, float _y2)
{
frame_id = _frame_id;
rotation = _rotation;
x1 = _x1;
y1 = _y1;
x2 = _x2;
y2 = _y2;
}
};
class CVTracker {
private:
std::map<size_t, FrameData> trackedDataById; // Save tracked data
std::string trackerType; // Name of the chosen tracker
cv::Ptr<OPENCV_TRACKER_TYPE> tracker; // Pointer of the selected tracker
cv::Rect2d bbox; // Bounding box coords
SortTracker sort;
std::string protobuf_data_path; // Path to protobuf data file
uint progress; // Pre-processing effect progress
ProcessingController *processingController;
bool json_interval;
size_t start;
size_t end;
bool error = false;
// Initialize the tracker
bool initTracker(cv::Mat &frame, size_t frameId);
// Update the object tracker according to frame
bool trackFrame(cv::Mat &frame, size_t frameId);
public:
// Constructor
CVTracker(std::string processInfoJson, ProcessingController &processingController);
// Set desirable tracker method
cv::Ptr<OPENCV_TRACKER_TYPE> selectTracker(std::string trackerType);
void trackClip(openshot::Clip& video, size_t _start=0, size_t _end=0, bool process_interval=false);
cv::Rect2d filter_box_jitter(size_t frameId);
FrameData GetTrackedData(size_t frameId);
// Protobuf Save and Load methods
bool SaveTrackedData();
void AddFrameDataToProto(pb_tracker::Frame* pbFrameData, FrameData& fData);
// Get and Set JSON methods
void SetJson(const std::string value);
void SetJsonValue(const Json::Value root);
// Load protobuf file (ONLY FOR MAKE TEST)
bool _LoadTrackedData();
};
}
#endif
Clip.h
Header file for Clip class.
Frame.h
Header file for Frame 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)
ProcessingController.h
This is a message class for thread safe comunication between ClipProcessingJobs and OpenCV classes.
ProcessingController
Definition ProcessingController.h:20
SortTracker
Definition sort.hpp:33
openshot::CVTracker
The tracker class will receive one bounding box provided by the user and then iterate over the clip f...
Definition CVTracker.h:75
openshot::CVTracker::trackClip
void trackClip(openshot::Clip &video, size_t _start=0, size_t _end=0, bool process_interval=false)
Definition CVTracker.cpp:58
openshot::CVTracker::SaveTrackedData
bool SaveTrackedData()
Save protobuf file.
Definition CVTracker.cpp:205
openshot::CVTracker::_LoadTrackedData
bool _LoadTrackedData()
Definition CVTracker.cpp:326
openshot::CVTracker::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition CVTracker.cpp:284
openshot::CVTracker::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition CVTracker.cpp:267
openshot::CVTracker::filter_box_jitter
cv::Rect2d filter_box_jitter(size_t frameId)
Filter current bounding box jitter.
Definition CVTracker.cpp:185
openshot::CVTracker::AddFrameDataToProto
void AddFrameDataToProto(pb_tracker::Frame *pbFrameData, FrameData &fData)
Add frame tracked data into protobuf message.
Definition CVTracker.cpp:238
openshot::CVTracker::GetTrackedData
FrameData GetTrackedData(size_t frameId)
Get tracked data for a given frame.
Definition CVTracker.cpp:253
openshot::CVTracker::selectTracker
cv::Ptr< OPENCV_TRACKER_TYPE > selectTracker(std::string trackerType)
Definition CVTracker.cpp:37
openshot::Clip
This class represents a clip (used to arrange readers on the timeline)
Definition Clip.h:89
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
pb_tracker
Definition CVTracker.h:37
sort.hpp
openshot::FrameData
Definition CVTracker.h:45
openshot::FrameData::x2
float x2
Definition CVTracker.h:50
openshot::FrameData::y1
float y1
Definition CVTracker.h:49
openshot::FrameData::x1
float x1
Definition CVTracker.h:48
openshot::FrameData::FrameData
FrameData()
Definition CVTracker.h:54
openshot::FrameData::FrameData
FrameData(size_t _frame_id)
Definition CVTracker.h:57
openshot::FrameData::rotation
float rotation
Definition CVTracker.h:47
openshot::FrameData::frame_id
size_t frame_id
Definition CVTracker.h:46
openshot::FrameData::y2
float y2
Definition CVTracker.h:51
openshot::FrameData::FrameData
FrameData(size_t _frame_id, float _rotation, float _x1, float _y1, float _x2, float _y2)
Definition CVTracker.h:60