Skip to content

Commit

Permalink
TrackedObject: Pare down includes
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Jun 5, 2021
1 parent c04ce9d commit 1edaf80
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 56 deletions.
9 changes: 5 additions & 4 deletions src/EffectBase.h
Expand Up @@ -31,14 +31,15 @@
#ifndef OPENSHOT_EFFECT_BASE_H
#define OPENSHOT_EFFECT_BASE_H

#include <iostream>
#include <iomanip>
#include <memory>
#include "ClipBase.h"

#include "Json.h"
#include "Frame.h"
#include "TrackedObjectBase.h"

#include <memory>
#include <map>
#include <string>

namespace openshot
{
/**
Expand Down
23 changes: 12 additions & 11 deletions src/TrackedObjectBBox.cpp
Expand Up @@ -30,15 +30,13 @@
*/

#include "TrackedObjectBBox.h"

#include "Clip.h"
#include <algorithm>
#include <fstream>
#include <iostream>
#include <functional>

using namespace std;
using namespace openshot;
#include "protobuf_messages/trackerdata.pb.h"
#include <google/protobuf/util/time_util.h>

using google::protobuf::util::TimeUtil;

// Default Constructor that sets the bounding-box displacement as 0 and the scales as 1 for the first frame
TrackedObjectBBox::TrackedObjectBBox() : delta_x(0.0), delta_y(0.0), scale_x(1.0), scale_y(1.0), rotation(0.0),
Expand Down Expand Up @@ -247,22 +245,24 @@ void TrackedObjectBBox::ScalePoints(double time_scale){
this->TimeScale = time_scale;
}

// Load the bounding-boxes information from the protobuf file
// Load the bounding-boxes information from the protobuf file
bool TrackedObjectBBox::LoadBoxData(std::string inputFilePath)
{
using std::ios;

// Variable to hold the loaded data
pb_tracker::Tracker bboxMessage;

// Read the existing tracker message.
fstream input(inputFilePath, ios::in | ios::binary);
std::fstream input(inputFilePath, ios::in | ios::binary);

// Check if it was able to read the protobuf data
if (!bboxMessage.ParseFromIstream(&input))
{
cerr << "Failed to parse protobuf message." << endl;
std::cerr << "Failed to parse protobuf message." << std::endl;
return false;
}

this->clear();

// Iterate over all frames of the saved message
Expand Down Expand Up @@ -294,7 +294,8 @@ bool TrackedObjectBBox::LoadBoxData(std::string inputFilePath)
// Show the time stamp from the last update in tracker data file
if (bboxMessage.has_last_updated())
{
cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString(bboxMessage.last_updated()) << endl;
std::cout << " Loaded Data. Saved Time Stamp: "
<< TimeUtil::ToString(bboxMessage.last_updated()) << std::endl;
}

// Delete all global objects allocated by libprotobuf.
Expand Down
41 changes: 15 additions & 26 deletions src/TrackedObjectBBox.h
Expand Up @@ -32,33 +32,22 @@
#ifndef OPENSHOT_TRACKEDOBJECTBBOX_H
#define OPENSHOT_TRACKEDOBJECTBBOX_H

#include <iostream>
#include <iomanip>
#include <cmath>
#include <assert.h>
#include <vector>
#include "TrackedObjectBase.h"

#include "Color.h"
#include "Exceptions.h"
#include "Fraction.h"
#include "Coordinate.h"
#include "Point.h"
#include "Json.h"
#include "KeyFrame.h"
#include "TrackedObjectBase.h"
#include "Color.h"
#include "protobuf_messages/trackerdata.pb.h"
#include <google/protobuf/util/time_util.h>


using google::protobuf::util::TimeUtil;

namespace openshot
{
/**
* @brief This struct holds the information of a bounding-box.
*
*
* A bounding-box is a rectangular shape that enclosures an
* object or a desired set of pixels in a digital image.
*
*
* The bounding-box structure holds five floating-point properties:
* the x and y coordinates of the rectangle's center point (cx, cy),
* the rectangle's width, height and rotation.
Expand Down Expand Up @@ -89,7 +78,7 @@ namespace openshot
angle = _angle;
}


/// Generate JSON string of this object
std::string Json() const
{
Expand Down Expand Up @@ -141,17 +130,17 @@ namespace openshot
height = root["height"].asDouble();
if (!root["angle"].isNull())
angle = root["angle"].asDouble();
}
}
};

/**
* @brief This class contains the properties of a tracked object
* and functions to manipulate it.
*
*
* The bounding-box displacement in X and Y directions, it's width,
* height and rotation variation over the frames are set as
* openshot::Keyframe objects.
*
*
* The bounding-box information over the clip's frames are
* saved into a protobuf file and loaded into an
* object of this class.
Expand All @@ -160,7 +149,7 @@ namespace openshot
{
private:
Fraction BaseFps;
double TimeScale;
double TimeScale;

public:
std::map<double, BBox> BoxVec; ///< Index the bounding-box by time of each frame
Expand All @@ -184,7 +173,7 @@ namespace openshot

/// Add a BBox to the BoxVec map
void AddBox(int64_t _frame_num, float _cx, float _cy, float _width, float _height, float _angle) override;

/// Update object's BaseFps
void SetBaseFPS(Fraction fps);

Expand Down Expand Up @@ -213,7 +202,7 @@ namespace openshot
return const_cast<TrackedObjectBBox *>(this)->GetBox(frame_number);
}

/// Load the bounding-boxes information from the protobuf file
/// Load the bounding-boxes information from the protobuf file
bool LoadBoxData(std::string inputFilePath);

/// Get the time of the given frame
Expand All @@ -223,7 +212,7 @@ namespace openshot
BBox InterpolateBoxes(double t1, double t2, BBox left, BBox right, double target);

/// Clear the BoxVec map
void clear();
void clear();

/// Get and Set JSON methods
std::string Json() const override; ///< Generate JSON string of this object
Expand All @@ -242,8 +231,8 @@ namespace openshot
std::map<std::string, float> GetBoxValues(int64_t frame_number) const override;
/// Return a map that contains the properties of this object's parent clip
std::map<std::string, float> GetParentClipProperties(int64_t frame_number) const override;

};
} // namespace openshot

#endif
#endif
5 changes: 2 additions & 3 deletions src/TrackedObjectBase.cpp
Expand Up @@ -30,9 +30,8 @@
*/

#include "TrackedObjectBase.h"
#include <algorithm>
#include <functional>
#include <utility>

#include "Json.h"

namespace openshot
{
Expand Down
17 changes: 5 additions & 12 deletions src/TrackedObjectBase.h
Expand Up @@ -32,22 +32,17 @@
#ifndef OPENSHOT_TRACKEDOBJECTBASE_H
#define OPENSHOT_TRACKEDOBJECTBASE_H

#include <iostream>
#include <iomanip>
#include <cmath>
#include <assert.h>
#include <vector>
#include <string>
#include "Exceptions.h"
#include "Fraction.h"
#include "Coordinate.h"

#include "KeyFrame.h"
#include "Point.h"
#include "Json.h"
#include "ClipBase.h"


namespace openshot {

// Forward decls
class ClipBase;

/**
* @brief This abstract class is the base class of all Tracked Objects.
*
Expand Down Expand Up @@ -108,8 +103,6 @@ namespace openshot {
virtual Json::Value PropertiesJSON(int64_t requested_frame) const = 0;
/// Generate JSON choice for a property (dropdown properties)
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const;


};
} // Namespace openshot

Expand Down

0 comments on commit 1edaf80

Please sign in to comment.