TEST_P(SetTo, Masked) { cv::Scalar val = randomScalar(0.0, 255.0); cv::Mat mat_gold = randomMat(size, type); cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0); if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE)) { try { cv::gpu::GpuMat mat = createMat(size, type, useRoi); mat.setTo(val, loadMat(mask)); } catch (const cv::Exception& e) { ASSERT_EQ(CV_StsUnsupportedFormat, e.code); } } else { cv::gpu::GpuMat mat = loadMat(mat_gold, useRoi); mat.setTo(val, loadMat(mask, useRoi)); mat_gold.setTo(val, mask); EXPECT_MAT_NEAR(mat_gold, mat, 0.0); } }
TEST_P(SURF, Descriptor) { cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(image.empty()); cv::gpu::SURF_GPU surf; surf.hessianThreshold = hessianThreshold; surf.nOctaves = nOctaves; surf.nOctaveLayers = nOctaveLayers; surf.extended = extended; surf.upright = upright; surf.keypointsRatio = 0.05f; cv::SURF surf_gold; surf_gold.hessianThreshold = hessianThreshold; surf_gold.nOctaves = nOctaves; surf_gold.nOctaveLayers = nOctaveLayers; surf_gold.extended = extended; surf_gold.upright = upright; if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS)) { try { std::vector<cv::KeyPoint> keypoints; cv::gpu::GpuMat descriptors; surf(loadMat(image), cv::gpu::GpuMat(), keypoints, descriptors); } catch (const cv::Exception& e) { ASSERT_EQ(CV_StsNotImplemented, e.code); } } else { std::vector<cv::KeyPoint> keypoints; surf_gold(image, cv::noArray(), keypoints); cv::gpu::GpuMat descriptors; surf(loadMat(image), cv::gpu::GpuMat(), keypoints, descriptors, true); cv::Mat descriptors_gold; surf_gold(image, cv::noArray(), keypoints, descriptors_gold, true); cv::BFMatcher matcher(cv::NORM_L2); std::vector<cv::DMatch> matches; matcher.match(descriptors_gold, cv::Mat(descriptors), matches); int matchedCount = getMatchedPointsCount(keypoints, keypoints, matches); double matchedRatio = static_cast<double>(matchedCount) / keypoints.size(); EXPECT_GT(matchedRatio, 0.35); } }
TEST_P(SURF, Detector_Masked) { cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(image.empty()); cv::Mat mask(image.size(), CV_8UC1, cv::Scalar::all(1)); mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0)); cv::gpu::SURF_GPU surf; surf.hessianThreshold = hessianThreshold; surf.nOctaves = nOctaves; surf.nOctaveLayers = nOctaveLayers; surf.extended = extended; surf.upright = upright; surf.keypointsRatio = 0.05f; if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS)) { try { std::vector<cv::KeyPoint> keypoints; surf(loadMat(image), loadMat(mask), keypoints); } catch (const cv::Exception& e) { ASSERT_EQ(CV_StsNotImplemented, e.code); } } else { std::vector<cv::KeyPoint> keypoints; surf(loadMat(image), loadMat(mask), keypoints); cv::SURF surf_gold; surf_gold.hessianThreshold = hessianThreshold; surf_gold.nOctaves = nOctaves; surf_gold.nOctaveLayers = nOctaveLayers; surf_gold.extended = extended; surf_gold.upright = upright; std::vector<cv::KeyPoint> keypoints_gold; surf_gold(image, mask, keypoints_gold); ASSERT_EQ(keypoints_gold.size(), keypoints.size()); int matchedCount = getMatchedPointsCount(keypoints_gold, keypoints); double matchedRatio = static_cast<double>(matchedCount) / keypoints_gold.size(); EXPECT_GT(matchedRatio, 0.95); } }
TEST_P(Merge, Accuracy) { if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE)) return; PRINT_PARAM(devInfo); PRINT_TYPE(type); PRINT_PARAM(size); cv::Mat dst; ASSERT_NO_THROW( std::vector<cv::gpu::GpuMat> dev_src; cv::gpu::GpuMat dev_dst; for (size_t i = 0; i < src.size(); ++i) dev_src.push_back(cv::gpu::GpuMat(src[i])); cv::gpu::merge(dev_src, dev_dst); dev_dst.download(dst); );
TEST_P(SetTo, SameVal) { cv::Scalar val = cv::Scalar::all(randomDouble(0.0, 255.0)); if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE)) { try { cv::gpu::GpuMat mat = createMat(size, type, useRoi); mat.setTo(val); } catch (const cv::Exception& e) { ASSERT_EQ(CV_StsUnsupportedFormat, e.code); } } else { cv::gpu::GpuMat mat = createMat(size, type, useRoi); mat.setTo(val); EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0); } }