From f6de3ef2fb5dc03c4b554747695d4039646b1432 Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm Date: Wed, 23 Jul 2025 18:09:20 +0200 Subject: [PATCH] inial commit --- CMakeLists.txt | 11 +++ main.cpp | 196 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c43ced8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.4) +project(millingscanner) + + +add_executable(millingscanner main.cpp ) + +target_link_libraries( millingscanner -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_aruco -lopencv_bgsegm -lopencv_calib3d -lopencv_ccalib -lopencv_datasets -lopencv_dnn -lopencv_dpm -lopencv_features2d -lopencv_flann -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_imgcodecs -lopencv_imgproc -lopencv_video -lopencv_videoio -lopencv_stitching -lomp) +set_target_properties( millingscanner PROPERTIES COMPILE_FLAGS -m64 LINK_FLAGS -m64) +add_definitions(" -fopenmp -s -std=c++11 -Wall") + +install(TARGETS millingscanner RUNTIME DESTINATION bin) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..c4cdc84 --- /dev/null +++ b/main.cpp @@ -0,0 +1,196 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +class Config +{ +public: + std::vector inputImages; + std::string maskFileName = ""; + std::string outputFileName = "out.xyz"; + float scaleX = 0.01; + float scaleY = 0.01; + float scaleZ = 0.3; +}; + +void cd_to_exe_dir( char *argv[] ) +{ + std::string path = argv[0]; + int ii = path.length(); + while ( !( path[ii] == '/' || path[ii] == '\\' ) && ii > 0 ) + { + ii--; + } + path.erase( ii, 100 ); + chdir( path.c_str() ); +} + +static void printUsage() +{ + std::cout<<"scannassembler --output outImage inImage\n"; +} + +static int parseCmdArgs(int argc, char** argv, Config *config) +{ + if (argc == 1) + { + printUsage(); + return -1; + } + for (int i = 1; i < argc; i++) + { + if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") + { + printUsage(); + return -1; + } + else if (std::string(argv[i]) == "--output" || std::string(argv[i]) == "-o") + { + i++; + if(argc > i) config->outputFileName = argv[i]; + else return -1; + } + else if (std::string(argv[i]) == "--mask" || std::string(argv[i]) == "-m") + { + i++; + if(argc > i) config->maskFileName = argv[i]; + else return -1; + } + else if (std::string(argv[i]) == "--scale" || std::string(argv[i]) == "-s") + { + if(argc > i+3) + { + config->scaleX = atof(argv[i+1]); + config->scaleY = atof(argv[i+2]); + config->scaleZ = atof(argv[i+3]); + i+=3; + } + else return -1; + } + else if (std::string(argv[i]) == "--mask" || std::string(argv[i]) == "-m") + { + i++; + if(argc > i) config->maskFileName = argv[i]; + else return -1; + } + else config->inputImages.push_back(argv[i]); + } + return 0; +} + +void showImages(std::vector images) +{ + cv::namedWindow( "Viewer", cv::WINDOW_AUTOSIZE ); + for(uint i = 0; i< images.size(); i++) + { + cv::imshow( "Viewer", images[i] ); + cv::waitKey(0); + } + cv::destroyWindow("Viewer"); +} + +void showImages(std::vector images) +{ + cv::namedWindow( "Viewer", cv::WINDOW_AUTOSIZE ); + for(uint i = 0; i< images.size(); i++) + { + cv::imshow( "Viewer", images[i] ); + cv::waitKey(0); + } + cv::destroyWindow("Viewer"); +} + +void showImages(cv::Mat image) +{ + cv::namedWindow( "Viewer", cv::WINDOW_AUTOSIZE ); + cv::imshow( "Viewer", image ); + cv::waitKey(0); + cv::destroyWindow("Viewer"); +} + + + +std::vector loadImages(std::vector fileNames) +{ + std::vector images; + for(uint i = 0; i < fileNames.size(); i++) + { + cv::Mat tmpImage = cv::imread(fileNames[i]); + if(tmpImage.data)images.push_back(tmpImage); + else + { + std::cout<<"can not read image "<(x,y)) outputFile<