diff --git a/.gitignore b/.gitignore index 46dc307..5edb2a7 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,3 @@ cmake-build-debug/ build/ -output_detection/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 11f5579..edebabd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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} diff --git a/Dataset/other_videos_not_deliver/video1_1024_576.mp4 b/Dataset/other_videos_not_deliver/video1_1024_576.mp4 deleted file mode 100644 index 44b12a0..0000000 Binary files a/Dataset/other_videos_not_deliver/video1_1024_576.mp4 and /dev/null differ diff --git a/Dataset/other_videos_not_deliver/video1_1726_1080.mp4 b/Dataset/other_videos_not_deliver/video1_1726_1080.mp4 deleted file mode 100644 index 957425a..0000000 Binary files a/Dataset/other_videos_not_deliver/video1_1726_1080.mp4 and /dev/null differ diff --git a/Dataset/other_videos_not_deliver/video1_768_580.mp4 b/Dataset/other_videos_not_deliver/video1_768_580.mp4 deleted file mode 100644 index 17786ac..0000000 Binary files a/Dataset/other_videos_not_deliver/video1_768_580.mp4 and /dev/null differ diff --git a/Dataset/other_videos_not_deliver/video2_1024_576.mp4 b/Dataset/other_videos_not_deliver/video2_1024_576.mp4 deleted file mode 100644 index fd23f2d..0000000 Binary files a/Dataset/other_videos_not_deliver/video2_1024_576.mp4 and /dev/null differ diff --git a/Dataset/other_videos_not_deliver/video2_1920_1080.mp4 b/Dataset/other_videos_not_deliver/video2_1920_1080.mp4 deleted file mode 100644 index e28cd0f..0000000 Binary files a/Dataset/other_videos_not_deliver/video2_1920_1080.mp4 and /dev/null differ diff --git a/src/main.cpp b/src/main.cpp index 14e04ff..4f6d7b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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. */ @@ -44,12 +42,11 @@ int main(int argc, char* argv[]){ vector 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; @@ -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 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 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()); diff --git a/src/tableOrientation.cpp b/src/tableOrientation.cpp index 194ccd8..5f3c11d 100644 --- a/src/tableOrientation.cpp +++ b/src/tableOrientation.cpp @@ -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"); diff --git a/src/tracking.cpp b/src/tracking.cpp index 97c2ae6..3cd6324 100644 --- a/src/tracking.cpp +++ b/src/tracking.cpp @@ -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; diff --git a/src/transformation.cpp b/src/transformation.cpp index b1e6e65..6e7d4c7 100644 --- a/src/transformation.cpp +++ b/src/transformation.cpp @@ -92,8 +92,7 @@ Mat computeTransformation(const Mat& img, Vec &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> balls) { +Mat drawMinimap(Mat &minimap_with_track, const Mat &transform, Ptr> balls) { if(minimap_with_track.empty()) throw invalid_argument("Empty image in input");