commit 0812c3cb97843e4a18c375139ebf0b797fa5c876 Author: Carl Philipp Klemm Date: Tue Jan 17 14:01:49 2023 +0100 inital commit diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5938004 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.0) + +project(imagetournament) + +set(SRC_FILES main.cpp) + +set(RESOURCE_LOCATION data) + +find_package(OpenCV REQUIRED) +find_package(PkgConfig REQUIRED) +pkg_check_modules(POPPLER REQUIRED poppler-cpp) + +link_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(${PROJECT_NAME} ${SRC_FILES} main.cpp) +target_link_libraries( ${PROJECT_NAME} pthread ${OpenCV_LIBS}) +target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS}) +add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}) +target_compile_options(${PROJECT_NAME} PRIVATE "-std=c++2a" "-Wall" "-O2" "-g" "-fno-strict-aliasing" "-Wfatal-errors" "-Wno-reorder") + +set(CMAKE_INSTALL_PREFIX "/usr") +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..bb7047e --- /dev/null +++ b/main.cpp @@ -0,0 +1,139 @@ +#include +#include +#include + +static constexpr char OUTPUT_DIR[] = "./out"; + +static bool extensionMatches(const std::filesystem::path& path) +{ + std::string extension = path.extension(); + if(extension == ".png") + return true; + if(extension == ".PNG") + return true; + if(extension == ".jpg") + return true; + if(extension == ".JPG") + return true; + if(extension == ".jpeg") + return true; + return false; +} + +int main(int argc, char** argv) +{ + if(argc < 2) + { + std::cout<<"a directory must be specified\n"; + return 1; + } + + std::cout<<"Using folder "< images; + const std::filesystem::path directoryPath{argv[1]}; + for(const std::filesystem::directory_entry& dirent : std::filesystem::directory_iterator{directoryPath}) + { + std::string fileName = dirent.path().filename(); + if(dirent.is_regular_file() && extensionMatches(dirent.path())) + { + std::cout<<"Found: "<> rounds; + + while(images.size() > 1) + { + std::cout<<"New round "<()); + std::vector removeIndexies; + for(size_t i = 0; i < images.size()-1; i+=2) + { + cv::Mat imageA = cv::imread(images[i]); + cv::Mat imageB = cv::imread(images[i+1]); + + if(!imageA.data || !imageB.data) + { + std::cout<<"Images: "<= 0; --i) + { + rounds.back().push_back(images[removeIndexies[i]]); + images.erase(images.begin()+removeIndexies[i]); + } + } + + + for(size_t round = 0; round < rounds.size(); ++round) + { + std::string roundDirName = std::string("round_") + std::to_string(round); + if(!std::filesystem::is_directory(outDirPath/roundDirName) && !std::filesystem::create_directory(outDirPath/roundDirName)) + { + std::cout<<"Could not create or read "<