Skip to content

Commit

Permalink
const and references, and some indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
albertopasqualetto committed Jul 9, 2024
1 parent bd77933 commit b2e13e0
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 59 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Dataset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 22 additions & 20 deletions include/ball.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
// Author: Michela Schibuola

#ifndef BALL_H
#define BALL_H

#include <opencv2/core/types.hpp>
#include <opencv2/core/matx.hpp>
#include <opencv2/core/mat.hpp>
#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
2 changes: 1 addition & 1 deletion include/detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "ball.h"
#include "table.h"

void detectTable(const cv::Mat &frame, cv::Vec<cv::Point2f, 4> &tableCorners, cv::Vec2b &colorTable);
void detectTable(const cv::Mat &frame, cv::Vec<cv::Point2f, 4> &corners, cv::Vec2b &colorRange);
Category classifyBall(const cv::Mat& img, double radius);
void detectBalls(const cv::Mat &frame, std::vector<Ball> &balls, const cv::Vec<cv::Point2f, 4> &tableCorners, const cv::Scalar &colorTable);

Expand Down
2 changes: 1 addition & 1 deletion include/minimapConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/util.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Author:
// Author:

#ifndef UTIL_H
#define UTIL_H
Expand All @@ -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
51 changes: 22 additions & 29 deletions src/ball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -190,5 +190,6 @@ int main(int argc, char* argv[]){
// // // TODO work on last frame

// waitKey(0);
// return 0;

return 0;
}
2 changes: 2 additions & 0 deletions src/segmentation.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Author:

#include <opencv2/opencv.hpp>
#include <iostream>

Expand Down
3 changes: 1 addition & 2 deletions src/testTrackingInteractive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>

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;
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b2e13e0

Please sign in to comment.