2020-07-09 20:26:01 -03:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Track an object selected by the user
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
2021-04-20 23:07:23 -03:00
|
|
|
* @author Brenno Caldato <brenno.caldato@outlook.com>
|
2020-07-09 20:26:01 -03:00
|
|
|
*
|
|
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
|
|
|
|
*
|
|
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
|
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-05-04 07:33:47 -04:00
|
|
|
#include <fstream>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2021-01-13 20:22:17 -03:00
|
|
|
#include <google/protobuf/util/time_util.h>
|
2020-06-26 10:29:08 -03:00
|
|
|
|
2021-05-04 07:33:47 -04:00
|
|
|
#include "OpenCVUtilities.h"
|
|
|
|
|
#include "CVTracker.h"
|
|
|
|
|
|
2020-10-29 00:21:28 -03:00
|
|
|
using namespace openshot;
|
2021-01-13 20:22:17 -03:00
|
|
|
using google::protobuf::util::TimeUtil;
|
2020-10-29 00:21:28 -03:00
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Constructor
|
|
|
|
|
CVTracker::CVTracker(std::string processInfoJson, ProcessingController &processingController)
|
2021-01-13 12:08:33 -05:00
|
|
|
: processingController(&processingController), json_interval(false){
|
2020-07-16 21:10:02 -03:00
|
|
|
SetJson(processInfoJson);
|
2021-04-15 21:52:02 -03:00
|
|
|
start = 1;
|
|
|
|
|
end = 1;
|
2020-06-26 10:29:08 -03:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 22:31:26 -03:00
|
|
|
// Set desirable tracker method
|
2021-05-04 07:33:47 -04:00
|
|
|
cv::Ptr<OPENCV_TRACKER_TYPE> CVTracker::selectTracker(std::string trackerType){
|
2020-07-09 20:26:01 -03:00
|
|
|
|
|
|
|
|
if (trackerType == "BOOSTING")
|
2021-05-04 07:33:47 -04:00
|
|
|
return OPENCV_TRACKER_NS::TrackerBoosting::create();
|
2020-07-09 20:26:01 -03:00
|
|
|
if (trackerType == "MIL")
|
2021-05-04 07:33:47 -04:00
|
|
|
return OPENCV_TRACKER_NS::TrackerMIL::create();
|
2020-07-09 20:26:01 -03:00
|
|
|
if (trackerType == "KCF")
|
2021-05-04 07:33:47 -04:00
|
|
|
return OPENCV_TRACKER_NS::TrackerKCF::create();
|
2020-07-09 20:26:01 -03:00
|
|
|
if (trackerType == "TLD")
|
2021-05-04 07:33:47 -04:00
|
|
|
return OPENCV_TRACKER_NS::TrackerTLD::create();
|
2020-07-09 20:26:01 -03:00
|
|
|
if (trackerType == "MEDIANFLOW")
|
2021-05-04 07:33:47 -04:00
|
|
|
return OPENCV_TRACKER_NS::TrackerMedianFlow::create();
|
2020-07-09 20:26:01 -03:00
|
|
|
if (trackerType == "MOSSE")
|
2021-05-04 07:33:47 -04:00
|
|
|
return OPENCV_TRACKER_NS::TrackerMOSSE::create();
|
2020-07-09 20:26:01 -03:00
|
|
|
if (trackerType == "CSRT")
|
2021-05-04 07:33:47 -04:00
|
|
|
return OPENCV_TRACKER_NS::TrackerCSRT::create();
|
2020-06-26 10:29:08 -03:00
|
|
|
|
2021-05-04 07:33:47 -04:00
|
|
|
return nullptr;
|
2020-06-26 10:29:08 -03:00
|
|
|
}
|
|
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
// Track object in the hole clip or in a given interval
|
2020-07-22 10:00:40 -03:00
|
|
|
void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, bool process_interval){
|
2020-07-08 11:49:46 -03:00
|
|
|
|
2020-07-22 10:00:40 -03:00
|
|
|
video.Open();
|
2020-07-23 20:06:10 -03:00
|
|
|
if(!json_interval){
|
|
|
|
|
start = _start; end = _end;
|
|
|
|
|
|
2021-04-15 21:52:02 -03:00
|
|
|
if(!process_interval || end <= 1 || end-start == 0){
|
2020-07-23 20:06:10 -03:00
|
|
|
// Get total number of frames in video
|
2021-04-15 21:52:02 -03:00
|
|
|
start = (int)(video.Start() * video.Reader()->info.fps.ToFloat()) + 1;
|
|
|
|
|
end = (int)(video.End() * video.Reader()->info.fps.ToFloat()) + 1;
|
2020-07-23 20:06:10 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
2021-04-15 21:52:02 -03:00
|
|
|
start = (int)(start + video.Start() * video.Reader()->info.fps.ToFloat()) + 1;
|
|
|
|
|
end = (int)(video.End() * video.Reader()->info.fps.ToFloat()) + 1;
|
2020-07-16 21:10:02 -03:00
|
|
|
}
|
2021-01-13 12:08:33 -05:00
|
|
|
|
2020-11-01 20:02:46 -03:00
|
|
|
if(error){
|
|
|
|
|
return;
|
2021-01-13 12:08:33 -05:00
|
|
|
}
|
|
|
|
|
|
2020-11-01 20:02:46 -03:00
|
|
|
processingController->SetError(false, "");
|
2020-07-23 20:06:10 -03:00
|
|
|
bool trackerInit = false;
|
|
|
|
|
|
|
|
|
|
size_t frame;
|
2020-07-08 22:31:26 -03:00
|
|
|
// Loop through video
|
2020-07-22 14:05:19 -03:00
|
|
|
for (frame = start; frame <= end; frame++)
|
2020-07-08 11:49:46 -03:00
|
|
|
{
|
2020-07-16 21:10:02 -03:00
|
|
|
|
|
|
|
|
// Stop the feature tracker process
|
|
|
|
|
if(processingController->ShouldStop()){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t frame_number = frame;
|
2020-07-08 22:31:26 -03:00
|
|
|
// Get current frame
|
2020-07-08 11:49:46 -03:00
|
|
|
std::shared_ptr<openshot::Frame> f = video.GetFrame(frame_number);
|
2021-01-13 12:08:33 -05:00
|
|
|
|
2020-07-09 20:26:01 -03:00
|
|
|
// Grab OpenCV Mat image
|
2020-07-08 11:49:46 -03:00
|
|
|
cv::Mat cvimage = f->GetImageCV();
|
|
|
|
|
|
2021-03-15 21:45:31 -03:00
|
|
|
if(frame == start){
|
|
|
|
|
// Take the normalized inital bounding box and multiply to the current video shape
|
|
|
|
|
bbox = cv::Rect2d(bbox.x*cvimage.cols,bbox.y*cvimage.rows,bbox.width*cvimage.cols,
|
|
|
|
|
bbox.height*cvimage.rows);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 22:31:26 -03:00
|
|
|
// Pass the first frame to initialize the tracker
|
2020-07-08 11:49:46 -03:00
|
|
|
if(!trackerInit){
|
2021-01-13 12:08:33 -05:00
|
|
|
|
2020-07-08 22:31:26 -03:00
|
|
|
// Initialize the tracker
|
2020-07-16 21:10:02 -03:00
|
|
|
initTracker(cvimage, frame_number);
|
2020-07-08 11:49:46 -03:00
|
|
|
|
|
|
|
|
trackerInit = true;
|
|
|
|
|
}
|
|
|
|
|
else{
|
2021-01-13 12:08:33 -05:00
|
|
|
// Update the object tracker according to frame
|
2020-07-28 21:01:57 -03:00
|
|
|
trackerInit = trackFrame(cvimage, frame_number);
|
2021-01-13 12:08:33 -05:00
|
|
|
|
2020-07-08 11:49:46 -03:00
|
|
|
// Draw box on image
|
|
|
|
|
FrameData fd = GetTrackedData(frame_number);
|
|
|
|
|
|
|
|
|
|
}
|
2020-07-16 21:10:02 -03:00
|
|
|
// Update progress
|
2020-07-22 14:05:19 -03:00
|
|
|
processingController->SetProgress(uint(100*(frame_number-start)/(end-start)));
|
2020-07-08 11:49:46 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 20:26:01 -03:00
|
|
|
// Initialize the tracker
|
2020-07-16 21:10:02 -03:00
|
|
|
bool CVTracker::initTracker(cv::Mat &frame, size_t frameId){
|
|
|
|
|
|
2020-06-27 17:37:12 -03:00
|
|
|
// Create new tracker object
|
2020-07-16 21:10:02 -03:00
|
|
|
tracker = selectTracker(trackerType);
|
2020-06-26 10:29:08 -03:00
|
|
|
|
2020-08-13 07:25:16 -03:00
|
|
|
// Correct if bounding box contains negative proportions (width and/or height < 0)
|
|
|
|
|
if(bbox.width < 0){
|
|
|
|
|
bbox.x = bbox.x - abs(bbox.width);
|
|
|
|
|
bbox.width = abs(bbox.width);
|
|
|
|
|
}
|
|
|
|
|
if(bbox.height < 0){
|
|
|
|
|
bbox.y = bbox.y - abs(bbox.height);
|
|
|
|
|
bbox.height = abs(bbox.height);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 20:26:01 -03:00
|
|
|
// Initialize tracker
|
2020-06-26 10:29:08 -03:00
|
|
|
tracker->init(frame, bbox);
|
|
|
|
|
|
2020-07-28 21:01:57 -03:00
|
|
|
float fw = frame.size().width;
|
|
|
|
|
float fh = frame.size().height;
|
|
|
|
|
|
2020-06-27 17:37:12 -03:00
|
|
|
// Add new frame data
|
2020-07-28 21:01:57 -03:00
|
|
|
trackedDataById[frameId] = FrameData(frameId, 0, (bbox.x)/fw,
|
|
|
|
|
(bbox.y)/fh,
|
|
|
|
|
(bbox.x+bbox.width)/fw,
|
|
|
|
|
(bbox.y+bbox.height)/fh);
|
2020-06-27 17:37:12 -03:00
|
|
|
|
2020-06-26 10:29:08 -03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 12:08:33 -05:00
|
|
|
// Update the object tracker according to frame
|
2020-07-28 21:01:57 -03:00
|
|
|
bool CVTracker::trackFrame(cv::Mat &frame, size_t frameId){
|
2020-06-26 10:29:08 -03:00
|
|
|
// Update the tracking result
|
|
|
|
|
bool ok = tracker->update(frame, bbox);
|
|
|
|
|
|
2020-07-09 20:26:01 -03:00
|
|
|
// Add frame number and box coords if tracker finds the object
|
|
|
|
|
// Otherwise add only frame number
|
2020-06-26 10:29:08 -03:00
|
|
|
if (ok)
|
|
|
|
|
{
|
2020-07-28 21:01:57 -03:00
|
|
|
float fw = frame.size().width;
|
|
|
|
|
float fh = frame.size().height;
|
|
|
|
|
|
2021-03-16 13:15:55 -03:00
|
|
|
cv::Rect2d filtered_box = filter_box_jitter(frameId);
|
2020-06-27 17:37:12 -03:00
|
|
|
// Add new frame data
|
2021-03-16 13:15:55 -03:00
|
|
|
trackedDataById[frameId] = FrameData(frameId, 0, (filtered_box.x)/fw,
|
|
|
|
|
(filtered_box.y)/fh,
|
|
|
|
|
(filtered_box.x+filtered_box.width)/fw,
|
|
|
|
|
(filtered_box.y+filtered_box.height)/fh);
|
2020-06-26 10:29:08 -03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-16 13:15:55 -03:00
|
|
|
// Copy the last frame data if the tracker get lost
|
|
|
|
|
trackedDataById[frameId] = trackedDataById[frameId-1];
|
2020-06-26 10:29:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
2020-06-27 17:37:12 -03:00
|
|
|
|
2021-03-16 13:15:55 -03:00
|
|
|
cv::Rect2d CVTracker::filter_box_jitter(size_t frameId){
|
|
|
|
|
// get tracked data for the previous frame
|
|
|
|
|
float last_box_width = trackedDataById[frameId-1].x2 - trackedDataById[frameId-1].x1;
|
|
|
|
|
float last_box_height = trackedDataById[frameId-1].y2 - trackedDataById[frameId-1].y1;
|
|
|
|
|
|
|
|
|
|
float curr_box_width = bbox.width;
|
|
|
|
|
float curr_box_height = bbox.height;
|
|
|
|
|
// keep the last width and height if the difference is less than 1%
|
|
|
|
|
float threshold = 0.01;
|
2021-09-06 17:59:46 -04:00
|
|
|
|
2021-03-16 13:15:55 -03:00
|
|
|
cv::Rect2d filtered_box = bbox;
|
|
|
|
|
if(std::abs(1-(curr_box_width/last_box_width)) <= threshold){
|
|
|
|
|
filtered_box.width = last_box_width;
|
|
|
|
|
}
|
|
|
|
|
if(std::abs(1-(curr_box_height/last_box_height)) <= threshold){
|
|
|
|
|
filtered_box.height = last_box_height;
|
|
|
|
|
}
|
|
|
|
|
return filtered_box;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
bool CVTracker::SaveTrackedData(){
|
2021-05-04 07:33:47 -04:00
|
|
|
using std::ios;
|
|
|
|
|
|
2020-06-27 17:37:12 -03:00
|
|
|
// Create tracker message
|
2021-01-13 13:36:15 -05:00
|
|
|
pb_tracker::Tracker trackerMessage;
|
2020-06-27 17:37:12 -03:00
|
|
|
|
2020-07-09 20:26:01 -03:00
|
|
|
// Iterate over all frames data and save in protobuf message
|
2020-07-16 21:10:02 -03:00
|
|
|
for(std::map<size_t,FrameData>::iterator it=trackedDataById.begin(); it!=trackedDataById.end(); ++it){
|
2020-06-27 19:30:15 -03:00
|
|
|
FrameData fData = it->second;
|
2021-01-13 13:36:15 -05:00
|
|
|
pb_tracker::Frame* pbFrameData;
|
2020-06-27 17:37:12 -03:00
|
|
|
AddFrameDataToProto(trackerMessage.add_frame(), fData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add timestamp
|
|
|
|
|
*trackerMessage.mutable_last_updated() = TimeUtil::SecondsToTimestamp(time(NULL));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Write the new message to disk.
|
2020-07-16 21:10:02 -03:00
|
|
|
std::fstream output(protobuf_data_path, ios::out | ios::trunc | ios::binary);
|
2020-06-27 17:37:12 -03:00
|
|
|
if (!trackerMessage.SerializeToOstream(&output)) {
|
2021-05-04 07:33:47 -04:00
|
|
|
std::cerr << "Failed to write protobuf message." << std::endl;
|
2020-06-27 17:37:12 -03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete all global objects allocated by libprotobuf.
|
|
|
|
|
google::protobuf::ShutdownProtobufLibrary();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add frame tracked data into protobuf message.
|
2021-01-13 13:36:15 -05:00
|
|
|
void CVTracker::AddFrameDataToProto(pb_tracker::Frame* pbFrameData, FrameData& fData) {
|
2020-06-27 17:37:12 -03:00
|
|
|
|
2020-07-09 20:26:01 -03:00
|
|
|
// Save frame number and rotation
|
|
|
|
|
pbFrameData->set_id(fData.frame_id);
|
|
|
|
|
pbFrameData->set_rotation(0);
|
2020-06-27 17:37:12 -03:00
|
|
|
|
2021-01-13 13:36:15 -05:00
|
|
|
pb_tracker::Frame::Box* box = pbFrameData->mutable_bounding_box();
|
2020-07-09 20:26:01 -03:00
|
|
|
// Save bounding box data
|
2020-06-27 17:37:12 -03:00
|
|
|
box->set_x1(fData.x1);
|
|
|
|
|
box->set_y1(fData.y1);
|
|
|
|
|
box->set_x2(fData.x2);
|
|
|
|
|
box->set_y2(fData.y2);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 12:08:33 -05:00
|
|
|
// Get tracker info for the desired frame
|
2020-07-16 21:10:02 -03:00
|
|
|
FrameData CVTracker::GetTrackedData(size_t frameId){
|
2020-06-27 19:30:15 -03:00
|
|
|
|
2020-07-08 22:31:26 -03:00
|
|
|
// Check if the tracker info for the requested frame exists
|
2020-06-27 19:30:15 -03:00
|
|
|
if ( trackedDataById.find(frameId) == trackedDataById.end() ) {
|
2021-01-13 12:08:33 -05:00
|
|
|
|
2020-06-27 19:30:15 -03:00
|
|
|
return FrameData();
|
|
|
|
|
} else {
|
2021-01-13 12:08:33 -05:00
|
|
|
|
2020-06-27 19:30:15 -03:00
|
|
|
return trackedDataById[frameId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-07-16 21:10:02 -03:00
|
|
|
|
|
|
|
|
// Load JSON string into this object
|
|
|
|
|
void CVTracker::SetJson(const std::string value) {
|
|
|
|
|
// Parse JSON string into JSON objects
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const Json::Value root = openshot::stringToJson(value);
|
|
|
|
|
// Set all values that match
|
|
|
|
|
|
|
|
|
|
SetJsonValue(root);
|
|
|
|
|
}
|
|
|
|
|
catch (const std::exception& e)
|
|
|
|
|
{
|
|
|
|
|
// Error parsing JSON (or missing keys)
|
2020-07-22 10:00:40 -03:00
|
|
|
throw openshot::InvalidJSON("JSON is invalid (missing keys or invalid data types)");
|
2020-07-16 21:10:02 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load Json::Value into this object
|
|
|
|
|
void CVTracker::SetJsonValue(const Json::Value root) {
|
2021-01-13 12:08:33 -05:00
|
|
|
|
2021-09-06 17:59:46 -04:00
|
|
|
// Set data from Json (if key is found)
|
|
|
|
|
if (!root["protobuf_data_path"].isNull()){
|
|
|
|
|
protobuf_data_path = (root["protobuf_data_path"].asString());
|
|
|
|
|
}
|
2020-11-05 11:17:03 -03:00
|
|
|
if (!root["tracker-type"].isNull()){
|
2021-09-06 17:59:46 -04:00
|
|
|
trackerType = (root["tracker-type"].asString());
|
|
|
|
|
}
|
2021-01-13 12:08:33 -05:00
|
|
|
|
2020-11-05 11:17:03 -03:00
|
|
|
if (!root["region"].isNull()){
|
2021-03-15 21:45:31 -03:00
|
|
|
double x = root["region"]["normalized_x"].asDouble();
|
|
|
|
|
double y = root["region"]["normalized_y"].asDouble();
|
|
|
|
|
double w = root["region"]["normalized_width"].asDouble();
|
|
|
|
|
double h = root["region"]["normalized_height"].asDouble();
|
2020-07-16 21:10:02 -03:00
|
|
|
cv::Rect2d prev_bbox(x,y,w,h);
|
|
|
|
|
bbox = prev_bbox;
|
2021-09-08 12:35:57 -04:00
|
|
|
|
|
|
|
|
if (!root["region"]["first-frame"].isNull()){
|
|
|
|
|
start = root["region"]["first-frame"].asInt64();
|
|
|
|
|
json_interval = true;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
processingController->SetError(true, "No first-frame");
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 21:10:02 -03:00
|
|
|
}
|
2020-11-01 20:02:46 -03:00
|
|
|
else{
|
|
|
|
|
processingController->SetError(true, "No initial bounding box selected");
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-26 16:19:55 -03:00
|
|
|
}
|
|
|
|
|
|
2020-07-30 21:39:20 -03:00
|
|
|
/*
|
|
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
ONLY FOR MAKE TEST
|
|
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Load protobuf data file
|
|
|
|
|
bool CVTracker::_LoadTrackedData(){
|
2021-05-04 07:33:47 -04:00
|
|
|
using std::ios;
|
|
|
|
|
|
2020-07-30 21:39:20 -03:00
|
|
|
// Create tracker message
|
2021-01-13 13:36:15 -05:00
|
|
|
pb_tracker::Tracker trackerMessage;
|
2020-07-30 21:39:20 -03:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Read the existing tracker message.
|
2021-05-04 07:33:47 -04:00
|
|
|
std::fstream input(protobuf_data_path, ios::in | ios::binary);
|
2020-07-30 21:39:20 -03:00
|
|
|
if (!trackerMessage.ParseFromIstream(&input)) {
|
2021-05-04 07:33:47 -04:00
|
|
|
std::cerr << "Failed to parse protobuf message." << std::endl;
|
2020-07-30 21:39:20 -03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the trackedData is empty
|
|
|
|
|
trackedDataById.clear();
|
|
|
|
|
|
|
|
|
|
// Iterate over all frames of the saved message
|
|
|
|
|
for (size_t i = 0; i < trackerMessage.frame_size(); i++) {
|
2021-01-13 13:36:15 -05:00
|
|
|
const pb_tracker::Frame& pbFrameData = trackerMessage.frame(i);
|
2020-07-30 21:39:20 -03:00
|
|
|
|
|
|
|
|
// Load frame and rotation data
|
|
|
|
|
size_t id = pbFrameData.id();
|
|
|
|
|
float rotation = pbFrameData.rotation();
|
|
|
|
|
|
|
|
|
|
// Load bounding box data
|
2021-01-13 13:36:15 -05:00
|
|
|
const pb_tracker::Frame::Box& box = pbFrameData.bounding_box();
|
2020-07-30 21:39:20 -03:00
|
|
|
float x1 = box.x1();
|
|
|
|
|
float y1 = box.y1();
|
|
|
|
|
float x2 = box.x2();
|
|
|
|
|
float y2 = box.y2();
|
|
|
|
|
|
|
|
|
|
// Assign data to tracker map
|
|
|
|
|
trackedDataById[id] = FrameData(id, rotation, x1, y1, x2, y2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete all global objects allocated by libprotobuf.
|
|
|
|
|
google::protobuf::ShutdownProtobufLibrary();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|