From c6546a990918c0cd22bb03c293d7c38eb4203e64 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 16 Jul 2024 09:00:19 +0200 Subject: [PATCH 1/4] Update macos ci --- .github/workflows/macos-linux-conda.yml | 5 ++++- .github/workflows/macos.yml | 5 +---- README.md | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/macos-linux-conda.yml b/.github/workflows/macos-linux-conda.yml index e87580be47..bf254fdbf4 100644 --- a/.github/workflows/macos-linux-conda.yml +++ b/.github/workflows/macos-linux-conda.yml @@ -3,8 +3,11 @@ name: MacOS-Linux-conda-CI on: pull_request: types: [opened, reopened, synchronize] + +# https://stackoverflow.com/questions/66335225/how-to-cancel-previous-runs-in-the-pr-when-you-push-new-commitsupdate-the-curre#comment133398800_72408109 +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} cancel-in-progress: true jobs: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index e820b0096e..77b733ee20 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -81,16 +81,13 @@ jobs: # Openblas location is exported explicitly because openblas is keg-only, # which means it was not symlinked into /usr/local/. - # qt@5 is as a requested dependency for vtk and thus for pcl 1.12.1 - # qt@5 is keg-only, which means it was not symlinked into /usr/local that's why we need to set Qt5_DIR - name: Configure CMake run: | export LDFLAGS="-L/usr/local/opt/openblas/lib" export CPPFLAGS="-I/usr/local/opt/openblas/include" - export Qt5_DIR="$(brew --prefix qt5)/lib/cmake/Qt5" mkdir build cd build - cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5 + cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON cat ViSP-third-party.txt - name: Compile diff --git a/README.md b/README.md index 6ef88ce013..7d3c0d9c4c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Platform | Build Status | -------- | ------------ | Ubuntu 20.04, 22.04 (amd64)| [![ubuntu dep apt workflow](https://github.com/lagadic/visp/actions/workflows/ubuntu-dep-apt.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/ubuntu-dep-apt.yml) [![ubuntu dep src workflow](https://github.com/lagadic/visp/actions/workflows/ubuntu-dep-src.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/ubuntu-dep-src.yml) -macOS 11 and 12 | [![macos workflow](https://github.com/lagadic/visp/actions/workflows/macos.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/macos.yml) +macOS 13 and 14 | [![macos workflow](https://github.com/lagadic/visp/actions/workflows/macos.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/macos.yml) iOS on macOS 11.0| [![ios workflow](https://github.com/lagadic/visp/actions/workflows/ios.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/ios.yml) Windows 10 | [![Build status](https://ci.appveyor.com/api/projects/status/121dscdkryf5dbn0/branch/master?svg=true)](https://ci.appveyor.com/project/fspindle/visp/branch/master) Other arch Ubuntu 22.04 (aarch64, s390x)| [![other arch workflow](https://github.com/lagadic/visp/actions/workflows/other-arch.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/other-arch.yml) From 8310fcb579d3aadd4c3056b6cd4a1b9dbb468415 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 16 Jul 2024 22:20:38 +0200 Subject: [PATCH 2/4] Avoid redefinition of __USE_GNU macro Ros2 jenkins ci detected the following issue https://build.ros2.org/job/Hdev__visp__ubuntu_jammy_amd64/237 "__USE_GNU" redefined 29 | #define __USE_GNU | In file included from /usr/include/errno.h:25, from /tmp/ws/src/visp/3rdparty/apriltag/common/workerpool.cpp:27: --- 3rdparty/apriltag/common/workerpool.cpp | 250 ++++++++++++------------ 1 file changed, 128 insertions(+), 122 deletions(-) diff --git a/3rdparty/apriltag/common/workerpool.cpp b/3rdparty/apriltag/common/workerpool.cpp index 3134ec0c33..13d3780de3 100644 --- a/3rdparty/apriltag/common/workerpool.cpp +++ b/3rdparty/apriltag/common/workerpool.cpp @@ -26,7 +26,10 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include +// To avoid "__USE_GNU" redefined 29 | #define __USE_GNU | In file included from /usr/include/errno.h +#ifndef __USE_GNU #define __USE_GNU +#endif #include #include #include @@ -45,184 +48,187 @@ either expressed or implied, of the Regents of The University of Michigan. #include "math_util.h" #include "string_util.h" -struct workerpool { - int nthreads; - zarray_t *tasks; - int taskspos; +struct workerpool +{ + int nthreads; + zarray_t *tasks; + int taskspos; - pthread_t *threads; - int *status; + pthread_t *threads; + int *status; - pthread_mutex_t mutex; - pthread_cond_t startcond; // used to signal the availability of work - bool start_predicate; // predicate that prevents spurious wakeups on startcond - pthread_cond_t endcond; // used to signal completion of all work + pthread_mutex_t mutex; + pthread_cond_t startcond; // used to signal the availability of work + bool start_predicate; // predicate that prevents spurious wakeups on startcond + pthread_cond_t endcond; // used to signal completion of all work - int end_count; // how many threads are done? + int end_count; // how many threads are done? }; struct task { - void (*f)(void *p); - void *p; + void (*f)(void *p); + void *p; }; void *worker_thread(void *p) { - workerpool_t *wp = (workerpool_t*) p; + workerpool_t *wp = (workerpool_t *)p; - while (1) { - struct task *task; + while (1) { + struct task *task; - pthread_mutex_lock(&wp->mutex); - while (wp->taskspos == zarray_size(wp->tasks) || !wp->start_predicate) { - wp->end_count++; - pthread_cond_broadcast(&wp->endcond); - pthread_cond_wait(&wp->startcond, &wp->mutex); - } + pthread_mutex_lock(&wp->mutex); + while (wp->taskspos == zarray_size(wp->tasks) || !wp->start_predicate) { + wp->end_count++; + pthread_cond_broadcast(&wp->endcond); + pthread_cond_wait(&wp->startcond, &wp->mutex); + } - zarray_get_volatile(wp->tasks, wp->taskspos, &task); - wp->taskspos++; - pthread_mutex_unlock(&wp->mutex); - sched_yield(); + zarray_get_volatile(wp->tasks, wp->taskspos, &task); + wp->taskspos++; + pthread_mutex_unlock(&wp->mutex); + sched_yield(); - // we've been asked to exit. - if (task->f == NULL) - return NULL; + // we've been asked to exit. + if (task->f == NULL) + return NULL; - task->f(task->p); - } + task->f(task->p); + } - return NULL; + return NULL; } workerpool_t *workerpool_create(int nthreads) { - assert(nthreads > 0); - - workerpool_t *wp = (workerpool_t *)calloc(1, sizeof(workerpool_t)); - wp->nthreads = nthreads; - wp->tasks = zarray_create(sizeof(struct task)); - wp->start_predicate = false; + assert(nthreads > 0); + + workerpool_t *wp = (workerpool_t *)calloc(1, sizeof(workerpool_t)); + wp->nthreads = nthreads; + wp->tasks = zarray_create(sizeof(struct task)); + wp->start_predicate = false; + + if (nthreads > 1) { + wp->threads = (pthread_t *)calloc(wp->nthreads, sizeof(pthread_t)); + + pthread_mutex_init(&wp->mutex, NULL); + pthread_cond_init(&wp->startcond, NULL); + pthread_cond_init(&wp->endcond, NULL); + + for (int i = 0; i < nthreads; i++) { + int res = pthread_create(&wp->threads[i], NULL, worker_thread, wp); + if (res != 0) { + perror("pthread_create"); + // errno already set to EAGAIN by pthread_create() failure + return NULL; + } + } - if (nthreads > 1) { - wp->threads = (pthread_t *)calloc(wp->nthreads, sizeof(pthread_t)); - - pthread_mutex_init(&wp->mutex, NULL); - pthread_cond_init(&wp->startcond, NULL); - pthread_cond_init(&wp->endcond, NULL); - - for (int i = 0; i < nthreads; i++) { - int res = pthread_create(&wp->threads[i], NULL, worker_thread, wp); - if (res != 0) { - perror("pthread_create"); - // errno already set to EAGAIN by pthread_create() failure - return NULL; - } - } - - // Wait for the worker threads to be ready - pthread_mutex_lock(&wp->mutex); - while (wp->end_count < wp->nthreads) { - pthread_cond_wait(&wp->endcond, &wp->mutex); - } - pthread_mutex_unlock(&wp->mutex); + // Wait for the worker threads to be ready + pthread_mutex_lock(&wp->mutex); + while (wp->end_count < wp->nthreads) { + pthread_cond_wait(&wp->endcond, &wp->mutex); } + pthread_mutex_unlock(&wp->mutex); + } - return wp; + return wp; } void workerpool_destroy(workerpool_t *wp) { - if (wp == NULL) - return; - - // force all worker threads to exit. - if (wp->nthreads > 1) { - for (int i = 0; i < wp->nthreads; i++) - workerpool_add_task(wp, NULL, NULL); - - pthread_mutex_lock(&wp->mutex); - wp->start_predicate = true; - pthread_cond_broadcast(&wp->startcond); - pthread_mutex_unlock(&wp->mutex); - - for (int i = 0; i < wp->nthreads; i++) - pthread_join(wp->threads[i], NULL); - - pthread_mutex_destroy(&wp->mutex); - pthread_cond_destroy(&wp->startcond); - pthread_cond_destroy(&wp->endcond); - free(wp->threads); - } - - zarray_destroy(wp->tasks); - free(wp); + if (wp == NULL) + return; + +// force all worker threads to exit. + if (wp->nthreads > 1) { + for (int i = 0; i < wp->nthreads; i++) + workerpool_add_task(wp, NULL, NULL); + + pthread_mutex_lock(&wp->mutex); + wp->start_predicate = true; + pthread_cond_broadcast(&wp->startcond); + pthread_mutex_unlock(&wp->mutex); + + for (int i = 0; i < wp->nthreads; i++) + pthread_join(wp->threads[i], NULL); + + pthread_mutex_destroy(&wp->mutex); + pthread_cond_destroy(&wp->startcond); + pthread_cond_destroy(&wp->endcond); + free(wp->threads); + } + + zarray_destroy(wp->tasks); + free(wp); } int workerpool_get_nthreads(workerpool_t *wp) { - return wp->nthreads; + return wp->nthreads; } void workerpool_add_task(workerpool_t *wp, void (*f)(void *p), void *p) { - struct task t; - t.f = f; - t.p = p; - - if (wp->nthreads > 1) { - pthread_mutex_lock(&wp->mutex); - zarray_add(wp->tasks, &t); - pthread_mutex_unlock(&wp->mutex); - } else { - zarray_add(wp->tasks, &t); - } + struct task t; + t.f = f; + t.p = p; + + if (wp->nthreads > 1) { + pthread_mutex_lock(&wp->mutex); + zarray_add(wp->tasks, &t); + pthread_mutex_unlock(&wp->mutex); + } + else { + zarray_add(wp->tasks, &t); + } } void workerpool_run_single(workerpool_t *wp) { - for (int i = 0; i < zarray_size(wp->tasks); i++) { - struct task *task; - zarray_get_volatile(wp->tasks, i, &task); - task->f(task->p); - } + for (int i = 0; i < zarray_size(wp->tasks); i++) { + struct task *task; + zarray_get_volatile(wp->tasks, i, &task); + task->f(task->p); + } - zarray_clear(wp->tasks); + zarray_clear(wp->tasks); } // runs all added tasks, waits for them to complete. void workerpool_run(workerpool_t *wp) { - if (wp->nthreads > 1) { - pthread_mutex_lock(&wp->mutex); - wp->end_count = 0; - wp->start_predicate = true; - pthread_cond_broadcast(&wp->startcond); + if (wp->nthreads > 1) { + pthread_mutex_lock(&wp->mutex); + wp->end_count = 0; + wp->start_predicate = true; + pthread_cond_broadcast(&wp->startcond); - while (wp->end_count < wp->nthreads) { + while (wp->end_count < wp->nthreads) { // printf("caught %d\n", wp->end_count); - pthread_cond_wait(&wp->endcond, &wp->mutex); - } + pthread_cond_wait(&wp->endcond, &wp->mutex); + } - wp->taskspos = 0; - wp->start_predicate = false; - pthread_mutex_unlock(&wp->mutex); + wp->taskspos = 0; + wp->start_predicate = false; + pthread_mutex_unlock(&wp->mutex); - zarray_clear(wp->tasks); + zarray_clear(wp->tasks); - } else { - workerpool_run_single(wp); - } + } + else { + workerpool_run_single(wp); + } } int workerpool_get_nprocs() { #ifdef _WIN32 - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; #else - return sysconf (_SC_NPROCESSORS_ONLN); + return sysconf(_SC_NPROCESSORS_ONLN); #endif } From ab4d80b4492988f87772b5362ab2ad4014be51b6 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 16 Jul 2024 22:22:34 +0200 Subject: [PATCH 3/4] SIFT continues to produce issues on macos ci - skip SIFT when OpenCV 4.10.0 corresponding to VISP_HAVE_OPENCV_VERSION=0x040A00 - fix typo around pugixml detection - add verbosity to help debugging --- .../keypoint-with-dataset/testKeyPoint-2.cpp | 2 +- .../keypoint-with-dataset/testKeyPoint-4.cpp | 2 +- .../keypoint-with-dataset/testKeyPoint-5.cpp | 6 ++- .../keypoint-with-dataset/testKeyPoint-7.cpp | 49 +++++++++++++++---- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/modules/vision/test/keypoint-with-dataset/testKeyPoint-2.cpp b/modules/vision/test/keypoint-with-dataset/testKeyPoint-2.cpp index 4c2d51524b..81906d3a2f 100644 --- a/modules/vision/test/keypoint-with-dataset/testKeyPoint-2.cpp +++ b/modules/vision/test/keypoint-with-dataset/testKeyPoint-2.cpp @@ -189,7 +189,7 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis // Load config for tracker std::string tracker_config_file = vpIoTools::createFilePath(env_ipath, "mbt/cube.xml"); -#if defined(VISP_HAVE_PUGYXML) +#if defined(VISP_HAVE_PUGIXML) tracker.loadConfigFile(tracker_config_file); tracker.getCameraParameters(cam); #else diff --git a/modules/vision/test/keypoint-with-dataset/testKeyPoint-4.cpp b/modules/vision/test/keypoint-with-dataset/testKeyPoint-4.cpp index eef653ded5..94d69d74d6 100644 --- a/modules/vision/test/keypoint-with-dataset/testKeyPoint-4.cpp +++ b/modules/vision/test/keypoint-with-dataset/testKeyPoint-4.cpp @@ -191,7 +191,7 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis // Load config for tracker std::string tracker_config_file = vpIoTools::createFilePath(env_ipath, "mbt/cube.xml"); -#if defined(VISP_HAVE_PUGYXML) +#if defined(VISP_HAVE_PUGIXML) tracker.loadConfigFile(tracker_config_file); tracker.getCameraParameters(cam); #else diff --git a/modules/vision/test/keypoint-with-dataset/testKeyPoint-5.cpp b/modules/vision/test/keypoint-with-dataset/testKeyPoint-5.cpp index 5bf8d93d9a..8321466188 100644 --- a/modules/vision/test/keypoint-with-dataset/testKeyPoint-5.cpp +++ b/modules/vision/test/keypoint-with-dataset/testKeyPoint-5.cpp @@ -218,11 +218,12 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400) #if (VISP_HAVE_OPENCV_VERSION != 0x040504) && (VISP_HAVE_OPENCV_VERSION != 0x040505) && \ (VISP_HAVE_OPENCV_VERSION != 0x040600) && (VISP_HAVE_OPENCV_VERSION != 0x040700) && \ - (VISP_HAVE_OPENCV_VERSION != 0x040900) && (VISP_HAVE_OPENCV_VERSION != 0x041000) && \ + (VISP_HAVE_OPENCV_VERSION != 0x040900) && (VISP_HAVE_OPENCV_VERSION != 0x040A00) && \ (defined(__APPLE__) && defined(__MACH__)) // SIFT is known to be unstable with OpenCV 4.5.4 and 4.5.5 on macOS (see #1048) // Same for OpenCV 4.6.0 (see #1106) where it produces an Illegal Instruction error when OpenCV 4.6.0 is // installed with brew. It seems working when OpenCV is build from source + std::cout << "-- Add SIFT detector" << std::endl; detectorNames.push_back("PyramidSIFT"); detectorNames.push_back("SIFT"); #endif @@ -271,12 +272,13 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400) #if ((VISP_HAVE_OPENCV_VERSION == 0x040504) || (VISP_HAVE_OPENCV_VERSION == 0x040505) || \ (VISP_HAVE_OPENCV_VERSION == 0x040600) || (VISP_HAVE_OPENCV_VERSION == 0x040700) || \ - (VISP_HAVE_OPENCV_VERSION == 0x040900) || (VISP_HAVE_OPENCV_VERSION == 0x041000)) && \ + (VISP_HAVE_OPENCV_VERSION == 0x040900) || (VISP_HAVE_OPENCV_VERSION == 0x040A00)) && \ (defined(__APPLE__) && defined(__MACH__)) // SIFT is known to be unstable with OpenCV 4.5.4 and 4.5.5 on macOS (see #1048) // Same for OpenCV 4.6.0 (see #1106) where it produces an Illegal Instruction error when OpenCV 4.6.0 is // installed with brew. It seems working when OpenCV is build from source if (i == vpKeyPoint::DETECTOR_SIFT) { + std::cout << "-- Skip SIFT detector" << std::endl; continue; } #endif diff --git a/modules/vision/test/keypoint-with-dataset/testKeyPoint-7.cpp b/modules/vision/test/keypoint-with-dataset/testKeyPoint-7.cpp index ba32b33fb3..eba90a7573 100644 --- a/modules/vision/test/keypoint-with-dataset/testKeyPoint-7.cpp +++ b/modules/vision/test/keypoint-with-dataset/testKeyPoint-7.cpp @@ -305,6 +305,7 @@ template void run_test(const std::string &env_ipath, const std:: // Test with binary descriptor { + std::cout << "Detect ORB keypoints" << std::endl; std::string keypointName = "ORB"; keyPoints.setDetector(keypointName); keyPoints.setExtractor(keypointName); @@ -324,6 +325,7 @@ template void run_test(const std::string &env_ipath, const std:: filename = vpIoTools::createFilePath(opath, "bin_with_img"); vpIoTools::makeDirectory(filename); filename = vpIoTools::createFilePath(filename, "test_save_in_bin_with_img.bin"); + std::cout << "Save keypoints in binary with image in: " << filename << std::endl; keyPoints.saveLearningData(filename, true, true); // Test if save is ok @@ -335,18 +337,20 @@ template void run_test(const std::string &env_ipath, const std:: // Test if read is ok vpKeyPoint read_keypoint1; - + std::cout << "Read keypoints from file: " << filename << std::endl; read_keypoint1.loadLearningData(filename, true); std::vector trainKeyPoints_read; read_keypoint1.getTrainKeyPoints(trainKeyPoints_read); cv::Mat trainDescriptors_read = read_keypoint1.getTrainDescriptors(); + std::cout << "Compare keypoints" << std::endl; if (!compareKeyPoints(trainKeyPoints, trainKeyPoints_read)) { throw vpException(vpException::fatalError, "Problem with trainKeyPoints when reading learning file saved " "in binary with train images saved !"); } + std::cout << "Compare descriptors" << std::endl; if (!compareDescriptors(trainDescriptors, trainDescriptors_read)) { throw vpException(vpException::fatalError, "Problem with trainDescriptors when reading " "learning file saved in " @@ -357,6 +361,7 @@ template void run_test(const std::string &env_ipath, const std:: filename = vpIoTools::createFilePath(opath, "bin_without_img"); vpIoTools::makeDirectory(filename); filename = vpIoTools::createFilePath(filename, "test_save_in_bin_without_img.bin"); + std::cout << "Save keypoints in binary without image in: " << filename << std::endl; keyPoints.saveLearningData(filename, true, false); // Test if save is ok @@ -368,27 +373,31 @@ template void run_test(const std::string &env_ipath, const std:: // Test if read is ok vpKeyPoint read_keypoint2; + std::cout << "Read keypoints from file: " << filename << std::endl; read_keypoint2.loadLearningData(filename, true); trainKeyPoints_read.clear(); read_keypoint2.getTrainKeyPoints(trainKeyPoints_read); trainDescriptors_read = read_keypoint2.getTrainDescriptors(); + std::cout << "Compare keypoints" << std::endl; if (!compareKeyPoints(trainKeyPoints, trainKeyPoints_read)) { throw vpException(vpException::fatalError, "Problem with trainKeyPoints when reading learning file saved in " "binary without train images !"); } + std::cout << "Compare descriptors" << std::endl; if (!compareDescriptors(trainDescriptors, trainDescriptors_read)) { throw vpException(vpException::fatalError, "Problem with trainDescriptors when reading " "learning file saved in " "binary without train images !"); } -#if defined(VISP_HAVE_PUGYXML) +#if defined(VISP_HAVE_PUGIXML) // Save in xml with training images filename = vpIoTools::createFilePath(opath, "xml_with_img"); vpIoTools::makeDirectory(filename); filename = vpIoTools::createFilePath(filename, "test_save_in_xml_with_img.xml"); + std::cout << "Save keypoints in xml with image in: " << filename << std::endl; keyPoints.saveLearningData(filename, false, true); // Test if save is ok @@ -400,16 +409,19 @@ template void run_test(const std::string &env_ipath, const std:: // Test if read is ok vpKeyPoint read_keypoint3; + std::cout << "Read keypoints from file: " << filename << std::endl; read_keypoint3.loadLearningData(filename, false); trainKeyPoints_read.clear(); read_keypoint3.getTrainKeyPoints(trainKeyPoints_read); trainDescriptors_read = read_keypoint3.getTrainDescriptors(); + std::cout << "Compare keypoints" << std::endl; if (!compareKeyPoints(trainKeyPoints, trainKeyPoints_read)) { throw vpException(vpException::fatalError, "Problem with trainKeyPoints when reading learning file saved in " "xml with train images saved !"); } + std::cout << "Compare descriptors" << std::endl; if (!compareDescriptors(trainDescriptors, trainDescriptors_read)) { throw vpException(vpException::fatalError, "Problem with trainDescriptors when reading " "learning file saved in " @@ -420,6 +432,7 @@ template void run_test(const std::string &env_ipath, const std:: filename = vpIoTools::createFilePath(opath, "xml_without_img"); vpIoTools::makeDirectory(filename); filename = vpIoTools::createFilePath(filename, "test_save_in_xml_without_img.xml"); + std::cout << "Save keypoints in xml without image in: " << filename << std::endl; keyPoints.saveLearningData(filename, false, false); // Test if save is ok @@ -433,14 +446,17 @@ template void run_test(const std::string &env_ipath, const std:: vpKeyPoint read_keypoint4; read_keypoint4.loadLearningData(filename, false); trainKeyPoints_read.clear(); + std::cout << "Read keypoints from file: " << filename << std::endl; read_keypoint4.getTrainKeyPoints(trainKeyPoints_read); trainDescriptors_read = read_keypoint4.getTrainDescriptors(); + std::cout << "Compare keypoints" << std::endl; if (!compareKeyPoints(trainKeyPoints, trainKeyPoints_read)) { throw vpException(vpException::fatalError, "Problem with trainKeyPoints when reading learning file saved in " "xml without train images saved !"); } + std::cout << "Compare descriptors" << std::endl; if (!compareDescriptors(trainDescriptors, trainDescriptors_read)) { throw vpException(vpException::fatalError, "Problem with trainDescriptors when reading " "learning file saved in " @@ -457,19 +473,22 @@ template void run_test(const std::string &env_ipath, const std:: { #if (VISP_HAVE_OPENCV_VERSION != 0x040504) && (VISP_HAVE_OPENCV_VERSION != 0x040505) && \ (VISP_HAVE_OPENCV_VERSION != 0x040600) && (VISP_HAVE_OPENCV_VERSION != 0x040700) && \ - (VISP_HAVE_OPENCV_VERSION != 0x040900) && (VISP_HAVE_OPENCV_VERSION != 0x041000) && \ + (VISP_HAVE_OPENCV_VERSION != 0x040900) && (VISP_HAVE_OPENCV_VERSION != 0x040A00) && \ (defined(__APPLE__) && defined(__MACH__)) // SIFT is known to be unstable with OpenCV 4.5.4 and 4.5.5 on macOS (see #1048) // Same for OpenCV 4.6.0 (see #1106) where it produces an Illegal Instruction error when OpenCV 4.6.0 is // installed with brew. It seems working when OpenCV is build from source std::string keypointName = "SIFT"; + std::cout << "Use " << keypointName << " keypoints" << std::endl; keyPoints.setDetector(keypointName); keyPoints.setExtractor(keypointName); + std::cout << "Detect keypoints" << std::endl; keyPoints.buildReference(I); std::vector trainKeyPoints; keyPoints.getTrainKeyPoints(trainKeyPoints); + std::cout << "Get descriptors" << std::endl; cv::Mat trainDescriptors = keyPoints.getTrainDescriptors(); if (trainKeyPoints.empty() || trainDescriptors.empty() || (int)trainKeyPoints.size() != trainDescriptors.rows) { throw vpException(vpException::fatalError, "Problem when detecting keypoints or when " @@ -480,6 +499,7 @@ template void run_test(const std::string &env_ipath, const std:: filename = vpIoTools::createFilePath(opath, "bin_with_img"); vpIoTools::makeDirectory(filename); filename = vpIoTools::createFilePath(filename, "test_save_in_bin_with_img.bin"); + std::cout << "Save keypoints in binary with image in: " << filename << std::endl; keyPoints.saveLearningData(filename, true, true); // Test if save is ok @@ -491,16 +511,19 @@ template void run_test(const std::string &env_ipath, const std:: // Test if read is ok vpKeyPoint read_keypoint1; + std::cout << "Load keypoints from: " << filename << std::endl; read_keypoint1.loadLearningData(filename, true); std::vector trainKeyPoints_read; read_keypoint1.getTrainKeyPoints(trainKeyPoints_read); cv::Mat trainDescriptors_read = read_keypoint1.getTrainDescriptors(); + std::cout << "Compare keypoints" << std::endl; if (!compareKeyPoints(trainKeyPoints, trainKeyPoints_read)) { throw vpException(vpException::fatalError, "Problem with trainKeyPoints when reading learning file saved in " "binary with train images saved !"); } + std::cout << "Compare descriptors" << std::endl; if (!compareDescriptors(trainDescriptors, trainDescriptors_read)) { throw vpException(vpException::fatalError, "Problem with trainDescriptors when reading " "learning file saved in " @@ -511,6 +534,7 @@ template void run_test(const std::string &env_ipath, const std:: filename = vpIoTools::createFilePath(opath, "bin_without_img"); vpIoTools::makeDirectory(filename); filename = vpIoTools::createFilePath(filename, "test_save_in_bin_without_img.bin"); + std::cout << "Save keypoints in binary without image in: " << filename << std::endl; keyPoints.saveLearningData(filename, true, false); // Test if save is ok @@ -522,23 +546,26 @@ template void run_test(const std::string &env_ipath, const std:: // Test if read is ok vpKeyPoint read_keypoint2; + std::cout << "Load keypoints from: " << filename << std::endl; read_keypoint2.loadLearningData(filename, true); trainKeyPoints_read.clear(); read_keypoint2.getTrainKeyPoints(trainKeyPoints_read); trainDescriptors_read = read_keypoint2.getTrainDescriptors(); + std::cout << "Compare keypoints" << std::endl; if (!compareKeyPoints(trainKeyPoints, trainKeyPoints_read)) { throw vpException(vpException::fatalError, "Problem with trainKeyPoints when reading learning file saved in " "binary without train images saved !"); } + std::cout << "Compare descriptors" << std::endl; if (!compareDescriptors(trainDescriptors, trainDescriptors_read)) { throw vpException(vpException::fatalError, "Problem with trainDescriptors when reading " "learning file saved in " "binary without train images saved !"); } -#if defined(VISP_HAVE_PUGYXML) +#if defined(VISP_HAVE_PUGIXML) // Save in xml with training images filename = vpIoTools::createFilePath(opath, "xml_with_img"); vpIoTools::makeDirectory(filename); @@ -607,37 +634,41 @@ template void run_test(const std::string &env_ipath, const std:: vpKeyPoint keypoint_reset; keypointName = "ORB"; + std::cout << "Use " << keypointName << " as keypoints" << std::endl; keypoint_reset.setDetector(keypointName); keypoint_reset.setExtractor(keypointName); keypoint_reset.buildReference(I); + std::cout << keypointName << " keypoints are detected" << std::endl; // reset keypoint_reset.reset(); keypointName = "SIFT"; + std::cout << "Use " << keypointName << " as keypoints" << std::endl; keypoint_reset.setDetector(keypointName); keypoint_reset.setExtractor(keypointName); keypoint_reset.buildReference(I); + std::cout << keypointName << " keypoints are detected" << std::endl; std::vector trainKeyPoints_reset; keypoint_reset.getTrainKeyPoints(trainKeyPoints_reset); + std::cout << "Get descriptors" << std::endl; cv::Mat trainDescriptors_reset = keypoint_reset.getTrainDescriptors(); - // If reset is ok, we should get the same keypoints and the same - // descriptors + // If reset is ok, we should get the same keypoints and the same descriptors + std::cout << "Compare keypoints" << std::endl; if (!compareKeyPoints(trainKeyPoints, trainKeyPoints_reset)) { throw vpException(vpException::fatalError, "Problem with vpKeyPoint::reset() and trainKeyPoints !"); } + std::cout << "Compare descriptors" << std::endl; if (!compareDescriptors(trainDescriptors, trainDescriptors_reset)) { throw vpException(vpException::fatalError, "Problem with vpKeyPoint::reset() and trainDescriptors !"); } - std::cout << "vpKeyPoint::reset() is ok with trainKeyPoints and " - "trainDescriptors !" - << std::endl; + std::cout << "vpKeyPoint::reset() is ok with trainKeyPoints and trainDescriptors !" << std::endl; #endif // OpenCV != 4.5.4 on macOS } #endif From 2394054df200800756f1557aa411fde9a262871c Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 16 Jul 2024 22:25:36 +0200 Subject: [PATCH 4/4] Update vscode settings --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5dec46c458..c01e3cc45a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -165,7 +165,8 @@ "core": "cpp", "dense": "cpp", "stdvector": "cpp", - "numericaldiff": "cpp" + "numericaldiff": "cpp", + "source_location": "cpp" }, "C_Cpp.vcFormat.indent.namespaceContents": false, "editor.formatOnSave": true,