Skip to content

Commit

Permalink
Solved todo
Browse files Browse the repository at this point in the history
  • Loading branch information
Sproc01 committed Jul 20, 2024
1 parent 38ca62e commit f0f6476
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 25 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@

cmake-build-debug/
build/
output_detection/*
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 17)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS} include/)
include_directories(${OpenCV_INCLUDE_DIRS} include/ img/)

add_library(Ball include/ball.h src/ball.cpp)
add_library(Table include/table.h src/table.cpp)
Expand All @@ -17,7 +17,7 @@ add_library(TableOrientation include/tableOrientation.h src/tableOrientation.cpp
add_library(Transformation include/transformation.h src/transformation.cpp)
add_library(Tracking include/tracking.h src/tracking.cpp)
add_library(Metrics include/metrics.h src/metrics.cpp)
add_library(Utils include/category.h include/minimapConstants.h include/util.h src/util_first.cpp src/util_second.cpp)
add_library(Utils include/category.h include/minimapConstants.h include/util.h src/util_first.cpp src/util_second.cpp img/minimap.h)

target_link_libraries(Ball
${OpenCV_LIBS}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file removed Dataset/other_videos_not_deliver/video1_768_580.mp4
Binary file not shown.
Binary file removed Dataset/other_videos_not_deliver/video2_1024_576.mp4
Binary file not shown.
Binary file not shown.
19 changes: 8 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ using namespace std;
using namespace cv;
using namespace chrono;

//TODO: remove folders Dataset/other_videos and output_detection

/* Given a video it detects table and balls in the first frame and track the balls over different frame.
Using this information then it creates the output video with a minimap superimposed and then detect the balls
in the last frame. For the detection of the table and of the balls it computes also some performance metrics. */
Expand All @@ -44,12 +42,11 @@ int main(int argc, char* argv[]){
vector<double> metricsIoU;

//INPUT
// TODO rotate image if vertical; resize to be inscribed in current sizes, centered in the Mat; use this to calculate minimap; write to video file the original unrotated, unscaled image with the calculated image superimposed
if (argc == 2){
videoPath = filesystem::path(argv[1]);
}
else if (argc == 1) { //TODO: remove at the end
videoPath = filesystem::path("../Dataset/game2_clip1/game2_clip1.mp4");
videoPath = filesystem::path("../Dataset/game1_clip1/game1_clip1.mp4");
}
else {
cout << "Error of number of parameters: insert one parameter" << endl;
Expand Down Expand Up @@ -104,14 +101,14 @@ int main(int argc, char* argv[]){
table.setBoundaries(img_corners);

//MINIMAP
Mat minimap = imread(MINIMAP_PATH);
Mat minimap_with_track = minimap.clone();
Mat minimap_with_balls = minimap.clone();
//TODO use minimap.h
// vector<unsigned char> minimapVec(MINIMAP_DATA, MINIMAP_DATA + MINIMAP_DATA_SIZE);
// Mat minimap = imdecode(minimapVec, cv::IMREAD_UNCHANGED);
// The original is the png provided but we converted it to an header
// Mat minimap = imread(MINIMAP_PATH);
// imshow("minimap", minimap);
// Mat minimap_with_track = minimap.clone();
// Mat minimap_with_balls = minimap.clone();
vector<unsigned char> minimapVec(MINIMAP_DATA, MINIMAP_DATA + MINIMAP_DATA_SIZE);
Mat minimap = imdecode(minimapVec, cv::IMREAD_UNCHANGED);
Mat minimap = imread(MINIMAP_PATH);
imshow("minimap", minimap);

Mat transform = table.getTransform();
minimap_with_balls = drawMinimap(minimap_with_track, transform, table.ballsPtr());
Expand Down
2 changes: 1 addition & 1 deletion src/tableOrientation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool compareByPercentile(const Edge &e1, const Edge &e2)
* @throw invalid_argument if the rect in input is empty
*/
double computeTablePercentile(const Mat &mask_img, const Rect &rect) {
//TODO: check mask_img and colors

if(mask_img.empty())
throw invalid_argument("Empty image in input");

Expand Down
17 changes: 9 additions & 8 deletions src/tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ Rect BallTracker::trackOne(unsigned short ballIndex, const Mat &frame, bool call
ballsVec_->at(ballIndex).setBbox_prec(bbox);

bool isBboxUpdated = false;
// TODO check if ball is visible
if (callInit) {
enlargeRect(bbox, 10); // enlarge bbox to enhance tracking performance
ballTrackers_[ballIndex]->init(frame, bbox);
} else {
isBboxUpdated = ballTrackers_[ballIndex]->update(frame, bbox);
const float IOU_THRESHOLD = 0.9; // TODO tune IoU threshold for updating ball position
if (isBboxUpdated && IoU(ballsVec_->at(ballIndex).getBbox_prec(), bbox) > IOU_THRESHOLD) { // if IoU is too high, do not update: the shift is not significant
isBboxUpdated = false;
// TODO check if not updating the bbox makes the tracker lose the ball
} else {
ballsVec_->at(ballIndex).setBbox(bbox); // do not update if shift is too little (use IoU)
if(ballsVec_->at(ballIndex).getVisibility())
{
isBboxUpdated = ballTrackers_[ballIndex]->update(frame, bbox);
const float IOU_THRESHOLD = 0.9; // TODO tune IoU threshold for updating ball position
if (isBboxUpdated && IoU(ballsVec_->at(ballIndex).getBbox_prec(), bbox) > IOU_THRESHOLD) { // if IoU is too high, do not update: the shift is not significant
isBboxUpdated = false;
} else {
ballsVec_->at(ballIndex).setBbox(bbox); // do not update if shift is too little (use IoU)
}
}
}
//std::cout<< "Ball " << ballIndex << " updated? " << isBboxUpdated << " current bbox: " << bbox << std::endl;
Expand Down
3 changes: 1 addition & 2 deletions src/transformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ Mat computeTransformation(const Mat& img, Vec<Point2f, 4> &img_corners) {
* @throw invalid_argument if the transformation matrix in input is empty
* @throw invalid_argument if the balls pointer is a null pointer
*/
//TODO: const ptr?
Mat drawMinimap(Mat &minimap_with_track, const Mat &transform, const Ptr<vector<Ball>> balls) {
Mat drawMinimap(Mat &minimap_with_track, const Mat &transform, Ptr<vector<Ball>> balls) {
if(minimap_with_track.empty())
throw invalid_argument("Empty image in input");

Expand Down

0 comments on commit f0f6476

Please sign in to comment.