diff --git a/corelib/src/Features2d.cpp b/corelib/src/Features2d.cpp index 2ef8dc97..3b409c60 100644 --- a/corelib/src/Features2d.cpp +++ b/corelib/src/Features2d.cpp @@ -1211,13 +1211,13 @@ void SURF::parseParameters(const ParametersMap & parameters) #ifdef RTABMAP_NONFREE #if CV_MAJOR_VERSION < 3 - if(gpuVersion_ && cv::gpu::getCudaEnabledDeviceCount() == 0) + if(gpuVersion_ && cv::gpu::getCudaEnabledDeviceCount() <= 0) { UWARN("GPU version of SURF not available! Using CPU version instead..."); gpuVersion_ = false; } #else - if(gpuVersion_ && cv::cuda::getCudaEnabledDeviceCount() == 0) + if(gpuVersion_ && cv::cuda::getCudaEnabledDeviceCount() <= 0) { UWARN("GPU version of SURF not available! Using CPU version instead..."); gpuVersion_ = false; @@ -1650,7 +1650,7 @@ void ORB::parseParameters(const ParametersMap & parameters) #if CV_MAJOR_VERSION < 3 #ifdef HAVE_OPENCV_GPU - if(gpu_ && cv::gpu::getCudaEnabledDeviceCount() == 0) + if(gpu_ && cv::gpu::getCudaEnabledDeviceCount() <= 0) { UWARN("GPU version of ORB not available! Using CPU version instead..."); gpu_ = false; @@ -1670,7 +1670,7 @@ void ORB::parseParameters(const ParametersMap & parameters) gpu_ = false; } #endif - if(gpu_ && cv::cuda::getCudaEnabledDeviceCount() == 0) + if(gpu_ && cv::cuda::getCudaEnabledDeviceCount() <= 0) { UWARN("GPU version of ORB not available (no GPU found)! Using CPU version instead..."); gpu_ = false; @@ -1906,7 +1906,7 @@ void FAST::parseParameters(const ParametersMap & parameters) #if CV_MAJOR_VERSION < 3 #ifdef HAVE_OPENCV_GPU - if(gpu_ && cv::gpu::getCudaEnabledDeviceCount() == 0) + if(gpu_ && cv::gpu::getCudaEnabledDeviceCount() <= 0) { UWARN("GPU version of FAST not available! Using CPU version instead..."); gpu_ = false; @@ -1920,7 +1920,7 @@ void FAST::parseParameters(const ParametersMap & parameters) #endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D - if(gpu_ && cv::cuda::getCudaEnabledDeviceCount() == 0) + if(gpu_ && cv::cuda::getCudaEnabledDeviceCount() <= 0) { UWARN("GPU version of FAST not available! Using CPU version instead..."); gpu_ = false; @@ -2215,7 +2215,7 @@ void GFTT::parseParameters(const ParametersMap & parameters) #endif #ifdef HAVE_OPENCV_CUDAIMGPROC - if(_gpu && cv::cuda::getCudaEnabledDeviceCount() == 0) + if(_gpu && cv::cuda::getCudaEnabledDeviceCount() <= 0) { UWARN("GPU version of GFTT not available! Using CPU version instead..."); _gpu = false; diff --git a/corelib/src/VWDictionary.cpp b/corelib/src/VWDictionary.cpp index d6577ab2..ba3f29ca 100644 --- a/corelib/src/VWDictionary.cpp +++ b/corelib/src/VWDictionary.cpp @@ -300,7 +300,7 @@ bool VWDictionary::setNNStrategy(NNStrategy strategy) { #if CV_MAJOR_VERSION < 3 #ifdef HAVE_OPENCV_GPU - if(strategy == kNNBruteForceGPU && !cv::gpu::getCudaEnabledDeviceCount()) + if(strategy == kNNBruteForceGPU && cv::gpu::getCudaEnabledDeviceCount() <= 0) { UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but no CUDA devices found! Doing \"kNNBruteForce\" instead."); strategy = kNNBruteForce; @@ -314,7 +314,7 @@ bool VWDictionary::setNNStrategy(NNStrategy strategy) #endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D - if(strategy == kNNBruteForceGPU && !cv::cuda::getCudaEnabledDeviceCount()) + if(strategy == kNNBruteForceGPU && cv::cuda::getCudaEnabledDeviceCount() <= 0) { UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but no CUDA devices found! Doing \"kNNBruteForce\" instead."); strategy = kNNBruteForce; diff --git a/corelib/test/CMakeLists.txt b/corelib/test/CMakeLists.txt index 3a1f03f3..35a675be 100644 --- a/corelib/test/CMakeLists.txt +++ b/corelib/test/CMakeLists.txt @@ -30,7 +30,6 @@ add_test(NAME test_util3d_registration COMMAND test_util3d_registration) add_executable(test_util3d_features test_util3d_features.cpp) target_link_libraries(test_util3d_features gtest_main rtabmap_core) add_test(NAME test_util3d_features COMMAND test_util3d_features) -set_tests_properties(test_util3d_features PROPERTIES TIMEOUT 600) #util3d_correspondences.h add_executable(test_util3d_correspondences test_util3d_correspondences.cpp) @@ -71,7 +70,6 @@ add_test(NAME test_transform COMMAND test_transform) add_executable(test_stereo_dense test_stereo_dense.cpp) target_link_libraries(test_stereo_dense gtest_main rtabmap_core) add_test(NAME test_stereo_dense COMMAND test_stereo_dense) -set_tests_properties(test_stereo_dense PROPERTIES TIMEOUT 600) #Stereo.h (tests both BlockMatching and OpticalFlow strategies) add_executable(test_stereo test_stereo.cpp) @@ -162,7 +160,6 @@ add_test(NAME test_landmark COMMAND test_landmark) add_executable(test_localgrid test_localgrid.cpp) target_link_libraries(test_localgrid gtest_main rtabmap_core) add_test(NAME test_localgrid COMMAND test_localgrid) -set_tests_properties(test_localgrid PROPERTIES TIMEOUT 600) #Features2d.h add_executable(test_features2d test_features2d.cpp) diff --git a/corelib/test/test_rtabmap_integration.cpp b/corelib/test/test_rtabmap_integration.cpp index 4726537f..55d89df9 100644 --- a/corelib/test/test_rtabmap_integration.cpp +++ b/corelib/test/test_rtabmap_integration.cpp @@ -2029,7 +2029,7 @@ TEST_F(RtabmapIntegrationFixture, AppearanceOnly_PrecisionRecall) // Probe GPU availability once per detector. Build the temp instance // with the same asset paths the actual run uses; otherwise SuperPoint // variants log a (harmless) load failure. - bool useGpu = false; + bool gpuAvailable = false; { ParametersMap probeParams; if(detectorType == Feature2D::kFeatureSuperPointTorch) @@ -2042,9 +2042,15 @@ TEST_F(RtabmapIntegrationFixture, AppearanceOnly_PrecisionRecall) probeParams[Parameters::kSuperPointRpautratModelPath()] = superpointRpautratModel; } std::unique_ptr probe(Feature2D::create(detectorType, probeParams)); - if(probe) useGpu = probe->isGpuAvailable(); + if(probe) gpuAvailable = probe->isGpuAvailable(); } + // GPU-capable detectors are exercised twice (CPU + GPU) so both code + // paths stay covered. Detectors that don't report a GPU path run only + // once. + std::vector gpuVariants = {false}; + if(gpuAvailable) gpuVariants.push_back(true); + // Run only the default likelihood variant for every detector; // the TF-IDF variant adds a second run on the default detector // (kFeatureGfttOrb) so the alternative likelihood path stays @@ -2052,6 +2058,7 @@ TEST_F(RtabmapIntegrationFixture, AppearanceOnly_PrecisionRecall) std::vector tfIdfVariants = {false}; if(detectorType == defaultDetector) tfIdfVariants.push_back(true); + for(bool useGpu : gpuVariants) for(bool tfIdfUsed : tfIdfVariants) { const std::string detectorLabel = typeName @@ -2079,9 +2086,10 @@ TEST_F(RtabmapIntegrationFixture, AppearanceOnly_PrecisionRecall) params[Parameters::kKAZEThreshold()] = "0.0001"; // GFTT-specific: tighten the minimum keypoint separation (default // 7 px) so more candidates fit per frame. - params[Parameters::kGFTTMinDistance()] = "5"; + params[Parameters::kGFTTMinDistance()] = "3"; params[Parameters::kMemBadSignaturesIgnored()] = "false"; params[Parameters::kMemRehearsalSimilarity()] = "0.20"; + params[Parameters::kBRIEFBytes()] = "64"; // Backend-specific asset paths + GPU/CUDA toggle. `useGpu` only // reaches here when this detector reports a usable GPU path; we diff --git a/corelib/test/test_vwdictionary.cpp b/corelib/test/test_vwdictionary.cpp index 8ffc010b..9e67f8e6 100644 --- a/corelib/test/test_vwdictionary.cpp +++ b/corelib/test/test_vwdictionary.cpp @@ -62,17 +62,11 @@ TEST_F(VWDictionaryTest, AddNewWordsIncremental) for(VWDictionary::NNStrategy strategy : strategies) { - // Reset dictionary for each strategy - dict->clear(); - dict->setNNStrategy(strategy); - - EXPECT_TRUE(dict->isIncremental()); - if(strategy == VWDictionary::kNNBruteForceGPU) { #if CV_MAJOR_VERSION < 3 #ifdef HAVE_OPENCV_GPU - if(!cv::gpu::getCudaEnabledDeviceCount()) + if(cv::gpu::getCudaEnabledDeviceCount() <= 0) { strategy = VWDictionary::kNNBruteForce; } @@ -81,7 +75,7 @@ TEST_F(VWDictionaryTest, AddNewWordsIncremental) #endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D - if(!cv::cuda::getCudaEnabledDeviceCount()) + if(cv::cuda::getCudaEnabledDeviceCount() <= 0) { strategy = VWDictionary::kNNBruteForce; } @@ -90,6 +84,12 @@ TEST_F(VWDictionaryTest, AddNewWordsIncremental) #endif #endif } + + // Reset dictionary for each strategy + dict->clear(); + dict->setNNStrategy(strategy); + + EXPECT_TRUE(dict->isIncremental()); EXPECT_EQ(dict->getNNStrategy(), strategy); // Add initial words to dictionary (2D descriptors) @@ -636,15 +636,11 @@ TEST_F(VWDictionaryTest, SerializeDeserializeIndex) for(VWDictionary::NNStrategy strategy : strategies) { - // Reset dictionary for each strategy - dict->clear(); - dict->setNNStrategy(strategy); - if(strategy == VWDictionary::kNNBruteForceGPU) { #if CV_MAJOR_VERSION < 3 #ifdef HAVE_OPENCV_GPU - if(!cv::gpu::getCudaEnabledDeviceCount()) + if(cv::gpu::getCudaEnabledDeviceCount() <= 0) { continue; // Skip if no GPU available } @@ -653,7 +649,7 @@ TEST_F(VWDictionaryTest, SerializeDeserializeIndex) #endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D - if(!cv::cuda::getCudaEnabledDeviceCount()) + if(cv::cuda::getCudaEnabledDeviceCount() <= 0) { continue; // Skip if no GPU available } @@ -663,6 +659,10 @@ TEST_F(VWDictionaryTest, SerializeDeserializeIndex) #endif } + // Reset dictionary for each strategy + dict->clear(); + dict->setNNStrategy(strategy); + // Add words and build index cv::Mat descriptors(5, 32, CV_32F); cv::randu(descriptors, cv::Scalar(0), cv::Scalar(1)); diff --git a/guilib/src/PreferencesDialog.cpp b/guilib/src/PreferencesDialog.cpp index 5c7043ad..2908f2a7 100644 --- a/guilib/src/PreferencesDialog.cpp +++ b/guilib/src/PreferencesDialog.cpp @@ -134,11 +134,11 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) : bool haveCuda = false; #if CV_MAJOR_VERSION < 3 #ifdef HAVE_OPENCV_GPU - haveCuda = cv::gpu::getCudaEnabledDeviceCount() != 0; + haveCuda = cv::gpu::getCudaEnabledDeviceCount() > 0; #endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D - haveCuda = cv::cuda::getCudaEnabledDeviceCount() != 0; + haveCuda = cv::cuda::getCudaEnabledDeviceCount() > 0; #endif #endif if(!haveCuda)