Commit d0780166 authored by Matteo's avatar Matteo
Browse files

add formatting config and style guide

parent e075f46c
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
#define GETTIMELABEL_H #define GETTIMELABEL_H
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
/** /**
* @fn std::string getTimeLabel(int ms, std::string delim = ":") * @fn std::string getTimeLabel(int ms, std::string delim = ":")
* @brief Convert an int representing milliseconds to the corresponding Time Label string. * @brief Convert an int representing milliseconds to the corresponding Time
* Label string.
* *
* @param ms the number of milliseconds. * @param ms the number of milliseconds.
* @param delim the time separator * @param delim the time separator
......
This diff is collapsed.
#include "utility.h"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "utility.h"
using namespace cv; using namespace cv;
using namespace std; using namespace std;
...@@ -14,135 +15,137 @@ utility::Frame::Frame(const Mat& m) : Mat(m) {} ...@@ -14,135 +15,137 @@ utility::Frame::Frame(const Mat& m) : Mat(m) {}
utility::Frame::Frame(const Frame& f) : Mat(f) {} utility::Frame::Frame(const Frame& f) : Mat(f) {}
// Operators // Operators
utility::Frame& utility::Frame::operator=(const Mat& m) { utility::Frame& utility::Frame::operator=(const Mat& m) {
Mat::operator=(m); Mat::operator=(m);
return *this; return *this;
} }
utility::Frame& utility::Frame::operator=(const Frame& f) { utility::Frame& utility::Frame::operator=(const Frame& f) {
Mat::operator=(f); Mat::operator=(f);
return *this; return *this;
} }
// Methods // Methods
utility::Frame utility::Frame::clone() const { utility::Frame utility::Frame::clone() const { return utility::Frame(Mat::clone()); }
return utility::Frame(Mat::clone());
}
utility::Frame& utility::Frame::downsample(int factor) { utility::Frame& utility::Frame::downsample(int factor) {
pyrDown(*this, *this, Size(size().width / factor, size().height / factor)); pyrDown(*this, *this, Size(size().width / factor, size().height / factor));
return *this; return *this;
} }
utility::Frame& utility::Frame::convertColor(int code) { utility::Frame& utility::Frame::convertColor(int code) {
cvtColor(*this, *this, code); cvtColor(*this, *this, code);
return *this; return *this;
}
utility::Frame utility::Frame::difference(Frame& f) {
return Frame(utility::difference(*this, f));
} }
utility::Frame utility::Frame::difference(Frame& f) { return Frame(utility::difference(*this, f)); }
utility::Frame& utility::Frame::crop(Size rect_size, Point2f center) { utility::Frame& utility::Frame::crop(Size rect_size, Point2f center) {
cv::getRectSubPix(*this, rect_size, center, *this); cv::getRectSubPix(*this, rect_size, center, *this);
return *this; return *this;
} }
utility::Frame& utility::Frame::warp(cv::Mat rotationMatrix) { utility::Frame& utility::Frame::warp(cv::Mat rotationMatrix) {
cv::warpAffine(*this, *this, rotationMatrix, this->size(), INTER_CUBIC); cv::warpAffine(*this, *this, rotationMatrix, this->size(), INTER_CUBIC);
return *this; return *this;
} }
pair<utility::Frame, utility::Frame> utility::Frame::deinterlace() const { pair<utility::Frame, utility::Frame> utility::Frame::deinterlace() const {
Frame odd_frame(cv::Mat(this->rows/2, this->cols, CV_8UC3)); Frame odd_frame(cv::Mat(this->rows / 2, this->cols, CV_8UC3));
Frame even_frame(cv::Mat(this->rows/2, this->cols, CV_8UC3)); Frame even_frame(cv::Mat(this->rows / 2, this->cols, CV_8UC3));
utility::separateFrame(*this, odd_frame, even_frame); utility::separateFrame(*this, odd_frame, even_frame);
return make_pair(odd_frame, even_frame); return make_pair(odd_frame, even_frame);
} }
void utility::detectShape(Ptr<GeneralizedHoughGuil> alg, Mat templateShape, int posThresh, vector<Vec4f> &positivePositions, Mat &positiveVotes, vector<Vec4f> &negativePositions, Mat &negativeVotes, Mat processingArea) { void utility::detectShape(Ptr<GeneralizedHoughGuil> alg, Mat templateShape, int posThresh,
vector<Vec4f>& positivePositions, Mat& positiveVotes, vector<Vec4f>& negativePositions,
alg -> setPosThresh(posThresh); Mat& negativeVotes, Mat processingArea) {
alg -> setTemplate(templateShape); alg->setPosThresh(posThresh);
alg->setTemplate(templateShape);
int oldSizePositive = 0;
int i = 0; int oldSizePositive = 0;
int maxVote = 0; int i = 0;
int maxVote = 0;
// Process shapes with positive angles
alg -> setMinAngle(0); // Process shapes with positive angles
alg -> setMaxAngle(3); alg->setMinAngle(0);
while (true) { alg->setMaxAngle(3);
alg -> detect(processingArea, positivePositions, positiveVotes); while (true) {
int currentSize = positivePositions.size(); alg->detect(processingArea, positivePositions, positiveVotes);
if (currentSize == 1) { int currentSize = positivePositions.size();
// We detected the most interesting shape if (currentSize == 1) {
break; // We detected the most interesting shape
} else if (currentSize == 0 && oldSizePositive > 0) { break;
// It is not possible to detect only one shape with the current parameters } else if (currentSize == 0 && oldSizePositive > 0) {
alg -> setPosThresh(posThresh+i-1); // Decrease position value // It is not possible to detect only one shape with the current
alg -> detect(processingArea, positivePositions, positiveVotes); // Detect all available shapes // parameters
break; alg->setPosThresh(posThresh + i - 1); // Decrease position value
} else if (currentSize == 0 && oldSizePositive == 0) { alg->detect(processingArea, positivePositions,
// Impossible to find with these parameters positiveVotes); // Detect all available shapes
break; break;
} } else if (currentSize == 0 && oldSizePositive == 0) {
oldSizePositive = currentSize; // Impossible to find with these parameters
// Find maximum vote break;
for (int j = 0; j < positiveVotes.cols / 3; j++) { }
if (positiveVotes.at<int>(3*j) > maxVote) oldSizePositive = currentSize;
maxVote = positiveVotes.at<int>(3*j); // Find maximum vote
} for (int j = 0; j < positiveVotes.cols / 3; j++) {
if (positiveVotes.at<int>(3 * j) > maxVote) maxVote = positiveVotes.at<int>(3 * j);
if (currentSize > 10) { }
i += 5; // To speed up computation when there are too many matches
} else if (maxVote - (posThresh + i) > 100) { if (currentSize > 10) {
i += 100; // To speed up computation when there are few super high matches i += 5; // To speed up computation when there are too many matches
} else { } else if (maxVote - (posThresh + i) > 100) {
i++; i += 100; // To speed up computation when there are few super high
} // matches
alg -> setPosThresh(posThresh+i); } else {
} i++;
}
int oldSizeNegative = 0; alg->setPosThresh(posThresh + i);
// Reset incremental position value }
i = 0;
maxVote = 0; int oldSizeNegative = 0;
// Process shapes with negative angles // Reset incremental position value
alg -> setMinAngle(357); i = 0;
alg -> setMaxAngle(360); maxVote = 0;
while (true) { // Process shapes with negative angles
alg -> detect(processingArea, negativePositions, negativeVotes); alg->setMinAngle(357);
int currentSize = negativePositions.size(); alg->setMaxAngle(360);
if (currentSize == 1) { while (true) {
// We detected the most interesting shape alg->detect(processingArea, negativePositions, negativeVotes);
break; int currentSize = negativePositions.size();
} else if (currentSize == 0 && oldSizeNegative > 0) { if (currentSize == 1) {
// It is not possible to detect only one shape with the current parameters // We detected the most interesting shape
alg -> setPosThresh(posThresh+i-1); // Decrease position value break;
alg -> detect(processingArea, negativePositions, negativeVotes); // Detect all available shapes } else if (currentSize == 0 && oldSizeNegative > 0) {
break; // It is not possible to detect only one shape with the current
} else if (currentSize == 0 && oldSizeNegative == 0) { // parameters
// Impossible to found with these parameters alg->setPosThresh(posThresh + i - 1); // Decrease position value
break; alg->detect(processingArea, negativePositions,
} negativeVotes); // Detect all available shapes
oldSizeNegative = currentSize; break;
} else if (currentSize == 0 && oldSizeNegative == 0) {
// Find maximum vote // Impossible to found with these parameters
for (int j = 0; j < positiveVotes.cols / 3; j++) { break;
if (positiveVotes.at<int>(3*j) > maxVote) }
maxVote = positiveVotes.at<int>(3*j); oldSizeNegative = currentSize;
}
// Find maximum vote
if (currentSize > 10) { for (int j = 0; j < positiveVotes.cols / 3; j++) {
i += 5; // To speed up computation when there are too many matches if (positiveVotes.at<int>(3 * j) > maxVote) maxVote = positiveVotes.at<int>(3 * j);
} else if (maxVote - (posThresh + i) > 100) { }
i += 100; // To speed up computation when there are few super high matches
} else { if (currentSize > 10) {
i++; i += 5; // To speed up computation when there are too many matches
} } else if (maxVote - (posThresh + i) > 100) {
alg -> setPosThresh(posThresh+i); i += 100; // To speed up computation when there are few super high
} // matches
} else {
i++;
}
alg->setPosThresh(posThresh + i);
}
} }
RotatedRect utility::drawShapes(Mat frame, Vec4f &positions, Scalar color, int width, int height, int offsetX, int offsetY, float processingScale) { RotatedRect utility::drawShapes(Mat frame, Vec4f& positions, Scalar color, int width, int height, int offsetX,
int offsetY, float processingScale) {
RotatedRect rr; RotatedRect rr;
Point2f rrpts[4]; Point2f rrpts[4];
Point2f pos(positions[0]+offsetX, positions[1]+offsetY); Point2f pos(positions[0] + offsetX, positions[1] + offsetY);
float scale = positions[2]; float scale = positions[2];
float angle = positions[3]; float angle = positions[3];
...@@ -160,21 +163,20 @@ RotatedRect utility::drawShapes(Mat frame, Vec4f &positions, Scalar color, int w ...@@ -160,21 +163,20 @@ RotatedRect utility::drawShapes(Mat frame, Vec4f &positions, Scalar color, int w
return rr; return rr;
} }
void utility::separateFrame(const cv::Mat frame, cv::Mat &odd_frame, cv::Mat &even_frame) { void utility::separateFrame(const cv::Mat frame, cv::Mat& odd_frame, cv::Mat& even_frame) {
int i_odd_frame = 0; int i_odd_frame = 0;
int i_even_frame = 0; int i_even_frame = 0;
for (int i = 0; i < frame.rows; i++) { for (int i = 0; i < frame.rows; i++) {
for (int j = 0; j < frame.cols; j++) { for (int j = 0; j < frame.cols; j++) {
if (i % 2 == 0) { if (i % 2 == 0) {
even_frame.at<cv::Vec3b>( i_even_frame, j )[0] = frame.at<cv::Vec3b>(i, j)[0]; even_frame.at<cv::Vec3b>(i_even_frame, j)[0] = frame.at<cv::Vec3b>(i, j)[0];
even_frame.at<cv::Vec3b>( i_even_frame, j )[1] = frame.at<cv::Vec3b>(i, j)[1]; even_frame.at<cv::Vec3b>(i_even_frame, j)[1] = frame.at<cv::Vec3b>(i, j)[1];
even_frame.at<cv::Vec3b>( i_even_frame, j )[2] = frame.at<cv::Vec3b>(i, j)[2]; even_frame.at<cv::Vec3b>(i_even_frame, j)[2] = frame.at<cv::Vec3b>(i, j)[2];
} else { } else {
odd_frame.at<cv::Vec3b>( i_odd_frame, j )[0] = frame.at<cv::Vec3b>(i, j)[0]; odd_frame.at<cv::Vec3b>(i_odd_frame, j)[0] = frame.at<cv::Vec3b>(i, j)[0];
odd_frame.at<cv::Vec3b>( i_odd_frame, j )[1] = frame.at<cv::Vec3b>(i, j)[1]; odd_frame.at<cv::Vec3b>(i_odd_frame, j)[1] = frame.at<cv::Vec3b>(i, j)[1];
odd_frame.at<cv::Vec3b>( i_odd_frame, j )[2] = frame.at<cv::Vec3b>(i, j)[2]; odd_frame.at<cv::Vec3b>(i_odd_frame, j)[2] = frame.at<cv::Vec3b>(i, j)[2];
} }
} }
...@@ -186,14 +188,15 @@ void utility::separateFrame(const cv::Mat frame, cv::Mat &odd_frame, cv::Mat &ev ...@@ -186,14 +188,15 @@ void utility::separateFrame(const cv::Mat frame, cv::Mat &odd_frame, cv::Mat &ev
} }
return; return;
} }
cv::Mat utility::difference(cv::Mat &prevFrame, cv::Mat &currentFrame) { cv::Mat utility::difference(cv::Mat& prevFrame, cv::Mat& currentFrame) {
cv::Mat diff = currentFrame.clone(); cv::Mat diff = currentFrame.clone();
for (int i = 0; i < currentFrame.rows; i++) { for (int i = 0; i < currentFrame.rows; i++) {
for (int j = 0; j < currentFrame.cols; j++) { for (int j = 0; j < currentFrame.cols; j++) {
if (prevFrame.at<cv::Vec3b>(i, j)[0] != currentFrame.at<cv::Vec3b>(i, j)[0] || prevFrame.at<cv::Vec3b>(i, j)[1] != currentFrame.at<cv::Vec3b>(i, j)[1] || prevFrame.at<cv::Vec3b>(i, j)[2] != currentFrame.at<cv::Vec3b>(i, j)[2]) { if (prevFrame.at<cv::Vec3b>(i, j)[0] != currentFrame.at<cv::Vec3b>(i, j)[0] ||
prevFrame.at<cv::Vec3b>(i, j)[1] != currentFrame.at<cv::Vec3b>(i, j)[1] ||
prevFrame.at<cv::Vec3b>(i, j)[2] != currentFrame.at<cv::Vec3b>(i, j)[2]) {
// Different pixels // Different pixels
diff.at<cv::Vec3b>(i, j)[0] = 0; diff.at<cv::Vec3b>(i, j)[0] = 0;
} else { } else {
...@@ -206,34 +209,20 @@ cv::Mat utility::difference(cv::Mat &prevFrame, cv::Mat &currentFrame) { ...@@ -206,34 +209,20 @@ cv::Mat utility::difference(cv::Mat &prevFrame, cv::Mat &currentFrame) {
} }
SceneObject::SceneObject(int minDist, Threshold threshold) { SceneObject::SceneObject(int minDist, Threshold threshold) {
this->minDist = minDist; this->minDist = minDist;
this->threshold = threshold; this->threshold = threshold;
} }
SceneObject SceneObject::from_file(fs::path path, Object obj) { SceneObject SceneObject::from_file(fs::path path, Object obj) {
ifstream iConfig(path); ifstream iConfig(path);
json j; json j;
iConfig >> j; iConfig >> j;
if (obj == Object::TAPE) { if (obj == Object::TAPE) {
return SceneObject( return SceneObject(j["MinDist"],
j["MinDist"], Threshold{j["TapeThresholdPercentual"], j["AngleThresh"], j["ScaleThresh"], j["PosThresh"]});
Threshold { } else {
j["TapeThresholdPercentual"], return SceneObject(j["MinDistCapstan"], Threshold{j["CapstanThresholdPercentual"], j["AngleThreshCapstan"],
j["AngleThresh"], j["ScaleThreshCapstan"], j["PosThreshCapstan"]});
j["ScaleThresh"], }
j["PosThresh"]
}
);
} else {
return SceneObject(
j["MinDistCapstan"],
Threshold {
j["CapstanThresholdPercentual"],
j["AngleThreshCapstan"],
j["ScaleThreshCapstan"],
j["PosThreshCapstan"]
}
);
}
} }
\ No newline at end of file
...@@ -10,159 +10,173 @@ namespace fs = std::filesystem; ...@@ -10,159 +10,173 @@ namespace fs = std::filesystem;
/** /**
* @brief Namespace containing a set of utility functions used in the project. * @brief Namespace containing a set of utility functions used in the project.
* The functions are mainly used to perform operations on images. * The functions are mainly used to perform operations on images.
* *
*/ */
namespace utility { namespace utility {
/** /**
* @class Frame * @class Frame
* @brief Class that extends the OpenCV Mat class, adding some useful methods frequently used in the project. * @brief Class that extends the OpenCV Mat class, adding some useful methods
* * frequently used in the project.
*/ *
class Frame : public Mat { */
public: class Frame : public Mat {
Frame(); public:
Frame(const Mat& m); Frame();
Frame(const Frame& f); Frame(const Mat& m);
Frame& operator=(const Mat& m); Frame(const Frame& f);
Frame& operator=(const Frame& f); Frame& operator=(const Mat& m);
Frame clone() const; Frame& operator=(const Frame& f);
/** Frame clone() const;
* @brief Downsample the image by a given factor. /**
* * @brief Downsample the image by a given factor.
* @param factor The factor by which the image will be downsampled. *
* @return Frame& The downsampled image. * @param factor The factor by which the image will be downsampled.
*/ * @return Frame& The downsampled image.
Frame& downsample(int factor); */
/** Frame& downsample(int factor);
* @brief Convert the image to a given color space. /**
* * @brief Convert the image to a given color space.
* @param code The code of the color space to which the image will be converted. *
* @return Frame& The converted image. * @param code The code of the color space to which the image will be
*/ * converted.
Frame& convertColor(int code); * @return Frame& The converted image.
Frame difference(Frame& f); */
/** Frame& convertColor(int code);
* @brief Crop the image to a given size, centered in a given point. Frame difference(Frame& f);
* /**
* @param rect_size The size of the cropped image. * @brief Crop the image to a given size, centered in a given point.
* @param center The center of the cropped image. *
* @return Frame& The cropped image. * @param rect_size The size of the cropped image.
*/ * @param center The center of the cropped image.
Frame& crop(Size rect_size, Point2f center); * @return Frame& The cropped image.
/** */
* @brief Warp the image using a given rotation matrix. Frame& crop(Size rect_size, Point2f center);
* /**
* @param rotationMatrix The rotation matrix used to warp the image. * @brief Warp the image using a given rotation matrix.
* @return Frame& The warped image. *
*/ * @param rotationMatrix The rotation matrix used to warp the image.
Frame& warp(cv::Mat rotationMatrix); * @return Frame& The warped image.
/** */
* @brief Deinterlace the image, returning two images, one containing the odd lines and the other containing the even lines. Frame& warp(cv::Mat rotationMatrix);
* /**
* @return std::pair<Frame, Frame> The two images containing the odd and even lines. * @brief Deinterlace the image, returning two images, one containing the
*/ * odd lines and the other containing the even lines.
std::pair<Frame, Frame> deinterlace() const; *
}; * @return std::pair<Frame, Frame> The two images containing the odd and
* even lines.
/** */
* @fn void detectShape(Ptr<GeneralizedHoughGuil> alg, Mat templateShape, int posThresh, vector<Vec4f> &positivePositions, Mat &positiveVotes, vector<Vec4f> &negativePositions, Mat &negativeVotes, Mat processingArea) std::pair<Frame, Frame> deinterlace() const;
* @brief Detects a given shape in an image, using a the OpenCV algorithm GeneralizedHoughGuil. };
*
* @param[in] alg the algorithm instance;
* @param[in] templateShape the shape to detect;
* @param[in] posThresh the position votes threshold;
* @param[out] positivePositions vector representing the position assigned to each found rectangle for positive angles;
* @param[out] positiveVotes vector representing the vote assigned to each found rectangle for positive angles;
* @param[out] negativePositions vector representing the position assigned to each found rectangle for negative angles;
* @param[out] negativeVotes vector representing the vote assigned to each found rectangle for negative angles;
* @param[in] processingArea the image to be processed.
*/
void detectShape(Ptr<GeneralizedHoughGuil> alg, Mat templateShape, int posThresh, vector<Vec4f> &positivePositions, Mat &positiveVotes, vector<Vec4f> &negativePositions, Mat &negativeVotes, Mat processingArea);
/**
* @fn RotatedRect drawShapes(Mat frame, Vec4f &positions, Scalar color, int width, int height, int offsetX, int offsetY, float processingScale)
* @brief Draw rectangles on an image.
*
* @param frame Frame on which the rectangles will be drawn;
* @param positions The position of the rectangle;
* @param color The color of the rectangle;
* @param width The width of the rectangle;
* @param height The height of the rectangle;
* @param offsetX X offset on the position of the rectangle;
* @param offsetY Y offset on the position of the rectangle;
* @param processingScale Scaling factor, useful for downsizing.
* @return RotatedRect Object representing the drawn rectangle.
*/
RotatedRect drawShapes(Mat frame, Vec4f &positions, Scalar color, int width, int height, int offsetX, int offsetY, float processingScale);
/**
* @fn void detectShape(Ptr<GeneralizedHoughGuil> alg, Mat templateShape, int
* posThresh, vector<Vec4f> &positivePositions, Mat &positiveVotes,
* vector<Vec4f> &negativePositions, Mat &negativeVotes, Mat processingArea)
* @brief Detects a given shape in an image, using a the OpenCV algorithm
* GeneralizedHoughGuil.
*
* @param[in] alg the algorithm instance;
* @param[in] templateShape the shape to detect;
* @param[in] posThresh the position votes threshold;
* @param[out] positivePositions vector representing the position assigned to
* each found rectangle for positive angles;
* @param[out] positiveVotes vector representing the vote assigned to each found
* rectangle for positive angles;
* @param[out] negativePositions vector representing the position assigned to
* each found rectangle for negative angles;
* @param[out] negativeVotes vector representing the vote assigned to each found
* rectangle for negative angles;
* @param[in] processingArea the image to be processed.
*/
void detectShape(Ptr<GeneralizedHoughGuil> alg, Mat templateShape, int posThresh, vector<Vec4f>& positivePositions,
Mat& positiveVotes, vector<Vec4f>& negativePositions, Mat& negativeVotes, Mat processingArea);
/** /**
* @fn void separateFrame(cv::Mat frame, cv::Mat &odd_frame, cv::Mat &even_frame) * @fn RotatedRect drawShapes(Mat frame, Vec4f &positions, Scalar color, int
* @brief Function to deinterlace the current image. * width, int height, int offsetX, int offsetY, float processingScale)
* * @brief Draw rectangles on an image.
* @param[in] frame image to be processed; *
* @param[out] odd_frame odd plane; * @param frame Frame on which the rectangles will be drawn;
* @param[out] even_frame even plane. * @param positions The position of the rectangle;
*/ * @param color The color of the rectangle;
void separateFrame(const cv::Mat frame, cv::Mat &odd_frame, cv::Mat &even_frame); * @param width The width of the rectangle;
* @param height The height of the rectangle;
* @param offsetX X offset on the position of the rectangle;
* @param offsetY Y offset on the position of the rectangle;
* @param processingScale Scaling factor, useful for downsizing.
* @return RotatedRect Object representing the drawn rectangle.
*/
RotatedRect drawShapes(Mat frame, Vec4f& positions, Scalar color, int width, int height, int offsetX, int offsetY,
float processingScale);
/**
* @fn void separateFrame(cv::Mat frame, cv::Mat &odd_frame, cv::Mat
* &even_frame)
* @brief Function to deinterlace the current image.
*
* @param[in] frame image to be processed;
* @param[out] odd_frame odd plane;
* @param[out] even_frame even plane.
*/
void separateFrame(const cv::Mat frame, cv::Mat& odd_frame, cv::Mat& even_frame);
/** /**
* @fn void separateFrame(cv::Mat frame, cv::Mat &odd_frame, cv::Mat &even_frame) * @fn void separateFrame(cv::Mat frame, cv::Mat &odd_frame, cv::Mat
* @brief Compute the number of different pixels between two frames. * &even_frame)
* * @brief Compute the number of different pixels between two frames.
* @param prevFrame the first frame; *
* @param currentFrame the second frame. * @param prevFrame the first frame;
* @return cv::Mat A black and white frame, where black pixels represent a difference, while white pixels represent an equality. * @param currentFrame the second frame.
*/ * @return cv::Mat A black and white frame, where black pixels represent a
cv::Mat difference(cv::Mat &prevFrame, cv::Mat &currentFrame); * difference, while white pixels represent an equality.
} */
cv::Mat difference(cv::Mat& prevFrame, cv::Mat& currentFrame);
} // namespace utility
/** /**
* @struct Threshold * @struct Threshold
* @brief Struct containing the threshold values used to detect a shape. * @brief Struct containing the threshold values used to detect a shape.
* *
*/ */
struct Threshold { struct Threshold {
/** float percentual; /**< The minimum percentage of different pixels for
* considering the current frame under the ROI as a
*/ potential Irregularity */
float percentual; /**< The minimum percentage of different pixels for considering the current frame under the ROI as a potential Irregularity */ int angle; /**< The angle votes threshold for the detection of the object */
int angle; /**< The angle votes threshold for the detection of the object */ int scale; /**< The scale votes threshold for the detection of the object */
int scale; /**< The scale votes threshold for the detection of the object */ int pos; /**< The position votes threshold for the detection of the object
int pos; /**< The position votes threshold for the detection of the object */ */
}; };
/** /**
* @enum Object * @enum Object
* @brief Enum containing the possible objects to detect. * @brief Enum containing the possible objects to detect.
* *
*/ */
enum Object { enum Object { TAPE, CAPSTAN };
TAPE,
CAPSTAN
};
/** /**
* @struct SceneObject * @struct SceneObject
* @brief A scene object is an object that can be detected in a scene, such as a tape or a capstan. * @brief A scene object is an object that can be detected in a scene, such as a
* tape or a capstan.
* *
*/ */
struct SceneObject { struct SceneObject {
int minDist; /**< The minimum distance between the centers of the detected objects for the detection of the reading head */ int minDist; /**< The minimum distance between the centers of the detected
Threshold threshold; /**< the threshold values used to detect the object */ objects for the detection of the reading head */
Threshold threshold; /**< the threshold values used to detect the object */
SceneObject(int minDist, Threshold threshold); SceneObject(int minDist, Threshold threshold);
~SceneObject() = default; ~SceneObject() = default;
/** /**
* @fn static SceneObject from_file(fs::path path, Object obj) * @fn static SceneObject from_file(fs::path path, Object obj)
* @brief Create a SceneObject from a given file. * @brief Create a SceneObject from a given file.
* *
* @param path The path of the file containing the object. * @param path The path of the file containing the object.
* @note The file must be a JSON file. * @note The file must be a JSON file.
* @param obj The object to detect. * @param obj The object to detect.
* @return SceneObject The SceneObject created from the file. * @return SceneObject The SceneObject created from the file.
*/ */
static SceneObject from_file(fs::path path, Object obj); static SceneObject from_file(fs::path path, Object obj);
}; };
#include "../src/lib/enums.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_generators.hpp>
#include "../src/lib/enums.h"
TEST(IrregularityType, toString) { TEST(IrregularityType, toString) { EXPECT_EQ(irregularityTypeToString(IrregularityType::WOW_AND_FLUTTER), "wf"); }
EXPECT_EQ(irregularityTypeToString(IrregularityType::WOW_AND_FLUTTER), "wf");
}
TEST(IrregularityType, fromString) { TEST(IrregularityType, fromString) {
EXPECT_EQ(irregularityTypeFromString("wf"), IrregularityType::WOW_AND_FLUTTER); EXPECT_EQ(irregularityTypeFromString("wf"), IrregularityType::WOW_AND_FLUTTER);
......
#include "../src/lib/Irregularity.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_generators.hpp>
#include "../src/lib/Irregularity.h"
TEST(Irregularity, Init) { TEST(Irregularity, Init) {
Irregularity irreg = Irregularity( Irregularity irreg =
Source::Video, Irregularity(Source::Video, "00:00:00.000", IrregularityType::WOW_AND_FLUTTER, "https://example.com/image.png");
"00:00:00.000",
IrregularityType::WOW_AND_FLUTTER,
"https://example.com/image.png"
);
Irregularity irreg2 = Irregularity( Irregularity irreg2 =
Source::Video, Irregularity(Source::Video, "00:00:00.000", IrregularityType::WOW_AND_FLUTTER, "https://example.com/image.png");
"00:00:00.000",
IrregularityType::WOW_AND_FLUTTER,
"https://example.com/image.png"
);
EXPECT_NE(irreg.id, irreg2.id); EXPECT_NE(irreg.id, irreg2.id);
EXPECT_EQ(irreg.source, irreg2.source); EXPECT_EQ(irreg.source, irreg2.source);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment