diff --git a/.gitignore b/.gitignore index a95be5d02605031165d4f5fa4147275dc4b5630d..1a54ff15872b407e5553633e46c6055b775c10dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ */build */node_modules -*/include/ftl/config.h +**/include/ftl/config.h +**/src/config.cpp **/*.blend1 fabric/ fabric-js/ diff --git a/CMakeLists.txt b/CMakeLists.txt index a7a01fb96a7b562e29bd590b2a9e20b15d3f1631..f30fecaf969bf3ef3e671f7879070cf0139273f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,8 @@ find_package( OpenCV REQUIRED ) find_package( Threads REQUIRED ) find_package( LibSGM ) +include_directories(${PROJECT_SOURCE_DIR}/common/cpp/include) + check_language(CUDA) if (CUDA_FOUND) enable_language(CUDA) @@ -31,10 +33,10 @@ include(git_version) if (WIN32) file(TO_CMAKE_PATH "$ENV{USERPROFILE}" ENV_USERPROFILE) - set(FTL_CONFIG_ROOT "\"${ENV_USERPROFILE}/AppData/ftl\"") - message(STATUS "Config root is ${FTL_CONFIG_ROOT}") - set(FTL_CACHE_ROOT "\"$ENV{USERPROFILE}/AppData/ftl\"") - set(FTL_DATA_ROOT "\"$ENV{USERPROFILE}/AppData/ftl\"") + set(FTL_LOCAL_CONFIG_ROOT "\"${ENV_USERPROFILE}/AppData/ftl\"") + message(STATUS "Config root is ${FTL_LOCAL_CONFIG_ROOT}") + set(FTL_LOCAL_CACHE_ROOT "\"$ENV{USERPROFILE}/AppData/ftl\"") + set(FTL_LOCAL_DATA_ROOT "\"$ENV{USERPROFILE}/AppData/ftl\"") add_definitions(-DWIN32) set(CMAKE_CXX_FLAGS "/std:c++17") @@ -44,10 +46,16 @@ endif (WIN32) if (UNIX) add_definitions(-DUNIX) - set(FTL_CONFIG_ROOT "\"$ENV{HOME}/.config/ftl\"") - message(STATUS "Config root is ${FTL_CONFIG_ROOT}") - set(FTL_CACHE_ROOT "\"$ENV{HOME}/.cache/ftl\"") - set(FTL_DATA_ROOT "\"$ENV{HOME}/.local/share/ftl\"") + + set(FTL_LOCAL_CONFIG_ROOT "\"$ENV{HOME}/.config/ftl\"") + message(STATUS "Config root is ${FTL_LOCAL_CONFIG_ROOT}") + set(FTL_LOCAL_CACHE_ROOT "\"$ENV{HOME}/.cache/ftl\"") + set(FTL_LOCAL_DATA_ROOT "\"$ENV{HOME}/.local/share/ftl\"") + + set(FTL_GLOBAL_CONFIG_ROOT "\"${CMAKE_INSTALL_PREFIX}/share/ftl\"") + message(STATUS "Global config root is ${FTL_GLOBAL_CONFIG_ROOT}") + set(FTL_GLOBAL_CACHE_ROOT "\"${CMAKE_INSTALL_PREFIX}/share/ftl\"") + set(FTL_GLOBAL_DATA_ROOT "\"${CMAKE_INSTALL_PREFIX}/share/ftl\"") set(CMAKE_CXX_FLAGS "-std=c++17") set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -pg -Wall") @@ -59,3 +67,11 @@ SET(CMAKE_USE_RELATIVE_PATHS ON) add_subdirectory(net/cpp) add_subdirectory(cv-node) +configure_file(${CMAKE_SOURCE_DIR}/common/cpp/include/ftl/config.h.in + ${CMAKE_SOURCE_DIR}/common/cpp/include/ftl/config.h +) + +configure_file(${CMAKE_SOURCE_DIR}/common/cpp/src/config.cpp.in + ${CMAKE_SOURCE_DIR}/common/cpp/src/config.cpp +) + diff --git a/cmake/Findglog.cmake b/cmake/Findglog.cmake index e4e0eea8c1d3a5117873552c8b9d2a32ebbbcb60..dc0bf0bd33dab68b2fce0b7da134605a9a920923 100644 --- a/cmake/Findglog.cmake +++ b/cmake/Findglog.cmake @@ -33,5 +33,5 @@ if(GLOG_FOUND) include_directories(${GLOG_INCLUDE_DIRS}) set(GLOG_FOUND TRUE CACHE BOOL "" FORCE) set(GLOG_LIBRARIES ${GLOG_LIBRARY}) - message(STATUS "Found glog)") + message(STATUS "Found glog") endif() diff --git a/cmake/git_version.cmake b/cmake/git_version.cmake index 14ce6dfc10de7c15cfd58b264ac449d7300b9f32..f44754522e8d88c22d05a59050f888b7e954a160 100644 --- a/cmake/git_version.cmake +++ b/cmake/git_version.cmake @@ -4,7 +4,7 @@ if (Git_FOUND) #CHECK_REQUIRED_VARIABLE(GIT_EXECUTABLE) execute_process(COMMAND - "${GIT_EXECUTABLE}" describe --contains HEAD + "${GIT_EXECUTABLE}" describe --tags WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE VERSION @@ -14,7 +14,8 @@ if (Git_FOUND) string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" ftl_VERSION_MAJOR "${VERSION}") string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" ftl_VERSION_MINOR "${VERSION}") string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" ftl_VERSION_PATCH "${VERSION}") - string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" ftl_VERSION_SHA1 "${VERSION}") + string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-([0-9]+).*" "\\1" ftl_VERSION_COMMITS "${VERSION}") + string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+-(.*)" "\\1" ftl_VERSION_SHA1 "${VERSION}") set(FTL_VERSION "\"${ftl_VERSION_MAJOR}.${ftl_VERSION_MINOR}.${ftl_VERSION_PATCH}\"") else() diff --git a/common/cpp/include/ftl/config.h.in b/common/cpp/include/ftl/config.h.in new file mode 100644 index 0000000000000000000000000000000000000000..d3e2166031f7e7072f905701f98a3d4a4d90d38b --- /dev/null +++ b/common/cpp/include/ftl/config.h.in @@ -0,0 +1,24 @@ +#ifndef __FTL_CONFIG_H__ +#define __FTL_CONFIG_H__ + +#cmakedefine HAVE_VIZ +#cmakedefine HAVE_OPENCVCUDA +#cmakedefine HAVE_URIPARSESINGLE + +extern const char *FTL_VERSION_LONG; +extern const char *FTL_VERSION; +extern const int FTL_VERSION_MAJOR; +extern const int FTL_VERSION_MINOR; +extern const int FTL_VERSION_PATCH; +extern const int FTL_VERSION_COMMITS; +extern const char *FTL_VERSION_SHA1; + +#define FTL_LOCAL_CONFIG_ROOT @FTL_LOCAL_CONFIG_ROOT@ +#define FTL_LOCAL_CACHE_ROOT @FTL_LOCAL_CACHE_ROOT@ +#define FTL_LOCAL_DATA_ROOT @FTL_LOCAL_DATA_ROOT@ + +#define FTL_GLOBAL_CONFIG_ROOT @FTL_GLOBAL_CONFIG_ROOT@ +#define FTL_GLOBAL_CACHE_ROOT @FTL_GLOBAL_CACHE_ROOT@ +#define FTL_GLOBAL_DATA_ROOT @FTL_GLOBAL_DATA_ROOT@ + +#endif // __FTL_CONFIG_H__ diff --git a/common/cpp/src/config.cpp.in b/common/cpp/src/config.cpp.in new file mode 100644 index 0000000000000000000000000000000000000000..353e7ccbaa60ef204227a6e80c5bdde048ef7c9d --- /dev/null +++ b/common/cpp/src/config.cpp.in @@ -0,0 +1,9 @@ + +const char *FTL_VERSION_LONG = "@VERSION@"; +const char *FTL_VERSION = @FTL_VERSION@; +const int FTL_VERSION_MAJOR = @ftl_VERSION_MAJOR@; +const int FTL_VERSION_MINOR = @ftl_VERSION_MINOR@; +const int FTL_VERSION_PATCH = @ftl_VERSION_PATCH@; +const int FTL_VERSION_COMMITS = @ftl_VERSION_COMMITS@; +const char *FTL_VERSION_SHA1 = "@ftl_VERSION_SHA1@"; + diff --git a/cv-node/CMakeLists.txt b/cv-node/CMakeLists.txt index 0f7c6d64f625b488d2587a407378e7225e65099c..5f5457c82ba1b8cb7ea89f2eaed3e96c9478b82d 100644 --- a/cv-node/CMakeLists.txt +++ b/cv-node/CMakeLists.txt @@ -7,11 +7,8 @@ set(CMAKE_REQUIRED_INCLUDES ${OpenCV_INCLUDE_DIRS}) check_include_file_cxx("opencv2/viz.hpp" HAVE_VIZ) check_include_file_cxx("opencv2/cudastereo.hpp" HAVE_OPENCVCUDA) -configure_file(${CMAKE_SOURCE_DIR}/cv-node/include/ftl/config.h.in - ${CMAKE_SOURCE_DIR}/cv-node/include/ftl/config.h -) - set(CVNODESRC + ../common/cpp/src/config.cpp src/main.cpp src/calibrate.cpp src/local.cpp diff --git a/cv-node/include/ftl/config.h.in b/cv-node/include/ftl/config.h.in deleted file mode 100644 index bd68be9df86896a29d239bd99f892d55225dacff..0000000000000000000000000000000000000000 --- a/cv-node/include/ftl/config.h.in +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __FTL_CONFIG_H__ -#define __FTL_CONFIG_H__ - -#cmakedefine HAVE_VIZ -#cmakedefine HAVE_OPENCVCUDA - -#define FTL_VERSION_LONG "@VERSION@" -#define FTL_VERSION @FTL_VERSION@ -#define FTL_VERSION_MAJOR @ftl_VERSION_MAJOR@ -#define FTL_VERSION_MINOR @ftl_VERSION_MINOR@ -#define FTL_VERSION_PATCH @ftl_VERSION_PATCH@ -#define FTL_VERSION_SHA1 "@ftl_VERSION_SHA1@" - -#define FTL_CONFIG_ROOT @FTL_CONFIG_ROOT@ -#define FTL_CACHE_ROOT @FTL_CACHE_ROOT@ -#define FTL_DATA_ROOT @FTL_DATA_ROOT@ - -#endif // __FTL_CONFIG_H__ diff --git a/cv-node/src/calibrate.cpp b/cv-node/src/calibrate.cpp index cb66dad517aba256fbad10c66a92076441e986ee..22b5d59b30b14ee624f8d25dbcd75ff5ec63df23 100644 --- a/cv-node/src/calibrate.cpp +++ b/cv-node/src/calibrate.cpp @@ -206,7 +206,7 @@ bool Calibrate::_loadCalibration() { Rect roi1, roi2; // reading intrinsic parameters - FileStorage fs(FTL_CONFIG_ROOT "/intrinsics.yml", FileStorage::READ); + FileStorage fs(FTL_LOCAL_CONFIG_ROOT "/intrinsics.yml", FileStorage::READ); if(!fs.isOpened()) { LOG(WARNING) << "Calibration file not found"; @@ -222,7 +222,7 @@ bool Calibrate::_loadCalibration() { M1 *= scale; M2 *= scale; - fs.open(FTL_CONFIG_ROOT "/extrinsics.yml", FileStorage::READ); + fs.open(FTL_LOCAL_CONFIG_ROOT "/extrinsics.yml", FileStorage::READ); if(!fs.isOpened()) { LOG(WARNING) << "Calibration file not found"; @@ -289,7 +289,7 @@ bool Calibrate::recalibrate() { LOG(INFO) << "... done with RMS error=" << rms; // save intrinsic parameters - FileStorage fs(FTL_CONFIG_ROOT "/intrinsics.yml", FileStorage::WRITE); + FileStorage fs(FTL_LOCAL_CONFIG_ROOT "/intrinsics.yml", FileStorage::WRITE); if( fs.isOpened() ) { fs << "M1" << cameraMatrix[0] << "D1" << distCoeffs[0] << @@ -307,7 +307,7 @@ bool Calibrate::recalibrate() { imageSize[0], R, T, R1, R2, P1, P2, Q_, CALIB_ZERO_DISPARITY, 1, imageSize[0], &validRoi[0], &validRoi[1]); - fs.open(FTL_CONFIG_ROOT "/extrinsics.yml", FileStorage::WRITE); + fs.open(FTL_LOCAL_CONFIG_ROOT "/extrinsics.yml", FileStorage::WRITE); if( fs.isOpened() ) { fs << "R" << R << "T" << T << "R1" << R1 << "R2" << R2 << "P1" << P1 << "P2" << P2 << "Q" << Q_; @@ -376,13 +376,13 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints, LOG(INFO) << "Grabbing calibration image..."; if (view[0].empty() || (local_->isStereo() && view[1].empty()) || imagePoints[0].size() >= (size_t)settings_.nrFrames) { - settings_.outputFileName = FTL_CONFIG_ROOT "/cam0.xml"; + settings_.outputFileName = FTL_LOCAL_CONFIG_ROOT "/cam0.xml"; bool r = runCalibration(settings_, imageSize[0], cameraMatrix[0], distCoeffs[0], imagePoints[0], grid_width, release_object); if (local_->isStereo()) { - settings_.outputFileName = FTL_CONFIG_ROOT "/cam1.xml"; + settings_.outputFileName = FTL_LOCAL_CONFIG_ROOT "/cam1.xml"; r &= runCalibration(settings_, imageSize[1], cameraMatrix[1], distCoeffs[1], imagePoints[1], grid_width, release_object); diff --git a/cv-node/src/main.cpp b/cv-node/src/main.cpp index 1248014980f6303b94446bc81245264a33223943..0eb2dc6f2d430082884f6f51d7e5bd26fe8de0ca 100644 --- a/cv-node/src/main.cpp +++ b/cv-node/src/main.cpp @@ -36,7 +36,7 @@ static json config; */ static bool findConfiguration(const string &file) { // TODO Check other locations - ifstream i((file != "") ? file : FTL_CONFIG_ROOT "/config.json"); + ifstream i((file != "") ? file : FTL_LOCAL_CONFIG_ROOT "/config.json"); if (!i.is_open()) return false; i >> config; return true; @@ -74,6 +74,12 @@ static void process_options(const map<string,string> &opts) { for (auto opt : opts) { if (opt.first == "config") continue; + if (opt.first == "version") { + std::cout << "FTL Vision Node - v" << FTL_VERSION << std::endl; + std::cout << FTL_VERSION_LONG << std::endl; + exit(0); + } + try { auto ptr = json::json_pointer("/"+opt.first); // TODO Allow strings without quotes