diff --git a/.editorconfig b/.editorconfig index 534ab4f..0275d55 100644 --- a/.editorconfig +++ b/.editorconfig @@ -329,3 +329,12 @@ ij_cmake_spaces_within_if_parentheses = false ij_cmake_spaces_within_method_call_parentheses = false ij_cmake_spaces_within_method_parentheses = false ij_cmake_spaces_within_while_parentheses = false + + +[.editorconfig] +ij_editorconfig_align_group_field_declarations = false +ij_editorconfig_space_after_colon = false +ij_editorconfig_space_after_comma = true +ij_editorconfig_space_before_colon = false +ij_editorconfig_space_before_comma = false +ij_editorconfig_spaces_around_assignment_operators = true \ No newline at end of file diff --git a/Dataset/README.md b/Dataset/README.md index 3ebcae7..67ca682 100644 --- a/Dataset/README.md +++ b/Dataset/README.md @@ -33,7 +33,7 @@ The frames corresponding to the initial and final status of the game have been a - Segmentation masks are provided as grayscale mask where each pixel is assigned the corresponding category ID (background, white cu ball, black 8-ball, solid color, striped and playing field). -Note that segmentation masks can be easily visualized as color images highlighting the different categories by mapping each category ID in a segmentation mask to a RGB color, for example: +Note that segmentation masks can be easily visualized as color images highlighting the different categories by mapping each category ID in a segmentation mask to an RGB color, for example: 0: (128,128,128) 1: (255, 255, 255) diff --git a/include/ball.h b/include/ball.h index 4ba9841..a208a99 100644 --- a/include/ball.h +++ b/include/ball.h @@ -1,33 +1,35 @@ // Author: Michela Schibuola +#ifndef BALL_H +#define BALL_H + #include #include #include #include "category.h" -#ifndef BALL_H -#define BALL_H - -class Ball -{ - cv::Rect bbox_; - Category category_; - cv::Rect bbox_prec_; +class Ball { + cv::Rect bbox_; + Category category_; + cv::Rect bbox_prec_; -public: - Ball(cv::Rect bbox, Category category, cv::Rect bbox_prec) : bbox_(bbox), category_(category), bbox_prec_(bbox_prec) {} - //TODO: bbox_prec = -1, -1 for first frame? - Ball(cv::Rect bbox, Category category) : bbox_(bbox), category_(category), bbox_prec_(cv::Rect(-1, -1, 0, 0)) {} + public: + Ball(cv::Rect bbox, Category category, cv::Rect bbox_prec) : bbox_(bbox), category_(category), + bbox_prec_(bbox_prec) { + } + //TODO: bbox_prec = -1, -1 for first frame? + Ball(cv::Rect bbox, Category category) : bbox_(bbox), category_(category), bbox_prec_(cv::Rect(-1, -1, 0, 0)) { + } - cv::Rect getBbox() const; - Category getCategory() const; - cv::Rect getBbox_prec() const; - cv::Point2f getBBoxCenter(); - cv::Point2f getBboxCenter_prec(); + cv::Rect getBbox() const; + Category getCategory() const; + cv::Rect getBbox_prec() const; + cv::Point2f getBBoxCenter() const; + cv::Point2f getBboxCenter_prec() const; - void setBbox(cv::Rect bbox); - void setCategory(Category category); - void setBbox_prec(cv::Rect bbox_prec); + void setBbox(cv::Rect bbox); + void setCategory(Category category); + void setBbox_prec(cv::Rect bbox_prec); }; #endif // BALL_H diff --git a/include/detection.h b/include/detection.h index ca0bb4d..8a69665 100644 --- a/include/detection.h +++ b/include/detection.h @@ -7,7 +7,7 @@ #include "ball.h" #include "table.h" -void detectTable(const cv::Mat &frame, cv::Vec &tableCorners, cv::Vec2b &colorTable); +void detectTable(const cv::Mat &frame, cv::Vec &corners, cv::Vec2b &colorRange); Category classifyBall(const cv::Mat& img, double radius); void detectBalls(const cv::Mat &frame, std::vector &balls, const cv::Vec &tableCorners, const cv::Scalar &colorTable); diff --git a/include/minimapConstants.h b/include/minimapConstants.h index ec615a8..a68f285 100644 --- a/include/minimapConstants.h +++ b/include/minimapConstants.h @@ -21,7 +21,7 @@ const double MAP_BALL_RADIUS = 12.6; //colors for the balls in the minimap const cv::Vec3b BACKGROUND_BGR_COLOR = cv::Vec3b(0, 0, 0); // black -const cv::Vec3b WHITE_BGR_COLOR = cv::Vec3b(255, 255, 255); // white +const cv::Vec3b WHITE_BGR_COLOR = cv::Vec3b(255, 255, 255); // white const cv::Vec3b BLACK_BGR_COLOR = cv::Vec3b(100, 100, 100); // gray const cv::Vec3b SOLID_BGR_COLOR = cv::Vec3b(0, 0, 255); // red const cv::Vec3b STRIPED_BGR_COLOR = cv::Vec3b(255, 0, 0); // blue diff --git a/include/util.h b/include/util.h index 353fc9e..1d9f4ef 100644 --- a/include/util.h +++ b/include/util.h @@ -1,4 +1,4 @@ -//Author: +// Author: #ifndef UTIL_H #define UTIL_H @@ -13,6 +13,6 @@ cv::Vec2b mostFrequentColor(const cv::Mat &img); void computeIntersection(const cv::Vec3f &line1, const cv::Vec3f &line2, cv::Point2f &intersection); void equationFormula(float x1, float y1, float x2, float y2, float &a, float &b, float &c); void createOutputImage(const cv::Mat& frame, const cv::Mat& minimap_with_balls, cv::Mat& res); -void kMeansClustering(const cv::Mat inputImage, cv::Mat& clusteredImage, int clusterCount); +void kMeansClustering(const cv::Mat &inputImage, cv::Mat& clusteredImage, int clusterCount); #endif //UTIL_H diff --git a/src/ball.cpp b/src/ball.cpp index 3b389cc..20a93d4 100644 --- a/src/ball.cpp +++ b/src/ball.cpp @@ -8,50 +8,43 @@ using namespace cv; -Rect Ball::getBbox() const -{ - if (bbox_.empty()) - throw std::runtime_error("bbox is uninitialized"); +Rect Ball::getBbox() const { + if (bbox_.empty()) + throw std::runtime_error("bbox is uninitialized"); - return bbox_; + return bbox_; } -Category Ball::getCategory() const -{ - if (category_ == 0) - throw std::runtime_error("category is uninitialized"); +Category Ball::getCategory() const { + if (category_ == 0) + throw std::runtime_error("category is uninitialized"); - return category_; + return category_; } -Rect Ball::getBbox_prec() const -{ - if (bbox_prec_.empty()) - throw std::runtime_error("bbox_prec is uninitialized"); +Rect Ball::getBbox_prec() const { + if (bbox_prec_.empty()) + throw std::runtime_error("bbox_prec is uninitialized"); - return bbox_prec_; + return bbox_prec_; } -void Ball::setBbox(Rect bbox) -{ - bbox_ = bbox; +void Ball::setBbox(Rect bbox) { + bbox_ = bbox; } -void Ball::setCategory(Category category) -{ - category_ = category; +void Ball::setCategory(Category category) { + category_ = category; } -void Ball::setBbox_prec(Rect bbox_prec) -{ - bbox_prec_ = bbox_prec; +void Ball::setBbox_prec(Rect bbox_prec) { + bbox_prec_ = bbox_prec; } -Point2f Ball::getBBoxCenter() { - return Point(bbox_.x + bbox_.width/2, bbox_.y + bbox_.height/2); +Point2f Ball::getBBoxCenter() const { + return Point(bbox_.x + bbox_.width / 2, bbox_.y + bbox_.height / 2); } -Point2f Ball::getBboxCenter_prec() -{ - return Point(bbox_prec_.x + bbox_prec_.width/2, bbox_prec_.y + bbox_prec_.height/2); +Point2f Ball::getBboxCenter_prec() const { + return Point(bbox_prec_.x + bbox_prec_.width / 2, bbox_prec_.y + bbox_prec_.height / 2); } diff --git a/src/main.cpp b/src/main.cpp index f9932b7..7b008fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,7 +89,7 @@ int main(int argc, char* argv[]){ VideoWriter vidOutput = VideoWriter(); double fps = vid.get(CAP_PROP_FPS); //TODO: remove the video if some error occour, or if the execution is closed before end (it is corrupted) - vidOutput.open(pathOutput, codec, fps, frame.size(), 1); + vidOutput.open(pathOutput, codec, fps, frame.size(), true); //DETECT AND SEGMENT TABLE detectTable(frame, tableCorners, colorTable); @@ -190,5 +190,6 @@ int main(int argc, char* argv[]){ // // // TODO work on last frame // waitKey(0); -// return 0; + + return 0; } diff --git a/src/segmentation.cpp b/src/segmentation.cpp index 42c5082..8618a5b 100644 --- a/src/segmentation.cpp +++ b/src/segmentation.cpp @@ -1,3 +1,5 @@ +// Author: + #include #include diff --git a/src/testTrackingInteractive.cpp b/src/testTrackingInteractive.cpp index 89866cc..2f422a3 100644 --- a/src/testTrackingInteractive.cpp +++ b/src/testTrackingInteractive.cpp @@ -2,12 +2,11 @@ #include #include #include -#include using namespace std; using namespace cv; -int main( int argc, char** argv ){ +int main(){ VideoCapture cap("../Dataset/game1_clip1/game1_clip1.mp4"); Rect roi; Mat frame; diff --git a/src/util.cpp b/src/util.cpp index cbeacd3..cd41f23 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -120,7 +120,7 @@ void createOutputImage(const Mat& frame, const Mat& minimap_with_balls, Mat& res } -void kMeansClustering(const Mat inputImage, Mat& clusteredImage, int clusterCount) +void kMeansClustering(const Mat &inputImage, Mat& clusteredImage, int clusterCount) { Mat blurred, samples, labels; int attempts = 10;