Revert "call resetDevice if gpu test fails"

This reverts commit ab25fe9e37.
This commit is contained in:
Vladislav Vinogradov 2012-12-19 11:13:31 +04:00
parent 41c9377db0
commit 4ba33fa1ed
36 changed files with 5694 additions and 9450 deletions

View File

@ -92,23 +92,15 @@ PERF_TEST_P(Image, HoughLinesP,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_image(image);
{ cv::gpu::GpuMat d_lines;
cv::gpu::GpuMat d_image(image); cv::gpu::HoughLinesBuf d_buf;
cv::gpu::GpuMat d_lines;
cv::gpu::HoughLinesBuf d_buf;
cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap);
TEST_CYCLE()
{
cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap);
TEST_CYCLE()
{
cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -163,25 +155,17 @@ PERF_TEST_P(Image_Depth, GoodFeaturesToTrack,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, k);
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_mask(mask);
cv::gpu::GpuMat d_pts;
d_detector(d_src, d_pts, d_mask);
TEST_CYCLE()
{ {
cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, k);
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_mask(mask);
cv::gpu::GpuMat d_pts;
d_detector(d_src, d_pts, d_mask); d_detector(d_src, d_pts, d_mask);
TEST_CYCLE()
{
d_detector(d_src, d_pts, d_mask);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -260,31 +244,23 @@ PERF_TEST_P(ImagePair_Depth_GraySource, OpticalFlowPyrLKSparse,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src1(src1);
cv::gpu::GpuMat d_src2(src2);
cv::gpu::GpuMat d_pts(pts.reshape(2, 1));
cv::gpu::GpuMat d_nextPts;
cv::gpu::GpuMat d_status;
cv::gpu::PyrLKOpticalFlow d_pyrLK;
d_pyrLK.winSize = winSize;
d_pyrLK.maxLevel = maxLevel;
d_pyrLK.iters = criteria.maxCount;
d_pyrLK.useInitialFlow = false;
d_pyrLK.sparse(d_src1, d_src2, d_pts, d_nextPts, d_status);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_src1(src1);
cv::gpu::GpuMat d_src2(src2);
cv::gpu::GpuMat d_pts(pts.reshape(2, 1));
cv::gpu::GpuMat d_nextPts;
cv::gpu::GpuMat d_status;
cv::gpu::PyrLKOpticalFlow d_pyrLK;
d_pyrLK.winSize = winSize;
d_pyrLK.maxLevel = maxLevel;
d_pyrLK.iters = criteria.maxCount;
d_pyrLK.useInitialFlow = false;
d_pyrLK.sparse(d_src1, d_src2, d_pts, d_nextPts, d_status); d_pyrLK.sparse(d_src1, d_src2, d_pts, d_nextPts, d_status);
TEST_CYCLE()
{
d_pyrLK.sparse(d_src1, d_src2, d_pts, d_nextPts, d_status);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -346,33 +322,25 @@ PERF_TEST_P(ImagePair_Depth, OpticalFlowFarneback,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src1(src1);
cv::gpu::GpuMat d_src2(src2);
cv::gpu::GpuMat d_u(src1.size(), CV_32FC1, cv::Scalar::all(0));
cv::gpu::GpuMat d_v(src1.size(), CV_32FC1, cv::Scalar::all(0));
cv::gpu::FarnebackOpticalFlow d_farneback;
d_farneback.pyrScale = pyrScale;
d_farneback.numLevels = numLevels;
d_farneback.winSize = winSize;
d_farneback.numIters = numIters;
d_farneback.polyN = polyN;
d_farneback.polySigma = polySigma;
d_farneback.flags = flags;
d_farneback(d_src1, d_src2, d_u, d_v);
TEST_CYCLE_N(10)
{ {
cv::gpu::GpuMat d_src1(src1);
cv::gpu::GpuMat d_src2(src2);
cv::gpu::GpuMat d_u(src1.size(), CV_32FC1, cv::Scalar::all(0));
cv::gpu::GpuMat d_v(src1.size(), CV_32FC1, cv::Scalar::all(0));
cv::gpu::FarnebackOpticalFlow d_farneback;
d_farneback.pyrScale = pyrScale;
d_farneback.numLevels = numLevels;
d_farneback.winSize = winSize;
d_farneback.numIters = numIters;
d_farneback.polyN = polyN;
d_farneback.polySigma = polySigma;
d_farneback.flags = flags;
d_farneback(d_src1, d_src2, d_u, d_v); d_farneback(d_src1, d_src2, d_u, d_v);
TEST_CYCLE_N(10)
{
d_farneback(d_src1, d_src2, d_u, d_v);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -441,23 +409,15 @@ PERF_TEST_P(ImagePair_BlockSize_ShiftSize_MaxRange, OpticalFlowBM,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src1(src1);
{ cv::gpu::GpuMat d_src2(src2);
cv::gpu::GpuMat d_src1(src1); cv::gpu::GpuMat d_velx, d_vely, buf;
cv::gpu::GpuMat d_src2(src2);
cv::gpu::GpuMat d_velx, d_vely, buf;
cv::gpu::calcOpticalFlowBM(d_src1, d_src2, block_size, shift_size, max_range, false, d_velx, d_vely, buf);
TEST_CYCLE_N(10)
{
cv::gpu::calcOpticalFlowBM(d_src1, d_src2, block_size, shift_size, max_range, false, d_velx, d_vely, buf); cv::gpu::calcOpticalFlowBM(d_src1, d_src2, block_size, shift_size, max_range, false, d_velx, d_vely, buf);
TEST_CYCLE_N(10)
{
cv::gpu::calcOpticalFlowBM(d_src1, d_src2, block_size, shift_size, max_range, false, d_velx, d_vely, buf);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -500,25 +460,17 @@ PERF_TEST_P(ImagePair_BlockSize_ShiftSize_MaxRange, FastOpticalFlowBM,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src1(src1);
cv::gpu::GpuMat d_src2(src2);
cv::gpu::GpuMat d_velx, d_vely;
cv::gpu::FastOpticalFlowBM fastBM;
fastBM(d_src1, d_src2, d_velx, d_vely, max_range.width, block_size.width);
TEST_CYCLE_N(10)
{ {
cv::gpu::GpuMat d_src1(src1);
cv::gpu::GpuMat d_src2(src2);
cv::gpu::GpuMat d_velx, d_vely;
cv::gpu::FastOpticalFlowBM fastBM;
fastBM(d_src1, d_src2, d_velx, d_vely, max_range.width, block_size.width); fastBM(d_src1, d_src2, d_velx, d_vely, max_range.width, block_size.width);
TEST_CYCLE_N(10)
{
fastBM(d_src1, d_src2, d_velx, d_vely, max_range.width, block_size.width);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else

View File

@ -26,28 +26,20 @@ PERF_TEST_P(ImagePair, Calib3D_StereoBM, Values(pair_string("gpu/perf/aloe.png",
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::StereoBM_GPU d_bm(preset, ndisp);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_bm(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE()
{ {
cv::gpu::StereoBM_GPU d_bm(preset, ndisp);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_bm(d_imgLeft, d_imgRight, d_dst); d_bm(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE()
{
d_bm(d_imgLeft, d_imgRight, d_dst);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -83,28 +75,20 @@ PERF_TEST_P(ImagePair, Calib3D_StereoBeliefPropagation, Values(pair_string("gpu/
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::StereoBeliefPropagation d_bp(ndisp);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_bp(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE()
{ {
cv::gpu::StereoBeliefPropagation d_bp(ndisp);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_bp(d_imgLeft, d_imgRight, d_dst); d_bp(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE()
{
d_bp(d_imgLeft, d_imgRight, d_dst);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -129,28 +113,20 @@ PERF_TEST_P(ImagePair, Calib3D_StereoConstantSpaceBP, Values(pair_string("gpu/st
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::StereoConstantSpaceBP d_csbp(ndisp);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_csbp(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE()
{ {
cv::gpu::StereoConstantSpaceBP d_csbp(ndisp);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_csbp(d_imgLeft, d_imgRight, d_dst); d_csbp(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE()
{
d_csbp(d_imgLeft, d_imgRight, d_dst);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -173,28 +149,20 @@ PERF_TEST_P(ImagePair, Calib3D_DisparityBilateralFilter, Values(pair_string("gpu
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::DisparityBilateralFilter d_filter(ndisp);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_disp(disp);
cv::gpu::GpuMat d_dst;
d_filter(d_disp, d_img, d_dst);
TEST_CYCLE()
{ {
cv::gpu::DisparityBilateralFilter d_filter(ndisp);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_disp(disp);
cv::gpu::GpuMat d_dst;
d_filter(d_disp, d_img, d_dst); d_filter(d_disp, d_img, d_dst);
TEST_CYCLE()
{
d_filter(d_disp, d_img, d_dst);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -219,25 +187,17 @@ PERF_TEST_P(Count, Calib3D_TransformPoints, Values(5000, 10000, 20000))
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::transformPoints(d_src, rvec, tvec, d_dst);
TEST_CYCLE()
{
cv::gpu::transformPoints(d_src, rvec, tvec, d_dst); cv::gpu::transformPoints(d_src, rvec, tvec, d_dst);
TEST_CYCLE()
{
cv::gpu::transformPoints(d_src, rvec, tvec, d_dst);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -261,25 +221,17 @@ PERF_TEST_P(Count, Calib3D_ProjectPoints, Values(5000, 10000, 20000))
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst);
TEST_CYCLE()
{
cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst); cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst);
TEST_CYCLE()
{
cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -331,19 +283,11 @@ PERF_TEST_P(Count, Calib3D_SolvePnPRansac, Values(5000, 10000, 20000))
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
TEST_CYCLE()
{ {
cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
TEST_CYCLE()
{
cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -376,25 +320,17 @@ PERF_TEST_P(Sz_Depth, Calib3D_ReprojectImageTo3D, Combine(GPU_TYPICAL_MAT_SIZES,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::reprojectImageTo3D(d_src, d_dst, Q);
TEST_CYCLE()
{
cv::gpu::reprojectImageTo3D(d_src, d_dst, Q); cv::gpu::reprojectImageTo3D(d_src, d_dst, Q);
TEST_CYCLE()
{
cv::gpu::reprojectImageTo3D(d_src, d_dst, Q);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -424,25 +360,17 @@ PERF_TEST_P(Sz_Depth, Calib3D_DrawColorDisp, Combine(GPU_TYPICAL_MAT_SIZES, Valu
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::drawColorDisp(d_src, d_dst, 255);
TEST_CYCLE()
{
cv::gpu::drawColorDisp(d_src, d_dst, 255); cv::gpu::drawColorDisp(d_src, d_dst, 255);
TEST_CYCLE()
{
cv::gpu::drawColorDisp(d_src, d_dst, 255);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {

File diff suppressed because it is too large Load Diff

View File

@ -30,27 +30,19 @@ PERF_TEST_P(Sz_Depth_Cn_KernelSz, Denoising_BilateralFilter,
cv::Mat src(size, type); cv::Mat src(size, type);
fillRandom(src); fillRandom(src);
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::bilateralFilter(d_src, d_dst, kernel_size, sigma_color, sigma_spatial, borderMode);
TEST_CYCLE()
{
cv::gpu::bilateralFilter(d_src, d_dst, kernel_size, sigma_color, sigma_spatial, borderMode); cv::gpu::bilateralFilter(d_src, d_dst, kernel_size, sigma_color, sigma_spatial, borderMode);
TEST_CYCLE()
{
cv::gpu::bilateralFilter(d_src, d_dst, kernel_size, sigma_color, sigma_spatial, borderMode);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -95,25 +87,17 @@ PERF_TEST_P(Sz_Depth_Cn_WinSz_BlockSz, Denoising_NonLocalMeans,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::nonLocalMeans(d_src, d_dst, h, search_widow_size, block_size, borderMode);
TEST_CYCLE()
{
cv::gpu::nonLocalMeans(d_src, d_dst, h, search_widow_size, block_size, borderMode); cv::gpu::nonLocalMeans(d_src, d_dst, h, search_widow_size, block_size, borderMode);
TEST_CYCLE()
{
cv::gpu::nonLocalMeans(d_src, d_dst, h, search_widow_size, block_size, borderMode);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -146,26 +130,18 @@ PERF_TEST_P(Sz_Depth_Cn_WinSz_BlockSz, Denoising_FastNonLocalMeans,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src); cv::gpu::FastNonLocalMeansDenoising fnlmd;
cv::gpu::GpuMat d_dst;
cv::gpu::FastNonLocalMeansDenoising fnlmd;
fnlmd.simpleMethod(d_src, d_dst, h, search_widow_size, block_size);
TEST_CYCLE()
{
fnlmd.simpleMethod(d_src, d_dst, h, search_widow_size, block_size); fnlmd.simpleMethod(d_src, d_dst, h, search_widow_size, block_size);
TEST_CYCLE()
{
fnlmd.simpleMethod(d_src, d_dst, h, search_widow_size, block_size);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -205,26 +181,18 @@ PERF_TEST_P(Sz_Depth_WinSz_BlockSz, Denoising_FastNonLocalMeansColored,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src); cv::gpu::FastNonLocalMeansDenoising fnlmd;
cv::gpu::GpuMat d_dst;
cv::gpu::FastNonLocalMeansDenoising fnlmd;
fnlmd.labMethod(d_src, d_dst, h, h, search_widow_size, block_size);
TEST_CYCLE()
{
fnlmd.labMethod(d_src, d_dst, h, h, search_widow_size, block_size); fnlmd.labMethod(d_src, d_dst, h, h, search_widow_size, block_size);
TEST_CYCLE()
{
fnlmd.labMethod(d_src, d_dst, h, h, search_widow_size, block_size);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -238,4 +206,4 @@ PERF_TEST_P(Sz_Depth_WinSz_BlockSz, Denoising_FastNonLocalMeansColored,
CPU_SANITY_CHECK(dst); CPU_SANITY_CHECK(dst);
} }
} }

View File

@ -19,28 +19,20 @@ PERF_TEST_P(Image, Features2D_SURF, Values<string>("gpu/perf/aloe.png"))
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::SURF_GPU d_surf;
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints, d_descriptors;
d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
TEST_CYCLE()
{ {
cv::gpu::SURF_GPU d_surf;
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints, d_descriptors;
d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
TEST_CYCLE()
{
d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
}
GPU_SANITY_CHECK(d_descriptors, 1e-4);
GPU_SANITY_CHECK_KEYPOINTS(SURF, d_keypoints);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_descriptors, 1e-4);
GPU_SANITY_CHECK_KEYPOINTS(SURF, d_keypoints);
} }
else else
{ {
@ -72,27 +64,19 @@ PERF_TEST_P(Image, Features2D_FAST, Values<string>("gpu/perf/aloe.png"))
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::FAST_GPU d_fast(20);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints;
d_fast(d_img, cv::gpu::GpuMat(), d_keypoints);
TEST_CYCLE()
{ {
cv::gpu::FAST_GPU d_fast(20);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints;
d_fast(d_img, cv::gpu::GpuMat(), d_keypoints); d_fast(d_img, cv::gpu::GpuMat(), d_keypoints);
TEST_CYCLE()
{
d_fast(d_img, cv::gpu::GpuMat(), d_keypoints);
}
GPU_SANITY_CHECK_RESPONSE(FAST, d_keypoints);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK_RESPONSE(FAST, d_keypoints);
} }
else else
{ {
@ -120,28 +104,20 @@ PERF_TEST_P(Image, Features2D_ORB, Values<string>("gpu/perf/aloe.png"))
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::ORB_GPU d_orb(4000);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints, d_descriptors;
d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
TEST_CYCLE()
{ {
cv::gpu::ORB_GPU d_orb(4000);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints, d_descriptors;
d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
TEST_CYCLE()
{
d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
}
GPU_SANITY_CHECK_KEYPOINTS(ORB, d_keypoints);
GPU_SANITY_CHECK(d_descriptors);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK_KEYPOINTS(ORB, d_keypoints);
GPU_SANITY_CHECK(d_descriptors);
} }
else else
{ {
@ -185,29 +161,21 @@ PERF_TEST_P(DescSize_Norm, Features2D_BFMatch, Combine(Values(64, 128, 256), Val
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_distance;
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
TEST_CYCLE()
{ {
cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_distance;
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance); d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
TEST_CYCLE()
{
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
}
GPU_SANITY_CHECK(d_trainIdx);
GPU_SANITY_CHECK(d_distance);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_trainIdx);
GPU_SANITY_CHECK(d_distance);
} }
else else
{ {
@ -252,29 +220,21 @@ PERF_TEST_P(DescSize_K_Norm, Features2D_BFKnnMatch, Combine(
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_distance, d_allDist;
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k);
TEST_CYCLE()
{ {
cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_distance, d_allDist;
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k); d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k);
TEST_CYCLE()
{
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k);
}
GPU_SANITY_CHECK(d_trainIdx);
GPU_SANITY_CHECK(d_distance);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_trainIdx);
GPU_SANITY_CHECK(d_distance);
} }
else else
{ {
@ -313,29 +273,21 @@ PERF_TEST_P(DescSize_Norm, Features2D_BFRadiusMatch, Combine(Values(64, 128, 256
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_nMatches, d_distance;
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0);
TEST_CYCLE()
{ {
cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_nMatches, d_distance;
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0); d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0);
TEST_CYCLE()
{
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0);
}
GPU_SANITY_CHECK(d_trainIdx);
GPU_SANITY_CHECK(d_distance);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_trainIdx);
GPU_SANITY_CHECK(d_distance);
} }
else else
{ {

View File

@ -23,25 +23,17 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Blur, Combine(GPU_TYPICAL_MAT_SIZES, Value
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize));
TEST_CYCLE()
{
cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize)); cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize));
TEST_CYCLE()
{
cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize));
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -74,26 +66,18 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Sobel, Combine(GPU_TYPICAL_MAT_SIZES, Valu
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src); cv::gpu::GpuMat d_buf;
cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_buf;
cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize);
TEST_CYCLE()
{
cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize); cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize);
TEST_CYCLE()
{
cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -125,26 +109,18 @@ PERF_TEST_P(Sz_Type, Filters_Scharr, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src); cv::gpu::GpuMat d_buf;
cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_buf;
cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf);
TEST_CYCLE()
{
cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf); cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf);
TEST_CYCLE()
{
cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -177,26 +153,18 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_GaussianBlur, Combine(GPU_TYPICAL_MAT_SIZE
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src); cv::gpu::GpuMat d_buf;
cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_buf;
cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5);
TEST_CYCLE()
{
cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5); cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5);
TEST_CYCLE()
{
cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -229,25 +197,17 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Laplacian, Combine(GPU_TYPICAL_MAT_SIZES,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::Laplacian(d_src, d_dst, -1, ksize);
TEST_CYCLE()
{
cv::gpu::Laplacian(d_src, d_dst, -1, ksize); cv::gpu::Laplacian(d_src, d_dst, -1, ksize);
TEST_CYCLE()
{
cv::gpu::Laplacian(d_src, d_dst, -1, ksize);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -281,26 +241,18 @@ PERF_TEST_P(Sz_Type, Filters_Erode, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src); cv::gpu::GpuMat d_buf;
cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_buf;
cv::gpu::erode(d_src, d_dst, ker, d_buf);
TEST_CYCLE()
{
cv::gpu::erode(d_src, d_dst, ker, d_buf); cv::gpu::erode(d_src, d_dst, ker, d_buf);
TEST_CYCLE()
{
cv::gpu::erode(d_src, d_dst, ker, d_buf);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -334,26 +286,18 @@ PERF_TEST_P(Sz_Type, Filters_Dilate, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src); cv::gpu::GpuMat d_buf;
cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_buf;
cv::gpu::dilate(d_src, d_dst, ker, d_buf);
TEST_CYCLE()
{
cv::gpu::dilate(d_src, d_dst, ker, d_buf); cv::gpu::dilate(d_src, d_dst, ker, d_buf);
TEST_CYCLE()
{
cv::gpu::dilate(d_src, d_dst, ker, d_buf);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -393,27 +337,19 @@ PERF_TEST_P(Sz_Type_Op, Filters_MorphologyEx, Combine(GPU_TYPICAL_MAT_SIZES, Val
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src); cv::gpu::GpuMat d_buf1;
cv::gpu::GpuMat d_dst; cv::gpu::GpuMat d_buf2;
cv::gpu::GpuMat d_buf1;
cv::gpu::GpuMat d_buf2;
cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2);
TEST_CYCLE()
{
cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2); cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2);
TEST_CYCLE()
{
cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -449,25 +385,17 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Filter2D, Combine(GPU_TYPICAL_MAT_SIZES, V
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::filter2D(d_src, d_dst, -1, kernel);
TEST_CYCLE()
{
cv::gpu::filter2D(d_src, d_dst, -1, kernel); cv::gpu::filter2D(d_src, d_dst, -1, kernel);
TEST_CYCLE()
{
cv::gpu::filter2D(d_src, d_dst, -1, kernel);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {

File diff suppressed because it is too large Load Diff

View File

@ -108,30 +108,22 @@ PERF_TEST_P(Image, Labeling_ConnectedComponents, Values<string>("gpu/labeling/al
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat mask;
mask.create(image.rows, image.cols, CV_8UC1);
cv::gpu::GpuMat components;
components.create(image.rows, image.cols, CV_32SC1);
cv::gpu::connectivityMask(cv::gpu::GpuMat(image), mask, cv::Scalar::all(0), cv::Scalar::all(2));
ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components));
TEST_CYCLE()
{ {
cv::gpu::GpuMat mask; cv::gpu::labelComponents(mask, components);
mask.create(image.rows, image.cols, CV_8UC1);
cv::gpu::GpuMat components;
components.create(image.rows, image.cols, CV_32SC1);
cv::gpu::connectivityMask(cv::gpu::GpuMat(image), mask, cv::Scalar::all(0), cv::Scalar::all(2));
ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components));
TEST_CYCLE()
{
cv::gpu::labelComponents(mask, components);
}
GPU_SANITY_CHECK(components);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(components);
} }
else else
{ {

View File

@ -20,24 +20,16 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_SetTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(size, type);
{
cv::gpu::GpuMat d_src(size, type);
d_src.setTo(val);
TEST_CYCLE()
{
d_src.setTo(val); d_src.setTo(val);
TEST_CYCLE()
{
d_src.setTo(val);
}
GPU_SANITY_CHECK(d_src);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_src);
} }
else else
{ {
@ -75,25 +67,17 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Value
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_mask(mask);
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_mask(mask);
d_src.setTo(val, d_mask);
TEST_CYCLE()
{
d_src.setTo(val, d_mask); d_src.setTo(val, d_mask);
TEST_CYCLE()
{
d_src.setTo(val, d_mask);
}
GPU_SANITY_CHECK(d_src);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_src);
} }
else else
{ {
@ -127,26 +111,18 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Valu
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_mask(mask);
cv::gpu::GpuMat d_src(src); cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_mask(mask);
cv::gpu::GpuMat d_dst;
d_src.copyTo(d_dst, d_mask);
TEST_CYCLE()
{
d_src.copyTo(d_dst, d_mask); d_src.copyTo(d_dst, d_mask);
TEST_CYCLE()
{
d_src.copyTo(d_dst, d_mask);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {
@ -179,25 +155,17 @@ PERF_TEST_P(Sz_2Depth, MatOp_ConvertTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_src(src);
{ cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
d_src.convertTo(d_dst, depth2, 0.5, 1.0);
TEST_CYCLE()
{
d_src.convertTo(d_dst, depth2, 0.5, 1.0); d_src.convertTo(d_dst, depth2, 0.5, 1.0);
TEST_CYCLE()
{
d_src.convertTo(d_dst, depth2, 0.5, 1.0);
}
GPU_SANITY_CHECK(d_dst);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_dst);
} }
else else
{ {

View File

@ -19,24 +19,16 @@ PERF_TEST_P(Image, ObjDetect_HOG, Values<string>("gpu/hog/road.png"))
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_img(img);
cv::gpu::HOGDescriptor d_hog;
d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
d_hog.detectMultiScale(d_img, found_locations);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_img(img);
cv::gpu::HOGDescriptor d_hog;
d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
d_hog.detectMultiScale(d_img, found_locations); d_hog.detectMultiScale(d_img, found_locations);
TEST_CYCLE()
{
d_hog.detectMultiScale(d_img, found_locations);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -69,24 +61,16 @@ PERF_TEST_P(HOG, CalTech, Values<string>("gpu/caltech/image_00000009_0.png", "gp
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_img(img);
cv::gpu::HOGDescriptor d_hog;
d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
d_hog.detectMultiScale(d_img, found_locations);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_img(img);
cv::gpu::HOGDescriptor d_hog;
d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
d_hog.detectMultiScale(d_img, found_locations); d_hog.detectMultiScale(d_img, found_locations);
TEST_CYCLE()
{
d_hog.detectMultiScale(d_img, found_locations);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -119,28 +103,20 @@ PERF_TEST_P(ImageAndCascade, ObjDetect_HaarClassifier,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::CascadeClassifier_GPU d_cascade;
ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second)));
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_objects_buffer;
d_cascade.detectMultiScale(d_img, d_objects_buffer);
TEST_CYCLE()
{ {
cv::gpu::CascadeClassifier_GPU d_cascade;
ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second)));
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_objects_buffer;
d_cascade.detectMultiScale(d_img, d_objects_buffer); d_cascade.detectMultiScale(d_img, d_objects_buffer);
TEST_CYCLE()
{
d_cascade.detectMultiScale(d_img, d_objects_buffer);
}
GPU_SANITY_CHECK(d_objects_buffer);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_objects_buffer);
} }
else else
{ {
@ -171,28 +147,20 @@ PERF_TEST_P(ImageAndCascade, ObjDetect_LBPClassifier,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::CascadeClassifier_GPU d_cascade;
ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second)));
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_gpu_rects;
d_cascade.detectMultiScale(d_img, d_gpu_rects);
TEST_CYCLE()
{ {
cv::gpu::CascadeClassifier_GPU d_cascade;
ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second)));
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_gpu_rects;
d_cascade.detectMultiScale(d_img, d_gpu_rects); d_cascade.detectMultiScale(d_img, d_gpu_rects);
TEST_CYCLE()
{
d_cascade.detectMultiScale(d_img, d_gpu_rects);
}
GPU_SANITY_CHECK(d_gpu_rects);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_gpu_rects);
} }
else else
{ {
@ -212,4 +180,4 @@ PERF_TEST_P(ImageAndCascade, ObjDetect_LBPClassifier,
} }
} }
} // namespace } // namespace

View File

@ -60,36 +60,28 @@ GPU_PERF_TEST_P(SCascadeTest, detect,
RUN_GPU(SCascadeTest, detect) RUN_GPU(SCascadeTest, detect)
{ {
try cv::Mat cpu = readImage (GET_PARAM(1));
ASSERT_FALSE(cpu.empty());
cv::gpu::GpuMat colored(cpu);
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(1);
cascade.detect(colored, rois, objectBoxes);
TEST_CYCLE()
{ {
cv::Mat cpu = readImage (GET_PARAM(1));
ASSERT_FALSE(cpu.empty());
cv::gpu::GpuMat colored(cpu);
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(1);
cascade.detect(colored, rois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
TEST_CYCLE()
{
cascade.detect(colored, rois, objectBoxes);
}
SANITY_CHECK(sortDetections(objectBoxes));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
SANITY_CHECK(sortDetections(objectBoxes));
} }
NO_CPU(SCascadeTest, detect) NO_CPU(SCascadeTest, detect)
@ -126,45 +118,37 @@ GPU_PERF_TEST_P(SCascadeTestRoi, detectInRoi,
RUN_GPU(SCascadeTestRoi, detectInRoi) RUN_GPU(SCascadeTestRoi, detectInRoi)
{ {
try cv::Mat cpu = readImage (GET_PARAM(1));
ASSERT_FALSE(cpu.empty());
cv::gpu::GpuMat colored(cpu);
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 16384 * 20, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0);
int nroi = GET_PARAM(2);
cv::RNG rng;
for (int i = 0; i < nroi; ++i)
{ {
cv::Mat cpu = readImage (GET_PARAM(1)); cv::Rect r = getFromTable(rng(10));
ASSERT_FALSE(cpu.empty()); cv::gpu::GpuMat sub(rois, r);
cv::gpu::GpuMat colored(cpu); sub.setTo(1);
}
cv::gpu::SCascade cascade; cascade.detect(colored, rois, objectBoxes);
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 16384 * 20, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0);
int nroi = GET_PARAM(2);
cv::RNG rng;
for (int i = 0; i < nroi; ++i)
{
cv::Rect r = getFromTable(rng(10));
cv::gpu::GpuMat sub(rois, r);
sub.setTo(1);
}
TEST_CYCLE()
{
cascade.detect(colored, rois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
TEST_CYCLE()
{
cascade.detect(colored, rois, objectBoxes);
}
SANITY_CHECK(sortDetections(objectBoxes));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
SANITY_CHECK(sortDetections(objectBoxes));
} }
NO_CPU(SCascadeTestRoi, detectInRoi) NO_CPU(SCascadeTestRoi, detectInRoi)
@ -179,41 +163,33 @@ GPU_PERF_TEST_P(SCascadeTestRoi, detectEachRoi,
RUN_GPU(SCascadeTestRoi, detectEachRoi) RUN_GPU(SCascadeTestRoi, detectEachRoi)
{ {
try cv::Mat cpu = readImage (GET_PARAM(1));
ASSERT_FALSE(cpu.empty());
cv::gpu::GpuMat colored(cpu);
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 16384 * 20, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0);
int idx = GET_PARAM(2);
cv::Rect r = getFromTable(idx);
cv::gpu::GpuMat sub(rois, r);
sub.setTo(1);
cascade.detect(colored, rois, objectBoxes);
TEST_CYCLE()
{ {
cv::Mat cpu = readImage (GET_PARAM(1));
ASSERT_FALSE(cpu.empty());
cv::gpu::GpuMat colored(cpu);
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 16384 * 20, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0);
int idx = GET_PARAM(2);
cv::Rect r = getFromTable(idx);
cv::gpu::GpuMat sub(rois, r);
sub.setTo(1);
cascade.detect(colored, rois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
TEST_CYCLE()
{
cascade.detect(colored, rois, objectBoxes);
}
SANITY_CHECK(sortDetections(objectBoxes));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
SANITY_CHECK(sortDetections(objectBoxes));
} }
NO_CPU(SCascadeTestRoi, detectEachRoi) NO_CPU(SCascadeTestRoi, detectEachRoi)
@ -233,44 +209,36 @@ GPU_PERF_TEST_P(SCascadeTest, detectOnIntegral,
RUN_GPU(SCascadeTest, detectOnIntegral) RUN_GPU(SCascadeTest, detectOnIntegral)
{ {
try cv::FileStorage fsi(perf::TestBase::getDataPath(GET_PARAM(1)), cv::FileStorage::READ);
ASSERT_TRUE(fsi.isOpened());
cv::gpu::GpuMat hogluv(121 * 10, 161, CV_32SC1);
for (int i = 0; i < 10; ++i)
{ {
cv::FileStorage fsi(perf::TestBase::getDataPath(GET_PARAM(1)), cv::FileStorage::READ); cv::Mat channel;
ASSERT_TRUE(fsi.isOpened()); fsi[std::string("channel") + itoa(i)] >> channel;
cv::gpu::GpuMat gchannel(hogluv, cv::Rect(0, 121 * i, 161, 121));
gchannel.upload(channel);
}
cv::gpu::GpuMat hogluv(121 * 10, 161, CV_32SC1); cv::gpu::SCascade cascade;
for (int i = 0; i < 10; ++i)
{
cv::Mat channel;
fsi[std::string("channel") + itoa(i)] >> channel;
cv::gpu::GpuMat gchannel(hogluv, cv::Rect(0, 121 * i, 161, 121));
gchannel.upload(channel);
}
cv::gpu::SCascade cascade; cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(cv::Size(640, 480), CV_8UC1);
rois.setTo(1);
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(cv::Size(640, 480), CV_8UC1); cascade.detect(hogluv, rois, objectBoxes);
rois.setTo(1);
TEST_CYCLE()
{
cascade.detect(hogluv, rois, objectBoxes); cascade.detect(hogluv, rois, objectBoxes);
TEST_CYCLE()
{
cascade.detect(hogluv, rois, objectBoxes);
}
SANITY_CHECK(sortDetections(objectBoxes));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
SANITY_CHECK(sortDetections(objectBoxes));
} }
NO_CPU(SCascadeTest, detectOnIntegral) NO_CPU(SCascadeTest, detectOnIntegral)
@ -283,42 +251,34 @@ GPU_PERF_TEST_P(SCascadeTest, detectStream,
RUN_GPU(SCascadeTest, detectStream) RUN_GPU(SCascadeTest, detectStream)
{ {
try cv::Mat cpu = readImage (GET_PARAM(1));
ASSERT_FALSE(cpu.empty());
cv::gpu::GpuMat colored(cpu);
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(1);
cv::gpu::Stream s;
cascade.detect(colored, rois, objectBoxes, s);
TEST_CYCLE()
{ {
cv::Mat cpu = readImage (GET_PARAM(1));
ASSERT_FALSE(cpu.empty());
cv::gpu::GpuMat colored(cpu);
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(1);
cv::gpu::Stream s;
cascade.detect(colored, rois, objectBoxes, s); cascade.detect(colored, rois, objectBoxes, s);
TEST_CYCLE()
{
cascade.detect(colored, rois, objectBoxes, s);
}
#ifdef HAVE_CUDA
cudaDeviceSynchronize();
#endif
SANITY_CHECK(sortDetections(objectBoxes));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
#ifdef HAVE_CUDA
cudaDeviceSynchronize();
#endif
SANITY_CHECK(sortDetections(objectBoxes));
} }
NO_CPU(SCascadeTest, detectStream) NO_CPU(SCascadeTest, detectStream)

View File

@ -36,31 +36,23 @@ PERF_TEST_P(ImagePair, Video_BroxOpticalFlow,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(d_frame0, d_frame1, d_u, d_v);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(d_frame0, d_frame1, d_u, d_v); d_flow(d_frame0, d_frame1, d_u, d_v);
TEST_CYCLE()
{
d_flow(d_frame0, d_frame1, d_u, d_v);
}
GPU_SANITY_CHECK(d_u);
GPU_SANITY_CHECK(d_v);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_u);
GPU_SANITY_CHECK(d_v);
} }
else else
{ {
@ -85,39 +77,31 @@ PERF_TEST_P(ImagePair, Video_InterpolateFrames,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_fu, d_fv;
cv::gpu::GpuMat d_bu, d_bv;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(d_frame0, d_frame1, d_fu, d_fv);
d_flow(d_frame1, d_frame0, d_bu, d_bv);
cv::gpu::GpuMat d_newFrame;
cv::gpu::GpuMat d_buf;
cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_fu, d_fv;
cv::gpu::GpuMat d_bu, d_bv;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(d_frame0, d_frame1, d_fu, d_fv);
d_flow(d_frame1, d_frame0, d_bu, d_bv);
cv::gpu::GpuMat d_newFrame;
cv::gpu::GpuMat d_buf;
cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf); cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf);
TEST_CYCLE()
{
cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf);
}
GPU_SANITY_CHECK(d_fu);
GPU_SANITY_CHECK(d_fv);
GPU_SANITY_CHECK(d_bu);
GPU_SANITY_CHECK(d_bv);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_fu);
GPU_SANITY_CHECK(d_fv);
GPU_SANITY_CHECK(d_bu);
GPU_SANITY_CHECK(d_bv);
} }
else else
{ {
@ -142,35 +126,27 @@ PERF_TEST_P(ImagePair, Video_CreateOpticalFlowNeedleMap,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(d_frame0, d_frame1, d_u, d_v);
cv::gpu::GpuMat d_vertex, d_colors;
cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(d_frame0, d_frame1, d_u, d_v);
cv::gpu::GpuMat d_vertex, d_colors;
cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors); cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors);
TEST_CYCLE()
{
cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors);
}
GPU_SANITY_CHECK(d_vertex);
GPU_SANITY_CHECK(d_colors);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_vertex);
GPU_SANITY_CHECK(d_colors);
} }
else else
{ {
@ -194,27 +170,19 @@ PERF_TEST_P(Image_MinDistance, Video_GoodFeaturesToTrack,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(8000, 0.01, minDistance);
cv::gpu::GpuMat d_image(image);
cv::gpu::GpuMat d_pts;
d_detector(d_image, d_pts);
TEST_CYCLE()
{ {
cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(8000, 0.01, minDistance);
cv::gpu::GpuMat d_image(image);
cv::gpu::GpuMat d_pts;
d_detector(d_image, d_pts); d_detector(d_image, d_pts);
TEST_CYCLE()
{
d_detector(d_image, d_pts);
}
GPU_SANITY_CHECK(d_pts);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_pts);
} }
else else
{ {
@ -270,34 +238,26 @@ PERF_TEST_P(ImagePair_Gray_NPts_WinSz_Levels_Iters, Video_PyrLKOpticalFlowSparse
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_pts(pts.reshape(2, 1));
cv::gpu::PyrLKOpticalFlow d_pyrLK;
d_pyrLK.winSize = cv::Size(winSize, winSize);
d_pyrLK.maxLevel = levels - 1;
d_pyrLK.iters = iters;
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_nextPts;
cv::gpu::GpuMat d_status;
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_pts(pts.reshape(2, 1));
cv::gpu::PyrLKOpticalFlow d_pyrLK;
d_pyrLK.winSize = cv::Size(winSize, winSize);
d_pyrLK.maxLevel = levels - 1;
d_pyrLK.iters = iters;
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_nextPts;
cv::gpu::GpuMat d_status;
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status); d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status);
TEST_CYCLE()
{
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status);
}
GPU_SANITY_CHECK(d_status);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_status);
} }
else else
{ {
@ -345,33 +305,25 @@ PERF_TEST_P(ImagePair_WinSz_Levels_Iters, Video_PyrLKOpticalFlowDense, Combine(
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::PyrLKOpticalFlow d_pyrLK;
d_pyrLK.winSize = cv::Size(winSize, winSize);
d_pyrLK.maxLevel = levels - 1;
d_pyrLK.iters = iters;
d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::PyrLKOpticalFlow d_pyrLK;
d_pyrLK.winSize = cv::Size(winSize, winSize);
d_pyrLK.maxLevel = levels - 1;
d_pyrLK.iters = iters;
d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v); d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v);
TEST_CYCLE()
{
d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v);
}
GPU_SANITY_CHECK(d_u);
GPU_SANITY_CHECK(d_v);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_u);
GPU_SANITY_CHECK(d_v);
} }
else else
{ {
@ -403,37 +355,29 @@ PERF_TEST_P(ImagePair, Video_FarnebackOpticalFlow,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::FarnebackOpticalFlow d_farneback;
d_farneback.numLevels = numLevels;
d_farneback.pyrScale = pyrScale;
d_farneback.winSize = winSize;
d_farneback.numIters = numIters;
d_farneback.polyN = polyN;
d_farneback.polySigma = polySigma;
d_farneback.flags = flags;
d_farneback(d_frame0, d_frame1, d_u, d_v);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::FarnebackOpticalFlow d_farneback;
d_farneback.numLevels = numLevels;
d_farneback.pyrScale = pyrScale;
d_farneback.winSize = winSize;
d_farneback.numIters = numIters;
d_farneback.polyN = polyN;
d_farneback.polySigma = polySigma;
d_farneback.flags = flags;
d_farneback(d_frame0, d_frame1, d_u, d_v); d_farneback(d_frame0, d_frame1, d_u, d_v);
TEST_CYCLE()
{
d_farneback(d_frame0, d_frame1, d_u, d_v);
}
GPU_SANITY_CHECK(d_u);
GPU_SANITY_CHECK(d_v);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_u);
GPU_SANITY_CHECK(d_v);
} }
else else
{ {
@ -466,30 +410,22 @@ PERF_TEST_P(ImagePair, Video_OpticalFlowDual_TVL1,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_flowx;
cv::gpu::GpuMat d_flowy;
cv::gpu::OpticalFlowDual_TVL1_GPU d_alg;
d_alg(d_frame0, d_frame1, d_flowx, d_flowy);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_flowx;
cv::gpu::GpuMat d_flowy;
cv::gpu::OpticalFlowDual_TVL1_GPU d_alg;
d_alg(d_frame0, d_frame1, d_flowx, d_flowy); d_alg(d_frame0, d_frame1, d_flowx, d_flowy);
TEST_CYCLE()
{
d_alg(d_frame0, d_frame1, d_flowx, d_flowy);
}
GPU_SANITY_CHECK(d_flowx);
GPU_SANITY_CHECK(d_flowy);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_flowx);
GPU_SANITY_CHECK(d_flowy);
} }
else else
{ {
@ -546,27 +482,19 @@ PERF_TEST_P(ImagePair, Video_OpticalFlowBM,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame0(frame0);
{ cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_frame0(frame0); cv::gpu::GpuMat d_velx, d_vely, buf;
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_velx, d_vely, buf;
cv::gpu::calcOpticalFlowBM(d_frame0, d_frame1, block_size, shift_size, max_range, false, d_velx, d_vely, buf);
TEST_CYCLE()
{
cv::gpu::calcOpticalFlowBM(d_frame0, d_frame1, block_size, shift_size, max_range, false, d_velx, d_vely, buf); cv::gpu::calcOpticalFlowBM(d_frame0, d_frame1, block_size, shift_size, max_range, false, d_velx, d_vely, buf);
TEST_CYCLE()
{
cv::gpu::calcOpticalFlowBM(d_frame0, d_frame1, block_size, shift_size, max_range, false, d_velx, d_vely, buf);
}
GPU_SANITY_CHECK(d_velx);
GPU_SANITY_CHECK(d_vely);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_velx);
GPU_SANITY_CHECK(d_vely);
} }
else else
{ {
@ -601,29 +529,21 @@ PERF_TEST_P(ImagePair, Video_FastOpticalFlowBM,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_velx, d_vely;
cv::gpu::FastOpticalFlowBM fastBM;
fastBM(d_frame0, d_frame1, d_velx, d_vely, max_range.width, block_size.width);
TEST_CYCLE()
{ {
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_velx, d_vely;
cv::gpu::FastOpticalFlowBM fastBM;
fastBM(d_frame0, d_frame1, d_velx, d_vely, max_range.width, block_size.width); fastBM(d_frame0, d_frame1, d_velx, d_vely, max_range.width, block_size.width);
TEST_CYCLE()
{
fastBM(d_frame0, d_frame1, d_velx, d_vely, max_range.width, block_size.width);
}
GPU_SANITY_CHECK(d_velx);
GPU_SANITY_CHECK(d_vely);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_velx);
GPU_SANITY_CHECK(d_vely);
} }
else else
{ {
@ -661,29 +581,21 @@ PERF_TEST_P(Video, DISABLED_Video_FGDStatModel, Values("gpu/video/768x576.avi",
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame(frame);
cv::gpu::FGDStatModel d_model(4);
d_model.create(d_frame);
for (int i = 0; i < 10; ++i)
{ {
cv::gpu::GpuMat d_frame(frame); cap >> frame;
ASSERT_FALSE(frame.empty());
cv::gpu::FGDStatModel d_model(4); d_frame.upload(frame);
d_model.create(d_frame);
for (int i = 0; i < 10; ++i) startTimer(); next();
{ d_model.update(d_frame);
cap >> frame; stopTimer();
ASSERT_FALSE(frame.empty());
d_frame.upload(frame);
startTimer(); next();
d_model.update(d_frame);
stopTimer();
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -737,40 +649,32 @@ PERF_TEST_P(Video_Cn_LearningRate, DISABLED_Video_MOG,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame(frame);
cv::gpu::MOG_GPU d_mog;
cv::gpu::GpuMat d_foreground;
d_mog(d_frame, d_foreground, learningRate);
for (int i = 0; i < 10; ++i)
{ {
cv::gpu::GpuMat d_frame(frame); cap >> frame;
cv::gpu::MOG_GPU d_mog; ASSERT_FALSE(frame.empty());
cv::gpu::GpuMat d_foreground;
d_mog(d_frame, d_foreground, learningRate); if (cn != 3)
for (int i = 0; i < 10; ++i)
{ {
cap >> frame; cv::Mat temp;
ASSERT_FALSE(frame.empty()); if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
if (cn != 3) else
{ cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::Mat temp; cv::swap(temp, frame);
if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
else
cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::swap(temp, frame);
}
d_frame.upload(frame);
startTimer(); next();
d_mog(d_frame, d_foreground, learningRate);
stopTimer();
} }
}
catch (...) d_frame.upload(frame);
{
cv::gpu::resetDevice(); startTimer(); next();
throw; d_mog(d_frame, d_foreground, learningRate);
stopTimer();
} }
} }
else else
@ -833,40 +737,32 @@ PERF_TEST_P(Video_Cn, DISABLED_Video_MOG2,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame(frame);
cv::gpu::MOG2_GPU d_mog2;
cv::gpu::GpuMat d_foreground;
d_mog2(d_frame, d_foreground);
for (int i = 0; i < 10; ++i)
{ {
cv::gpu::GpuMat d_frame(frame); cap >> frame;
cv::gpu::MOG2_GPU d_mog2; ASSERT_FALSE(frame.empty());
cv::gpu::GpuMat d_foreground;
d_mog2(d_frame, d_foreground); if (cn != 3)
for (int i = 0; i < 10; ++i)
{ {
cap >> frame; cv::Mat temp;
ASSERT_FALSE(frame.empty()); if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
if (cn != 3) else
{ cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::Mat temp; cv::swap(temp, frame);
if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
else
cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::swap(temp, frame);
}
d_frame.upload(frame);
startTimer(); next();
d_mog2(d_frame, d_foreground);
stopTimer();
} }
}
catch (...) d_frame.upload(frame);
{
cv::gpu::resetDevice(); startTimer(); next();
throw; d_mog2(d_frame, d_foreground);
stopTimer();
} }
} }
else else
@ -914,47 +810,39 @@ PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame;
cv::gpu::MOG2_GPU d_mog2;
cv::gpu::GpuMat d_foreground;
for (int i = 0; i < 10; ++i)
{ {
cv::gpu::GpuMat d_frame; cap >> frame;
cv::gpu::MOG2_GPU d_mog2; ASSERT_FALSE(frame.empty());
cv::gpu::GpuMat d_foreground;
for (int i = 0; i < 10; ++i) if (cn != 3)
{ {
cap >> frame; cv::Mat temp;
ASSERT_FALSE(frame.empty()); if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
if (cn != 3) else
{ cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::Mat temp; cv::swap(temp, frame);
if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
else
cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::swap(temp, frame);
}
d_frame.upload(frame);
d_mog2(d_frame, d_foreground);
} }
cv::gpu::GpuMat d_background; d_frame.upload(frame);
d_mog2(d_frame, d_foreground);
}
cv::gpu::GpuMat d_background;
d_mog2.getBackgroundImage(d_background);
TEST_CYCLE()
{
d_mog2.getBackgroundImage(d_background); d_mog2.getBackgroundImage(d_background);
TEST_CYCLE()
{
d_mog2.getBackgroundImage(d_background);
}
GPU_SANITY_CHECK(d_background);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_background);
} }
else else
{ {
@ -1019,40 +907,32 @@ PERF_TEST_P(Video_Cn, DISABLED_Video_VIBE,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame(frame);
cv::gpu::VIBE_GPU d_vibe;
cv::gpu::GpuMat d_foreground;
d_vibe(d_frame, d_foreground);
for (int i = 0; i < 10; ++i)
{ {
cv::gpu::GpuMat d_frame(frame); cap >> frame;
cv::gpu::VIBE_GPU d_vibe; ASSERT_FALSE(frame.empty());
cv::gpu::GpuMat d_foreground;
d_vibe(d_frame, d_foreground); if (cn != 3)
for (int i = 0; i < 10; ++i)
{ {
cap >> frame; cv::Mat temp;
ASSERT_FALSE(frame.empty()); if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
if (cn != 3) else
{ cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::Mat temp; cv::swap(temp, frame);
if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
else
cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::swap(temp, frame);
}
d_frame.upload(frame);
startTimer(); next();
d_vibe(d_frame, d_foreground);
stopTimer();
} }
}
catch (...) d_frame.upload(frame);
{
cv::gpu::resetDevice(); startTimer(); next();
throw; d_vibe(d_frame, d_foreground);
stopTimer();
} }
} }
else else
@ -1092,47 +972,39 @@ PERF_TEST_P(Video_Cn_MaxFeatures, DISABLED_Video_GMG,
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::GpuMat d_frame(frame);
cv::gpu::GpuMat d_fgmask;
cv::gpu::GMG_GPU d_gmg;
d_gmg.maxFeatures = maxFeatures;
d_gmg(d_frame, d_fgmask);
for (int i = 0; i < 150; ++i)
{ {
cv::gpu::GpuMat d_frame(frame); cap >> frame;
cv::gpu::GpuMat d_fgmask; if (frame.empty())
cv::gpu::GMG_GPU d_gmg;
d_gmg.maxFeatures = maxFeatures;
d_gmg(d_frame, d_fgmask);
for (int i = 0; i < 150; ++i)
{ {
cap.release();
cap.open(inputFile);
cap >> frame; cap >> frame;
if (frame.empty())
{
cap.release();
cap.open(inputFile);
cap >> frame;
}
if (cn != 3)
{
cv::Mat temp;
if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
else
cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::swap(temp, frame);
}
d_frame.upload(frame);
startTimer(); next();
d_gmg(d_frame, d_fgmask);
stopTimer();
} }
}
catch (...) if (cn != 3)
{ {
cv::gpu::resetDevice(); cv::Mat temp;
throw; if (cn == 1)
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
else
cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
cv::swap(temp, frame);
}
d_frame.upload(frame);
startTimer(); next();
d_gmg(d_frame, d_fgmask);
stopTimer();
} }
} }
else else
@ -1194,31 +1066,23 @@ PERF_TEST_P(Video, Video_VideoWriter, Values("gpu/video/768x576.avi", "gpu/video
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::VideoWriter_GPU d_writer;
cv::gpu::GpuMat d_frame;
for (int i = 0; i < 10; ++i)
{ {
cv::gpu::VideoWriter_GPU d_writer; reader >> frame;
ASSERT_FALSE(frame.empty());
cv::gpu::GpuMat d_frame; d_frame.upload(frame);
for (int i = 0; i < 10; ++i) if (!d_writer.isOpened())
{ d_writer.open(outputFile, frame.size(), FPS);
reader >> frame;
ASSERT_FALSE(frame.empty());
d_frame.upload(frame); startTimer(); next();
d_writer.write(d_frame);
if (!d_writer.isOpened()) stopTimer();
d_writer.open(outputFile, frame.size(), FPS);
startTimer(); next();
d_writer.write(d_frame);
stopTimer();
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
else else
@ -1251,27 +1115,19 @@ PERF_TEST_P(Video, Video_VideoReader, Values("gpu/video/768x576.avi", "gpu/video
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
try cv::gpu::VideoReader_GPU d_reader(inputFile);
ASSERT_TRUE( d_reader.isOpened() );
cv::gpu::GpuMat d_frame;
d_reader.read(d_frame);
TEST_CYCLE_N(10)
{ {
cv::gpu::VideoReader_GPU d_reader(inputFile);
ASSERT_TRUE( d_reader.isOpened() );
cv::gpu::GpuMat d_frame;
d_reader.read(d_frame); d_reader.read(d_frame);
TEST_CYCLE_N(10)
{
d_reader.read(d_frame);
}
GPU_SANITY_CHECK(d_frame);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(d_frame);
} }
else else
{ {

View File

@ -276,8 +276,6 @@ static void devNullOutput(const std::string& msg)
(void)msg; (void)msg;
} }
}
bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel) bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
{ {
path = test_data_path.c_str(); path = test_data_path.c_str();
@ -294,6 +292,8 @@ bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel
return testListerII.invoke(); return testListerII.invoke();
} }
}
bool nvidia_NPPST_Squared_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel) bool nvidia_NPPST_Squared_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel)
{ {
path = test_data_path; path = test_data_path;
@ -439,4 +439,4 @@ bool nvidia_NCV_Visualization(const std::string& test_data_path, OutputLevel out
return testListerVisualize.invoke(); return testListerVisualize.invoke();
} }
#endif /* CUDA_DISABLER */ #endif /* CUDA_DISABLER */

View File

@ -62,28 +62,20 @@ struct StereoBM : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(StereoBM, Regression) TEST_P(StereoBM, Regression)
{ {
try cv::Mat left_image = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE);
{ cv::Mat right_image = readImage("stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE);
cv::Mat left_image = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); cv::Mat disp_gold = readImage("stereobm/aloe-disp.png", cv::IMREAD_GRAYSCALE);
cv::Mat right_image = readImage("stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE);
cv::Mat disp_gold = readImage("stereobm/aloe-disp.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(left_image.empty()); ASSERT_FALSE(left_image.empty());
ASSERT_FALSE(right_image.empty()); ASSERT_FALSE(right_image.empty());
ASSERT_FALSE(disp_gold.empty()); ASSERT_FALSE(disp_gold.empty());
cv::gpu::StereoBM_GPU bm(0, 128, 19); cv::gpu::StereoBM_GPU bm(0, 128, 19);
cv::gpu::GpuMat disp; cv::gpu::GpuMat disp;
bm(loadMat(left_image), loadMat(right_image), disp); bm(loadMat(left_image), loadMat(right_image), disp);
EXPECT_MAT_NEAR(disp_gold, disp, 0.0); EXPECT_MAT_NEAR(disp_gold, disp, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoBM, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoBM, ALL_DEVICES);
@ -105,31 +97,23 @@ struct StereoBeliefPropagation : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(StereoBeliefPropagation, Regression) TEST_P(StereoBeliefPropagation, Regression)
{ {
try cv::Mat left_image = readImage("stereobp/aloe-L.png");
{ cv::Mat right_image = readImage("stereobp/aloe-R.png");
cv::Mat left_image = readImage("stereobp/aloe-L.png"); cv::Mat disp_gold = readImage("stereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE);
cv::Mat right_image = readImage("stereobp/aloe-R.png");
cv::Mat disp_gold = readImage("stereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(left_image.empty()); ASSERT_FALSE(left_image.empty());
ASSERT_FALSE(right_image.empty()); ASSERT_FALSE(right_image.empty());
ASSERT_FALSE(disp_gold.empty()); ASSERT_FALSE(disp_gold.empty());
cv::gpu::StereoBeliefPropagation bp(64, 8, 2, 25, 0.1f, 15, 1, CV_16S); cv::gpu::StereoBeliefPropagation bp(64, 8, 2, 25, 0.1f, 15, 1, CV_16S);
cv::gpu::GpuMat disp; cv::gpu::GpuMat disp;
bp(loadMat(left_image), loadMat(right_image), disp); bp(loadMat(left_image), loadMat(right_image), disp);
cv::Mat h_disp(disp); cv::Mat h_disp(disp);
h_disp.convertTo(h_disp, disp_gold.depth()); h_disp.convertTo(h_disp, disp_gold.depth());
EXPECT_MAT_NEAR(disp_gold, h_disp, 0.0); EXPECT_MAT_NEAR(disp_gold, h_disp, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoBeliefPropagation, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoBeliefPropagation, ALL_DEVICES);
@ -151,37 +135,29 @@ struct StereoConstantSpaceBP : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(StereoConstantSpaceBP, Regression) TEST_P(StereoConstantSpaceBP, Regression)
{ {
try cv::Mat left_image = readImage("csstereobp/aloe-L.png");
{ cv::Mat right_image = readImage("csstereobp/aloe-R.png");
cv::Mat left_image = readImage("csstereobp/aloe-L.png");
cv::Mat right_image = readImage("csstereobp/aloe-R.png");
cv::Mat disp_gold; cv::Mat disp_gold;
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20)) if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
disp_gold = readImage("csstereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE); disp_gold = readImage("csstereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE);
else else
disp_gold = readImage("csstereobp/aloe-disp_CC1X.png", cv::IMREAD_GRAYSCALE); disp_gold = readImage("csstereobp/aloe-disp_CC1X.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(left_image.empty()); ASSERT_FALSE(left_image.empty());
ASSERT_FALSE(right_image.empty()); ASSERT_FALSE(right_image.empty());
ASSERT_FALSE(disp_gold.empty()); ASSERT_FALSE(disp_gold.empty());
cv::gpu::StereoConstantSpaceBP csbp(128, 16, 4, 4); cv::gpu::StereoConstantSpaceBP csbp(128, 16, 4, 4);
cv::gpu::GpuMat disp; cv::gpu::GpuMat disp;
csbp(loadMat(left_image), loadMat(right_image), disp); csbp(loadMat(left_image), loadMat(right_image), disp);
cv::Mat h_disp(disp); cv::Mat h_disp(disp);
h_disp.convertTo(h_disp, disp_gold.depth()); h_disp.convertTo(h_disp, disp_gold.depth());
EXPECT_MAT_NEAR(disp_gold, h_disp, 1.0); EXPECT_MAT_NEAR(disp_gold, h_disp, 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoConstantSpaceBP, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoConstantSpaceBP, ALL_DEVICES);
@ -203,40 +179,32 @@ struct TransformPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(TransformPoints, Accuracy) TEST_P(TransformPoints, Accuracy)
{ {
try cv::Mat src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10);
cv::Mat rvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat tvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::gpu::GpuMat dst;
cv::gpu::transformPoints(loadMat(src), rvec, tvec, dst);
ASSERT_EQ(src.size(), dst.size());
ASSERT_EQ(src.type(), dst.type());
cv::Mat h_dst(dst);
cv::Mat rot;
cv::Rodrigues(rvec, rot);
for (int i = 0; i < h_dst.cols; ++i)
{ {
cv::Mat src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10); cv::Point3f res = h_dst.at<cv::Point3f>(0, i);
cv::Mat rvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat tvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::gpu::GpuMat dst; cv::Point3f p = src.at<cv::Point3f>(0, i);
cv::gpu::transformPoints(loadMat(src), rvec, tvec, dst); cv::Point3f res_gold(
rot.at<float>(0, 0) * p.x + rot.at<float>(0, 1) * p.y + rot.at<float>(0, 2) * p.z + tvec.at<float>(0, 0),
rot.at<float>(1, 0) * p.x + rot.at<float>(1, 1) * p.y + rot.at<float>(1, 2) * p.z + tvec.at<float>(0, 1),
rot.at<float>(2, 0) * p.x + rot.at<float>(2, 1) * p.y + rot.at<float>(2, 2) * p.z + tvec.at<float>(0, 2));
ASSERT_EQ(src.size(), dst.size()); ASSERT_POINT3_NEAR(res_gold, res, 1e-5);
ASSERT_EQ(src.type(), dst.type());
cv::Mat h_dst(dst);
cv::Mat rot;
cv::Rodrigues(rvec, rot);
for (int i = 0; i < h_dst.cols; ++i)
{
cv::Point3f res = h_dst.at<cv::Point3f>(0, i);
cv::Point3f p = src.at<cv::Point3f>(0, i);
cv::Point3f res_gold(
rot.at<float>(0, 0) * p.x + rot.at<float>(0, 1) * p.y + rot.at<float>(0, 2) * p.z + tvec.at<float>(0, 0),
rot.at<float>(1, 0) * p.x + rot.at<float>(1, 1) * p.y + rot.at<float>(1, 2) * p.z + tvec.at<float>(0, 1),
rot.at<float>(2, 0) * p.x + rot.at<float>(2, 1) * p.y + rot.at<float>(2, 2) * p.z + tvec.at<float>(0, 2));
ASSERT_POINT3_NEAR(res_gold, res, 1e-5);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
@ -259,42 +227,34 @@ struct ProjectPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(ProjectPoints, Accuracy) TEST_P(ProjectPoints, Accuracy)
{ {
try cv::Mat src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10);
cv::Mat rvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat tvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1);
camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(2, 1) = 0.f;
cv::gpu::GpuMat dst;
cv::gpu::projectPoints(loadMat(src), rvec, tvec, camera_mat, cv::Mat(), dst);
ASSERT_EQ(1, dst.rows);
ASSERT_EQ(MatType(CV_32FC2), MatType(dst.type()));
std::vector<cv::Point2f> dst_gold;
cv::projectPoints(src, rvec, tvec, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), dst_gold);
ASSERT_EQ(dst_gold.size(), static_cast<size_t>(dst.cols));
cv::Mat h_dst(dst);
for (size_t i = 0; i < dst_gold.size(); ++i)
{ {
cv::Mat src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10); cv::Point2f res = h_dst.at<cv::Point2f>(0, (int)i);
cv::Mat rvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1); cv::Point2f res_gold = dst_gold[i];
cv::Mat tvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1);
camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(2, 1) = 0.f;
cv::gpu::GpuMat dst; ASSERT_LE(cv::norm(res_gold - res) / cv::norm(res_gold), 1e-3f);
cv::gpu::projectPoints(loadMat(src), rvec, tvec, camera_mat, cv::Mat(), dst);
ASSERT_EQ(1, dst.rows);
ASSERT_EQ(MatType(CV_32FC2), MatType(dst.type()));
std::vector<cv::Point2f> dst_gold;
cv::projectPoints(src, rvec, tvec, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), dst_gold);
ASSERT_EQ(dst_gold.size(), static_cast<size_t>(dst.cols));
cv::Mat h_dst(dst);
for (size_t i = 0; i < dst_gold.size(); ++i)
{
cv::Point2f res = h_dst.at<cv::Point2f>(0, (int)i);
cv::Point2f res_gold = dst_gold[i];
ASSERT_LE(cv::norm(res_gold - res) / cv::norm(res_gold), 1e-3f);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
@ -317,36 +277,28 @@ struct SolvePnPRansac : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(SolvePnPRansac, Accuracy) TEST_P(SolvePnPRansac, Accuracy)
{ {
try cv::Mat object = randomMat(cv::Size(5000, 1), CV_32FC3, 0, 100);
{ cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1);
cv::Mat object = randomMat(cv::Size(5000, 1), CV_32FC3, 0, 100); camera_mat.at<float>(0, 1) = 0.f;
cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1); camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(0, 1) = 0.f; camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(1, 0) = 0.f; camera_mat.at<float>(2, 1) = 0.f;
camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(2, 1) = 0.f;
std::vector<cv::Point2f> image_vec; std::vector<cv::Point2f> image_vec;
cv::Mat rvec_gold; cv::Mat rvec_gold;
cv::Mat tvec_gold; cv::Mat tvec_gold;
rvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1); rvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
tvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1); tvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), image_vec); cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), image_vec);
cv::Mat rvec, tvec; cv::Mat rvec, tvec;
std::vector<int> inliers; std::vector<int> inliers;
cv::gpu::solvePnPRansac(object, cv::Mat(1, (int)image_vec.size(), CV_32FC2, &image_vec[0]), cv::gpu::solvePnPRansac(object, cv::Mat(1, (int)image_vec.size(), CV_32FC2, &image_vec[0]),
camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)),
rvec, tvec, false, 200, 2.f, 100, &inliers); rvec, tvec, false, 200, 2.f, 100, &inliers);
ASSERT_LE(cv::norm(rvec - rvec_gold), 1e-3); ASSERT_LE(cv::norm(rvec - rvec_gold), 1e-3);
ASSERT_LE(cv::norm(tvec - tvec_gold), 1e-3); ASSERT_LE(cv::norm(tvec - tvec_gold), 1e-3);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, SolvePnPRansac, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Calib3D, SolvePnPRansac, ALL_DEVICES);
@ -374,24 +326,16 @@ PARAM_TEST_CASE(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth, Use
TEST_P(ReprojectImageTo3D, Accuracy) TEST_P(ReprojectImageTo3D, Accuracy)
{ {
try cv::Mat disp = randomMat(size, depth, 5.0, 30.0);
{ cv::Mat Q = randomMat(cv::Size(4, 4), CV_32FC1, 0.1, 1.0);
cv::Mat disp = randomMat(size, depth, 5.0, 30.0);
cv::Mat Q = randomMat(cv::Size(4, 4), CV_32FC1, 0.1, 1.0);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::reprojectImageTo3D(loadMat(disp, useRoi), dst, Q, 3); cv::gpu::reprojectImageTo3D(loadMat(disp, useRoi), dst, Q, 3);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::reprojectImageTo3D(disp, dst_gold, Q, false); cv::reprojectImageTo3D(disp, dst_gold, Q, false);
EXPECT_MAT_NEAR(dst_gold, dst, 1e-5); EXPECT_MAT_NEAR(dst_gold, dst, 1e-5);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, ReprojectImageTo3D, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Calib3D, ReprojectImageTo3D, testing::Combine(

File diff suppressed because it is too large Load Diff

View File

@ -71,24 +71,16 @@ PARAM_TEST_CASE(CopyMakeBorder, cv::gpu::DeviceInfo, cv::Size, MatType, Border,
TEST_P(CopyMakeBorder, Accuracy) TEST_P(CopyMakeBorder, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ cv::Scalar val = randomScalar(0, 255);
cv::Mat src = randomMat(size, type);
cv::Scalar val = randomScalar(0, 255);
cv::gpu::GpuMat dst = createMat(cv::Size(size.width + 2 * border, size.height + 2 * border), type, useRoi); cv::gpu::GpuMat dst = createMat(cv::Size(size.width + 2 * border, size.height + 2 * border), type, useRoi);
cv::gpu::copyMakeBorder(loadMat(src, useRoi), dst, border, border, border, border, borderType, val); cv::gpu::copyMakeBorder(loadMat(src, useRoi), dst, border, border, border, border, borderType, val);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::copyMakeBorder(src, dst_gold, border, border, border, border, borderType, val); cv::copyMakeBorder(src, dst_gold, border, border, border, border, borderType, val);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CopyMakeBorder, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CopyMakeBorder, testing::Combine(

File diff suppressed because it is too large Load Diff

View File

@ -71,25 +71,17 @@ PARAM_TEST_CASE(BilateralFilter, cv::gpu::DeviceInfo, cv::Size, MatType)
TEST_P(BilateralFilter, Accuracy) TEST_P(BilateralFilter, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
src.convertTo(src, type); src.convertTo(src, type);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::bilateralFilter(loadMat(src), dst, kernel_size, sigma_color, sigma_spatial); cv::gpu::bilateralFilter(loadMat(src), dst, kernel_size, sigma_color, sigma_spatial);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::bilateralFilter(src, dst_gold, kernel_size, sigma_color, sigma_spatial); cv::bilateralFilter(src, dst_gold, kernel_size, sigma_color, sigma_spatial);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Denoising, BilateralFilter, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Denoising, BilateralFilter, testing::Combine(
@ -115,41 +107,35 @@ struct BruteForceNonLocalMeans: testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(BruteForceNonLocalMeans, Regression) TEST_P(BruteForceNonLocalMeans, Regression)
{ {
try using cv::gpu::GpuMat;
{
using cv::gpu::GpuMat;
cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR); cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);
ASSERT_FALSE(bgr.empty()); ASSERT_FALSE(bgr.empty());
cv::Mat gray; cv::Mat gray;
cv::cvtColor(bgr, gray, CV_BGR2GRAY); cv::cvtColor(bgr, gray, CV_BGR2GRAY);
GpuMat dbgr, dgray; GpuMat dbgr, dgray;
cv::gpu::nonLocalMeans(GpuMat(bgr), dbgr, 20); cv::gpu::nonLocalMeans(GpuMat(bgr), dbgr, 20);
cv::gpu::nonLocalMeans(GpuMat(gray), dgray, 20); cv::gpu::nonLocalMeans(GpuMat(gray), dgray, 20);
#if 0 #if 0
dumpImage("denoising/nlm_denoised_lena_bgr.png", cv::Mat(dbgr)); dumpImage("denoising/nlm_denoised_lena_bgr.png", cv::Mat(dbgr));
dumpImage("denoising/nlm_denoised_lena_gray.png", cv::Mat(dgray)); dumpImage("denoising/nlm_denoised_lena_gray.png", cv::Mat(dgray));
#endif #endif
cv::Mat bgr_gold = readImage("denoising/nlm_denoised_lena_bgr.png", cv::IMREAD_COLOR); cv::Mat bgr_gold = readImage("denoising/nlm_denoised_lena_bgr.png", cv::IMREAD_COLOR);
cv::Mat gray_gold = readImage("denoising/nlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE); cv::Mat gray_gold = readImage("denoising/nlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty()); ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());
EXPECT_MAT_NEAR(bgr_gold, dbgr, 1e-4); EXPECT_MAT_NEAR(bgr_gold, dbgr, 1e-4);
EXPECT_MAT_NEAR(gray_gold, dgray, 1e-4); EXPECT_MAT_NEAR(gray_gold, dgray, 1e-4);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Denoising, BruteForceNonLocalMeans, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Denoising, BruteForceNonLocalMeans, ALL_DEVICES);
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// Fast Force Non local means // Fast Force Non local means
@ -166,41 +152,34 @@ struct FastNonLocalMeans: testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(FastNonLocalMeans, Regression) TEST_P(FastNonLocalMeans, Regression)
{ {
try using cv::gpu::GpuMat;
{
using cv::gpu::GpuMat;
cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR); cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);
ASSERT_FALSE(bgr.empty()); ASSERT_FALSE(bgr.empty());
cv::Mat gray; cv::Mat gray;
cv::cvtColor(bgr, gray, CV_BGR2GRAY); cv::cvtColor(bgr, gray, CV_BGR2GRAY);
GpuMat dbgr, dgray; GpuMat dbgr, dgray;
cv::gpu::FastNonLocalMeansDenoising fnlmd; cv::gpu::FastNonLocalMeansDenoising fnlmd;
fnlmd.simpleMethod(GpuMat(gray), dgray, 20); fnlmd.simpleMethod(GpuMat(gray), dgray, 20);
fnlmd.labMethod(GpuMat(bgr), dbgr, 20, 10); fnlmd.labMethod(GpuMat(bgr), dbgr, 20, 10);
#if 0 #if 0
//dumpImage("denoising/fnlm_denoised_lena_bgr.png", cv::Mat(dbgr)); //dumpImage("denoising/fnlm_denoised_lena_bgr.png", cv::Mat(dbgr));
//dumpImage("denoising/fnlm_denoised_lena_gray.png", cv::Mat(dgray)); //dumpImage("denoising/fnlm_denoised_lena_gray.png", cv::Mat(dgray));
#endif #endif
cv::Mat bgr_gold = readImage("denoising/fnlm_denoised_lena_bgr.png", cv::IMREAD_COLOR); cv::Mat bgr_gold = readImage("denoising/fnlm_denoised_lena_bgr.png", cv::IMREAD_COLOR);
cv::Mat gray_gold = readImage("denoising/fnlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE); cv::Mat gray_gold = readImage("denoising/fnlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty()); ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());
EXPECT_MAT_NEAR(bgr_gold, dbgr, 1); EXPECT_MAT_NEAR(bgr_gold, dbgr, 1);
EXPECT_MAT_NEAR(gray_gold, dgray, 1); EXPECT_MAT_NEAR(gray_gold, dgray, 1);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Denoising, FastNonLocalMeans, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_Denoising, FastNonLocalMeans, ALL_DEVICES);
#endif // HAVE_CUDA #endif // HAVE_CUDA

View File

@ -180,19 +180,31 @@ PARAM_TEST_CASE(SURF, cv::gpu::DeviceInfo, SURF_HessianThreshold, SURF_Octaves,
TEST_P(SURF, Detector) TEST_P(SURF, Detector)
{ {
try 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;
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
{
try
{
std::vector<cv::KeyPoint> keypoints;
surf(loadMat(image), cv::gpu::GpuMat(), keypoints);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsNotImplemented, e.code);
}
}
else
{ {
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;
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;
surf(loadMat(image), cv::gpu::GpuMat(), keypoints); surf(loadMat(image), cv::gpu::GpuMat(), keypoints);
@ -212,31 +224,38 @@ TEST_P(SURF, Detector)
EXPECT_GT(matchedRatio, 0.95); EXPECT_GT(matchedRatio, 0.95);
} }
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(SURF, Detector_Masked) TEST_P(SURF, Detector_Masked)
{ {
try 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
{ {
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;
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;
surf(loadMat(image), loadMat(mask), keypoints); surf(loadMat(image), loadMat(mask), keypoints);
@ -256,35 +275,43 @@ TEST_P(SURF, Detector_Masked)
EXPECT_GT(matchedRatio, 0.95); EXPECT_GT(matchedRatio, 0.95);
} }
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(SURF, Descriptor) TEST_P(SURF, Descriptor)
{ {
try 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
{ {
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;
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;
surf_gold(image, cv::noArray(), keypoints); surf_gold(image, cv::noArray(), keypoints);
@ -303,11 +330,6 @@ TEST_P(SURF, Descriptor)
EXPECT_GT(matchedRatio, 0.6); EXPECT_GT(matchedRatio, 0.6);
} }
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Features2D, SURF, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Features2D, SURF, testing::Combine(
@ -342,14 +364,26 @@ PARAM_TEST_CASE(FAST, cv::gpu::DeviceInfo, FAST_Threshold, FAST_NonmaxSupression
TEST_P(FAST, Accuracy) TEST_P(FAST, Accuracy)
{ {
try cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(image.empty());
cv::gpu::FAST_GPU fast(threshold);
fast.nonmaxSupression = nonmaxSupression;
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
{
try
{
std::vector<cv::KeyPoint> keypoints;
fast(loadMat(image), cv::gpu::GpuMat(), keypoints);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsNotImplemented, e.code);
}
}
else
{ {
cv::Mat image = readImage("features2d/aloe.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(image.empty());
cv::gpu::FAST_GPU fast(threshold);
fast.nonmaxSupression = nonmaxSupression;
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;
fast(loadMat(image), cv::gpu::GpuMat(), keypoints); fast(loadMat(image), cv::gpu::GpuMat(), keypoints);
@ -358,11 +392,6 @@ TEST_P(FAST, Accuracy)
ASSERT_KEYPOINTS_EQ(keypoints_gold, keypoints); ASSERT_KEYPOINTS_EQ(keypoints_gold, keypoints);
} }
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Features2D, FAST, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Features2D, FAST, testing::Combine(
@ -416,17 +445,30 @@ PARAM_TEST_CASE(ORB, cv::gpu::DeviceInfo, ORB_FeaturesCount, ORB_ScaleFactor, OR
TEST_P(ORB, Accuracy) TEST_P(ORB, Accuracy)
{ {
try 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::ORB_GPU orb(nFeatures, scaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize);
orb.blurForDescriptor = blurForDescriptor;
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
{
try
{
std::vector<cv::KeyPoint> keypoints;
cv::gpu::GpuMat descriptors;
orb(loadMat(image), loadMat(mask), keypoints, descriptors);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsNotImplemented, e.code);
}
}
else
{ {
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::ORB_GPU orb(nFeatures, scaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize);
orb.blurForDescriptor = blurForDescriptor;
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;
cv::gpu::GpuMat descriptors; cv::gpu::GpuMat descriptors;
orb(loadMat(image), loadMat(mask), keypoints, descriptors); orb(loadMat(image), loadMat(mask), keypoints, descriptors);
@ -446,11 +488,6 @@ TEST_P(ORB, Accuracy)
EXPECT_GT(matchedRatio, 0.35); EXPECT_GT(matchedRatio, 0.35);
} }
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Features2D, ORB, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Features2D, ORB, testing::Combine(
@ -533,156 +570,307 @@ PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, NormCode, DescriptorSize
TEST_P(BruteForceMatcher, Match_Single) TEST_P(BruteForceMatcher, Match_Single)
{ {
try cv::gpu::BFMatcher_GPU matcher(normCode);
cv::gpu::GpuMat mask;
if (useMask)
{ {
cv::gpu::BFMatcher_GPU matcher(normCode); mask.create(query.rows, train.rows, CV_8UC1);
mask.setTo(cv::Scalar::all(1));
cv::gpu::GpuMat mask;
if (useMask)
{
mask.create(query.rows, train.rows, CV_8UC1);
mask.setTo(cv::Scalar::all(1));
}
std::vector<cv::DMatch> matches;
matcher.match(loadMat(query), loadMat(train), matches, mask);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
for (size_t i = 0; i < matches.size(); i++)
{
cv::DMatch match = matches[i];
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor) || (match.imgIdx != 0))
badCount++;
}
ASSERT_EQ(0, badCount);
} }
catch (...)
std::vector<cv::DMatch> matches;
matcher.match(loadMat(query), loadMat(train), matches, mask);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
for (size_t i = 0; i < matches.size(); i++)
{ {
cv::gpu::resetDevice(); cv::DMatch match = matches[i];
throw; if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor) || (match.imgIdx != 0))
badCount++;
} }
ASSERT_EQ(0, badCount);
} }
TEST_P(BruteForceMatcher, Match_Collection) TEST_P(BruteForceMatcher, Match_Collection)
{ {
try cv::gpu::BFMatcher_GPU matcher(normCode);
cv::gpu::GpuMat d_train(train);
// make add() twice to test such case
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal)
std::vector<cv::gpu::GpuMat> masks(2);
for (int mi = 0; mi < 2; mi++)
{ {
cv::gpu::BFMatcher_GPU matcher(normCode); masks[mi] = cv::gpu::GpuMat(query.rows, train.rows/2, CV_8UC1, cv::Scalar::all(1));
for (int di = 0; di < queryDescCount/2; di++)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
}
cv::gpu::GpuMat d_train(train); std::vector<cv::DMatch> matches;
if (useMask)
matcher.match(cv::gpu::GpuMat(query), matches, masks);
else
matcher.match(cv::gpu::GpuMat(query), matches);
// make add() twice to test such case ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal) int badCount = 0;
std::vector<cv::gpu::GpuMat> masks(2); int shift = useMask ? 1 : 0;
for (int mi = 0; mi < 2; mi++) for (size_t i = 0; i < matches.size(); i++)
{
cv::DMatch match = matches[i];
if ((int)i < queryDescCount / 2)
{ {
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows/2, CV_8UC1, cv::Scalar::all(1)); bool validQueryIdx = (match.queryIdx == (int)i);
for (int di = 0; di < queryDescCount/2; di++) bool validTrainIdx = (match.trainIdx == (int)i * countFactor + shift);
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0)); bool validImgIdx = (match.imgIdx == 0);
if (!validQueryIdx || !validTrainIdx || !validImgIdx)
badCount++;
} }
std::vector<cv::DMatch> matches;
if (useMask)
matcher.match(cv::gpu::GpuMat(query), matches, masks);
else else
matcher.match(cv::gpu::GpuMat(query), matches);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
int shift = useMask ? 1 : 0;
for (size_t i = 0; i < matches.size(); i++)
{ {
cv::DMatch match = matches[i]; bool validQueryIdx = (match.queryIdx == (int)i);
bool validTrainIdx = (match.trainIdx == ((int)i - queryDescCount / 2) * countFactor + shift);
if ((int)i < queryDescCount / 2) bool validImgIdx = (match.imgIdx == 1);
{ if (!validQueryIdx || !validTrainIdx || !validImgIdx)
bool validQueryIdx = (match.queryIdx == (int)i); badCount++;
bool validTrainIdx = (match.trainIdx == (int)i * countFactor + shift);
bool validImgIdx = (match.imgIdx == 0);
if (!validQueryIdx || !validTrainIdx || !validImgIdx)
badCount++;
}
else
{
bool validQueryIdx = (match.queryIdx == (int)i);
bool validTrainIdx = (match.trainIdx == ((int)i - queryDescCount / 2) * countFactor + shift);
bool validImgIdx = (match.imgIdx == 1);
if (!validQueryIdx || !validTrainIdx || !validImgIdx)
badCount++;
}
} }
}
ASSERT_EQ(0, badCount); ASSERT_EQ(0, badCount);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(BruteForceMatcher, KnnMatch_2_Single) TEST_P(BruteForceMatcher, KnnMatch_2_Single)
{ {
try cv::gpu::BFMatcher_GPU matcher(normCode);
const int knn = 2;
cv::gpu::GpuMat mask;
if (useMask)
{ {
cv::gpu::BFMatcher_GPU matcher(normCode); mask.create(query.rows, train.rows, CV_8UC1);
mask.setTo(cv::Scalar::all(1));
}
const int knn = 2; std::vector< std::vector<cv::DMatch> > matches;
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn, mask);
cv::gpu::GpuMat mask; ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
if (useMask)
int badCount = 0;
for (size_t i = 0; i < matches.size(); i++)
{
if ((int)matches[i].size() != knn)
badCount++;
else
{ {
mask.create(query.rows, train.rows, CV_8UC1); int localBadCount = 0;
mask.setTo(cv::Scalar::all(1)); for (int k = 0; k < knn; k++)
}
std::vector< std::vector<cv::DMatch> > matches;
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn, mask);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
for (size_t i = 0; i < matches.size(); i++)
{
if ((int)matches[i].size() != knn)
badCount++;
else
{ {
int localBadCount = 0; cv::DMatch match = matches[i][k];
for (int k = 0; k < knn; k++) if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k) || (match.imgIdx != 0))
{ localBadCount++;
cv::DMatch match = matches[i][k];
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k) || (match.imgIdx != 0))
localBadCount++;
}
badCount += localBadCount > 0 ? 1 : 0;
} }
badCount += localBadCount > 0 ? 1 : 0;
} }
}
ASSERT_EQ(0, badCount); ASSERT_EQ(0, badCount);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(BruteForceMatcher, KnnMatch_3_Single) TEST_P(BruteForceMatcher, KnnMatch_3_Single)
{ {
try cv::gpu::BFMatcher_GPU matcher(normCode);
const int knn = 3;
cv::gpu::GpuMat mask;
if (useMask)
{ {
cv::gpu::BFMatcher_GPU matcher(normCode); mask.create(query.rows, train.rows, CV_8UC1);
mask.setTo(cv::Scalar::all(1));
}
const int knn = 3; std::vector< std::vector<cv::DMatch> > matches;
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn, mask);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
for (size_t i = 0; i < matches.size(); i++)
{
if ((int)matches[i].size() != knn)
badCount++;
else
{
int localBadCount = 0;
for (int k = 0; k < knn; k++)
{
cv::DMatch match = matches[i][k];
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k) || (match.imgIdx != 0))
localBadCount++;
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
ASSERT_EQ(0, badCount);
}
TEST_P(BruteForceMatcher, KnnMatch_2_Collection)
{
cv::gpu::BFMatcher_GPU matcher(normCode);
const int knn = 2;
cv::gpu::GpuMat d_train(train);
// make add() twice to test such case
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal)
std::vector<cv::gpu::GpuMat> masks(2);
for (int mi = 0; mi < 2; mi++ )
{
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1));
for (int di = 0; di < queryDescCount / 2; di++)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
}
std::vector< std::vector<cv::DMatch> > matches;
if (useMask)
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks);
else
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
int shift = useMask ? 1 : 0;
for (size_t i = 0; i < matches.size(); i++)
{
if ((int)matches[i].size() != knn)
badCount++;
else
{
int localBadCount = 0;
for (int k = 0; k < knn; k++)
{
cv::DMatch match = matches[i][k];
{
if ((int)i < queryDescCount / 2)
{
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k + shift) || (match.imgIdx != 0) )
localBadCount++;
}
else
{
if ((match.queryIdx != (int)i) || (match.trainIdx != ((int)i - queryDescCount / 2) * countFactor + k + shift) || (match.imgIdx != 1) )
localBadCount++;
}
}
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
ASSERT_EQ(0, badCount);
}
TEST_P(BruteForceMatcher, KnnMatch_3_Collection)
{
cv::gpu::BFMatcher_GPU matcher(normCode);
const int knn = 3;
cv::gpu::GpuMat d_train(train);
// make add() twice to test such case
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal)
std::vector<cv::gpu::GpuMat> masks(2);
for (int mi = 0; mi < 2; mi++ )
{
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1));
for (int di = 0; di < queryDescCount / 2; di++)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
}
std::vector< std::vector<cv::DMatch> > matches;
if (useMask)
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks);
else
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
int shift = useMask ? 1 : 0;
for (size_t i = 0; i < matches.size(); i++)
{
if ((int)matches[i].size() != knn)
badCount++;
else
{
int localBadCount = 0;
for (int k = 0; k < knn; k++)
{
cv::DMatch match = matches[i][k];
{
if ((int)i < queryDescCount / 2)
{
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k + shift) || (match.imgIdx != 0) )
localBadCount++;
}
else
{
if ((match.queryIdx != (int)i) || (match.trainIdx != ((int)i - queryDescCount / 2) * countFactor + k + shift) || (match.imgIdx != 1) )
localBadCount++;
}
}
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
ASSERT_EQ(0, badCount);
}
TEST_P(BruteForceMatcher, RadiusMatch_Single)
{
cv::gpu::BFMatcher_GPU matcher(normCode);
const float radius = 1.f / countFactor;
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
{
try
{
std::vector< std::vector<cv::DMatch> > matches;
matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsNotImplemented, e.code);
}
}
else
{
cv::gpu::GpuMat mask; cv::gpu::GpuMat mask;
if (useMask) if (useMask)
{ {
@ -691,258 +879,63 @@ TEST_P(BruteForceMatcher, KnnMatch_3_Single)
} }
std::vector< std::vector<cv::DMatch> > matches; std::vector< std::vector<cv::DMatch> > matches;
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn, mask); matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius, mask);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size()); ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0; int badCount = 0;
for (size_t i = 0; i < matches.size(); i++) for (size_t i = 0; i < matches.size(); i++)
{ {
if ((int)matches[i].size() != knn) if ((int)matches[i].size() != 1)
badCount++; badCount++;
else else
{ {
int localBadCount = 0; cv::DMatch match = matches[i][0];
for (int k = 0; k < knn; k++) if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor) || (match.imgIdx != 0))
{
cv::DMatch match = matches[i][k];
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k) || (match.imgIdx != 0))
localBadCount++;
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
ASSERT_EQ(0, badCount);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
}
TEST_P(BruteForceMatcher, KnnMatch_2_Collection)
{
try
{
cv::gpu::BFMatcher_GPU matcher(normCode);
const int knn = 2;
cv::gpu::GpuMat d_train(train);
// make add() twice to test such case
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal)
std::vector<cv::gpu::GpuMat> masks(2);
for (int mi = 0; mi < 2; mi++ )
{
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1));
for (int di = 0; di < queryDescCount / 2; di++)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
}
std::vector< std::vector<cv::DMatch> > matches;
if (useMask)
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks);
else
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
int shift = useMask ? 1 : 0;
for (size_t i = 0; i < matches.size(); i++)
{
if ((int)matches[i].size() != knn)
badCount++;
else
{
int localBadCount = 0;
for (int k = 0; k < knn; k++)
{
cv::DMatch match = matches[i][k];
{
if ((int)i < queryDescCount / 2)
{
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k + shift) || (match.imgIdx != 0) )
localBadCount++;
}
else
{
if ((match.queryIdx != (int)i) || (match.trainIdx != ((int)i - queryDescCount / 2) * countFactor + k + shift) || (match.imgIdx != 1) )
localBadCount++;
}
}
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
ASSERT_EQ(0, badCount);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
}
TEST_P(BruteForceMatcher, KnnMatch_3_Collection)
{
try
{
cv::gpu::BFMatcher_GPU matcher(normCode);
const int knn = 3;
cv::gpu::GpuMat d_train(train);
// make add() twice to test such case
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal)
std::vector<cv::gpu::GpuMat> masks(2);
for (int mi = 0; mi < 2; mi++ )
{
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1));
for (int di = 0; di < queryDescCount / 2; di++)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
}
std::vector< std::vector<cv::DMatch> > matches;
if (useMask)
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn, masks);
else
matcher.knnMatch(cv::gpu::GpuMat(query), matches, knn);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
int shift = useMask ? 1 : 0;
for (size_t i = 0; i < matches.size(); i++)
{
if ((int)matches[i].size() != knn)
badCount++;
else
{
int localBadCount = 0;
for (int k = 0; k < knn; k++)
{
cv::DMatch match = matches[i][k];
{
if ((int)i < queryDescCount / 2)
{
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i * countFactor + k + shift) || (match.imgIdx != 0) )
localBadCount++;
}
else
{
if ((match.queryIdx != (int)i) || (match.trainIdx != ((int)i - queryDescCount / 2) * countFactor + k + shift) || (match.imgIdx != 1) )
localBadCount++;
}
}
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
ASSERT_EQ(0, badCount);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
}
TEST_P(BruteForceMatcher, RadiusMatch_Single)
{
try
{
cv::gpu::BFMatcher_GPU matcher(normCode);
const float radius = 1.f / countFactor;
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
{
try
{
std::vector< std::vector<cv::DMatch> > matches;
matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsNotImplemented, e.code);
}
}
else
{
cv::gpu::GpuMat mask;
if (useMask)
{
mask.create(query.rows, train.rows, CV_8UC1);
mask.setTo(cv::Scalar::all(1));
}
std::vector< std::vector<cv::DMatch> > matches;
matcher.radiusMatch(loadMat(query), loadMat(train), matches, radius, mask);
ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());
int badCount = 0;
for (size_t i = 0; i < matches.size(); i++)
{
if ((int)matches[i].size() != 1)
badCount++; badCount++;
else
{
cv::DMatch match = matches[i][0];
if ((match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor) || (match.imgIdx != 0))
badCount++;
}
} }
ASSERT_EQ(0, badCount);
} }
}
catch (...) ASSERT_EQ(0, badCount);
{
cv::gpu::resetDevice();
throw;
} }
} }
TEST_P(BruteForceMatcher, RadiusMatch_Collection) TEST_P(BruteForceMatcher, RadiusMatch_Collection)
{ {
try cv::gpu::BFMatcher_GPU matcher(normCode);
const int n = 3;
const float radius = 1.f / countFactor * n;
cv::gpu::GpuMat d_train(train);
// make add() twice to test such case
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal)
std::vector<cv::gpu::GpuMat> masks(2);
for (int mi = 0; mi < 2; mi++)
{ {
cv::gpu::BFMatcher_GPU matcher(normCode); masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1));
for (int di = 0; di < queryDescCount / 2; di++)
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
}
const int n = 3; if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
const float radius = 1.f / countFactor * n; {
try
cv::gpu::GpuMat d_train(train);
// make add() twice to test such case
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(0, train.rows / 2)));
matcher.add(std::vector<cv::gpu::GpuMat>(1, d_train.rowRange(train.rows / 2, train.rows)));
// prepare masks (make first nearest match illegal)
std::vector<cv::gpu::GpuMat> masks(2);
for (int mi = 0; mi < 2; mi++)
{ {
masks[mi] = cv::gpu::GpuMat(query.rows, train.rows / 2, CV_8UC1, cv::Scalar::all(1)); std::vector< std::vector<cv::DMatch> > matches;
for (int di = 0; di < queryDescCount / 2; di++) matcher.radiusMatch(cv::gpu::GpuMat(query), matches, radius, masks);
masks[mi].col(di * countFactor).setTo(cv::Scalar::all(0));
} }
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsNotImplemented, e.code);
}
}
else
{
std::vector< std::vector<cv::DMatch> > matches; std::vector< std::vector<cv::DMatch> > matches;
if (useMask) if (useMask)
@ -984,11 +977,6 @@ TEST_P(BruteForceMatcher, RadiusMatch_Collection)
ASSERT_EQ(0, badCount); ASSERT_EQ(0, badCount);
} }
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Features2D, BruteForceMatcher, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Features2D, BruteForceMatcher, testing::Combine(

View File

@ -88,23 +88,15 @@ PARAM_TEST_CASE(Blur, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Anchor, Use
TEST_P(Blur, Accuracy) TEST_P(Blur, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::blur(loadMat(src, useRoi), dst, ksize, anchor); cv::gpu::blur(loadMat(src, useRoi), dst, ksize, anchor);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::blur(src, dst_gold, ksize, anchor); cv::blur(src, dst_gold, ksize, anchor);
EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 1.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Filter, Blur, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Blur, testing::Combine(
@ -158,23 +150,15 @@ TEST_P(Sobel, Accuracy)
if (dx == 0 && dy == 0) if (dx == 0 && dy == 0)
return; return;
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::Sobel(loadMat(src, useRoi), dst, -1, dx, dy, ksize.width, 1.0, borderType); cv::gpu::Sobel(loadMat(src, useRoi), dst, -1, dx, dy, ksize.width, 1.0, borderType);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::Sobel(src, dst_gold, -1, dx, dy, ksize.width, 1.0, 0.0, borderType); cv::Sobel(src, dst_gold, -1, dx, dy, ksize.width, 1.0, 0.0, borderType);
EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.1); EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.1);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Filter, Sobel, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Sobel, testing::Combine(
@ -229,23 +213,15 @@ TEST_P(Scharr, Accuracy)
if (dx + dy != 1) if (dx + dy != 1)
return; return;
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::Scharr(loadMat(src, useRoi), dst, -1, dx, dy, 1.0, borderType); cv::gpu::Scharr(loadMat(src, useRoi), dst, -1, dx, dy, 1.0, borderType);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::Scharr(src, dst_gold, -1, dx, dy, 1.0, 0.0, borderType); cv::Scharr(src, dst_gold, -1, dx, dy, 1.0, 0.0, borderType);
EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.1); EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.1);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Filter, Scharr, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Scharr, testing::Combine(
@ -294,39 +270,31 @@ PARAM_TEST_CASE(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels,
TEST_P(GaussianBlur, Accuracy) TEST_P(GaussianBlur, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
double sigma1 = randomDouble(0.1, 1.0);
double sigma2 = randomDouble(0.1, 1.0);
if (ksize.height > 16 && !supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
{ {
cv::Mat src = randomMat(size, type); try
double sigma1 = randomDouble(0.1, 1.0);
double sigma2 = randomDouble(0.1, 1.0);
if (ksize.height > 16 && !supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
{ {
try cv::gpu::GpuMat dst;
{ cv::gpu::GaussianBlur(loadMat(src), dst, ksize, sigma1, sigma2, borderType);
cv::gpu::GpuMat dst;
cv::gpu::GaussianBlur(loadMat(src), dst, ksize, sigma1, sigma2, borderType);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsNotImplemented, e.code);
}
} }
else catch (const cv::Exception& e)
{ {
cv::gpu::GpuMat dst = createMat(size, type, useRoi); ASSERT_EQ(CV_StsNotImplemented, e.code);
cv::gpu::GaussianBlur(loadMat(src, useRoi), dst, ksize, sigma1, sigma2, borderType);
cv::Mat dst_gold;
cv::GaussianBlur(src, dst_gold, ksize, sigma1, sigma2, borderType);
EXPECT_MAT_NEAR(dst_gold, dst, 4.0);
} }
} }
catch (...) else
{ {
cv::gpu::resetDevice(); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
throw; cv::gpu::GaussianBlur(loadMat(src, useRoi), dst, ksize, sigma1, sigma2, borderType);
cv::Mat dst_gold;
cv::GaussianBlur(src, dst_gold, ksize, sigma1, sigma2, borderType);
EXPECT_MAT_NEAR(dst_gold, dst, 4.0);
} }
} }
@ -381,23 +349,15 @@ PARAM_TEST_CASE(Laplacian, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, UseRoi
TEST_P(Laplacian, Accuracy) TEST_P(Laplacian, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::Laplacian(loadMat(src, useRoi), dst, -1, ksize.width); cv::gpu::Laplacian(loadMat(src, useRoi), dst, -1, ksize.width);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::Laplacian(src, dst_gold, -1, ksize.width); cv::Laplacian(src, dst_gold, -1, ksize.width);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() < CV_32F ? 0.0 : 1e-3); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() < CV_32F ? 0.0 : 1e-3);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Filter, Laplacian, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Laplacian, testing::Combine(
@ -436,26 +396,18 @@ PARAM_TEST_CASE(Erode, cv::gpu::DeviceInfo, cv::Size, MatType, Anchor, Iteration
TEST_P(Erode, Accuracy) TEST_P(Erode, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
cv::Mat src = randomMat(size, type);
cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::erode(loadMat(src, useRoi), dst, kernel, anchor, iterations); cv::gpu::erode(loadMat(src, useRoi), dst, kernel, anchor, iterations);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::erode(src, dst_gold, kernel, anchor, iterations); cv::erode(src, dst_gold, kernel, anchor, iterations);
cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1)); cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Filter, Erode, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Erode, testing::Combine(
@ -493,26 +445,18 @@ PARAM_TEST_CASE(Dilate, cv::gpu::DeviceInfo, cv::Size, MatType, Anchor, Iteratio
TEST_P(Dilate, Accuracy) TEST_P(Dilate, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
cv::Mat src = randomMat(size, type);
cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::dilate(loadMat(src, useRoi), dst, kernel, anchor, iterations); cv::gpu::dilate(loadMat(src, useRoi), dst, kernel, anchor, iterations);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::dilate(src, dst_gold, kernel, anchor, iterations); cv::dilate(src, dst_gold, kernel, anchor, iterations);
cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1)); cv::Size ksize = cv::Size(kernel.cols + iterations * (kernel.cols - 1), kernel.rows + iterations * (kernel.rows - 1));
EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, ksize), getInnerROI(dst, ksize), 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Filter, Dilate, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Dilate, testing::Combine(
@ -555,26 +499,18 @@ PARAM_TEST_CASE(MorphEx, cv::gpu::DeviceInfo, cv::Size, MatType, MorphOp, Anchor
TEST_P(MorphEx, Accuracy) TEST_P(MorphEx, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
cv::Mat src = randomMat(size, type);
cv::Mat kernel = cv::Mat::ones(3, 3, CV_8U);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::morphologyEx(loadMat(src, useRoi), dst, morphOp, kernel, anchor, iterations); cv::gpu::morphologyEx(loadMat(src, useRoi), dst, morphOp, kernel, anchor, iterations);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::morphologyEx(src, dst_gold, morphOp, kernel, anchor, iterations); cv::morphologyEx(src, dst_gold, morphOp, kernel, anchor, iterations);
cv::Size border = cv::Size(kernel.cols + (iterations + 1) * kernel.cols + 2, kernel.rows + (iterations + 1) * kernel.rows + 2); cv::Size border = cv::Size(kernel.cols + (iterations + 1) * kernel.cols + 2, kernel.rows + (iterations + 1) * kernel.rows + 2);
EXPECT_MAT_NEAR(getInnerROI(dst_gold, border), getInnerROI(dst, border), 0.0); EXPECT_MAT_NEAR(getInnerROI(dst_gold, border), getInnerROI(dst, border), 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Filter, MorphEx, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, MorphEx, testing::Combine(
@ -617,24 +553,16 @@ PARAM_TEST_CASE(Filter2D, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Anchor,
TEST_P(Filter2D, Accuracy) TEST_P(Filter2D, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ cv::Mat kernel = randomMat(cv::Size(ksize.width, ksize.height), CV_32FC1, 0.0, 1.0);
cv::Mat src = randomMat(size, type);
cv::Mat kernel = randomMat(cv::Size(ksize.width, ksize.height), CV_32FC1, 0.0, 1.0);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::filter2D(loadMat(src, useRoi), dst, -1, kernel, anchor, borderType); cv::gpu::filter2D(loadMat(src, useRoi), dst, -1, kernel, anchor, borderType);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::filter2D(src, dst_gold, -1, kernel, anchor, 0, borderType); cv::filter2D(src, dst_gold, -1, kernel, anchor, 0, borderType);
EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) == CV_32F ? 1e-1 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) == CV_32F ? 1e-1 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_Filter, Filter2D, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_Filter, Filter2D, testing::Combine(

View File

@ -53,43 +53,35 @@ struct CompactPoints : testing::TestWithParam<gpu::DeviceInfo>
TEST_P(CompactPoints, CanCompactizeSmallInput) TEST_P(CompactPoints, CanCompactizeSmallInput)
{ {
try Mat src0(1, 3, CV_32FC2);
{ src0.at<Point2f>(0,0) = Point2f(0,0);
Mat src0(1, 3, CV_32FC2); src0.at<Point2f>(0,1) = Point2f(0,1);
src0.at<Point2f>(0,0) = Point2f(0,0); src0.at<Point2f>(0,2) = Point2f(0,2);
src0.at<Point2f>(0,1) = Point2f(0,1);
src0.at<Point2f>(0,2) = Point2f(0,2);
Mat src1(1, 3, CV_32FC2); Mat src1(1, 3, CV_32FC2);
src1.at<Point2f>(0,0) = Point2f(1,0); src1.at<Point2f>(0,0) = Point2f(1,0);
src1.at<Point2f>(0,1) = Point2f(1,1); src1.at<Point2f>(0,1) = Point2f(1,1);
src1.at<Point2f>(0,2) = Point2f(1,2); src1.at<Point2f>(0,2) = Point2f(1,2);
Mat mask(1, 3, CV_8U); Mat mask(1, 3, CV_8U);
mask.at<uchar>(0,0) = 1; mask.at<uchar>(0,0) = 1;
mask.at<uchar>(0,1) = 0; mask.at<uchar>(0,1) = 0;
mask.at<uchar>(0,2) = 1; mask.at<uchar>(0,2) = 1;
gpu::GpuMat dsrc0(src0), dsrc1(src1), dmask(mask); gpu::GpuMat dsrc0(src0), dsrc1(src1), dmask(mask);
gpu::compactPoints(dsrc0, dsrc1, dmask); gpu::compactPoints(dsrc0, dsrc1, dmask);
dsrc0.download(src0); dsrc0.download(src0);
dsrc1.download(src1); dsrc1.download(src1);
ASSERT_EQ(2, src0.cols); ASSERT_EQ(2, src0.cols);
ASSERT_EQ(2, src1.cols); ASSERT_EQ(2, src1.cols);
ASSERT_TRUE(src0.at<Point2f>(0,0) == Point2f(0,0)); ASSERT_TRUE(src0.at<Point2f>(0,0) == Point2f(0,0));
ASSERT_TRUE(src0.at<Point2f>(0,1) == Point2f(0,2)); ASSERT_TRUE(src0.at<Point2f>(0,1) == Point2f(0,2));
ASSERT_TRUE(src1.at<Point2f>(0,0) == Point2f(1,0)); ASSERT_TRUE(src1.at<Point2f>(0,0) == Point2f(1,0));
ASSERT_TRUE(src1.at<Point2f>(0,1) == Point2f(1,2)); ASSERT_TRUE(src1.at<Point2f>(0,1) == Point2f(1,2));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_GlobalMotion, CompactPoints, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_GlobalMotion, CompactPoints, ALL_DEVICES);

View File

@ -69,122 +69,90 @@ PARAM_TEST_CASE(SetTo, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
TEST_P(SetTo, Zero) TEST_P(SetTo, Zero)
{ {
try cv::Scalar zero = cv::Scalar::all(0);
{
cv::Scalar zero = cv::Scalar::all(0);
cv::gpu::GpuMat mat = createMat(size, type, useRoi); cv::gpu::GpuMat mat = createMat(size, type, useRoi);
mat.setTo(zero); mat.setTo(zero);
EXPECT_MAT_NEAR(cv::Mat::zeros(size, type), mat, 0.0); EXPECT_MAT_NEAR(cv::Mat::zeros(size, type), mat, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(SetTo, SameVal) TEST_P(SetTo, SameVal)
{ {
try cv::Scalar val = cv::Scalar::all(randomDouble(0.0, 255.0));
{
cv::Scalar val = cv::Scalar::all(randomDouble(0.0, 255.0));
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE)) if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE))
{ {
try 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); cv::gpu::GpuMat mat = createMat(size, type, useRoi);
mat.setTo(val); mat.setTo(val);
}
EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0); catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
} }
} }
catch (...) else
{ {
cv::gpu::resetDevice(); cv::gpu::GpuMat mat = createMat(size, type, useRoi);
throw; mat.setTo(val);
EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0);
} }
} }
TEST_P(SetTo, DifferentVal) TEST_P(SetTo, DifferentVal)
{ {
try cv::Scalar val = randomScalar(0.0, 255.0);
{
cv::Scalar val = randomScalar(0.0, 255.0);
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE)) if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE))
{ {
try 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); cv::gpu::GpuMat mat = createMat(size, type, useRoi);
mat.setTo(val); mat.setTo(val);
}
EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0); catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
} }
} }
catch (...) else
{ {
cv::gpu::resetDevice(); cv::gpu::GpuMat mat = createMat(size, type, useRoi);
throw; mat.setTo(val);
EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0);
} }
} }
TEST_P(SetTo, Masked) TEST_P(SetTo, Masked)
{ {
try 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))
{ {
cv::Scalar val = randomScalar(0.0, 255.0); try
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));
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 catch (const cv::Exception& e)
{ {
cv::gpu::GpuMat mat = loadMat(mat_gold, useRoi); ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
mat.setTo(val, loadMat(mask, useRoi));
mat_gold.setTo(val, mask);
EXPECT_MAT_NEAR(mat_gold, mat, 0.0);
} }
} }
catch (...) else
{ {
cv::gpu::resetDevice(); cv::gpu::GpuMat mat = loadMat(mat_gold, useRoi);
throw; mat.setTo(val, loadMat(mask, useRoi));
mat_gold.setTo(val, mask);
EXPECT_MAT_NEAR(mat_gold, mat, 0.0);
} }
} }
@ -218,59 +186,43 @@ PARAM_TEST_CASE(CopyTo, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
TEST_P(CopyTo, WithOutMask) TEST_P(CopyTo, WithOutMask)
{ {
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat d_src = loadMat(src, useRoi); cv::gpu::GpuMat d_src = loadMat(src, useRoi);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
d_src.copyTo(dst); d_src.copyTo(dst);
EXPECT_MAT_NEAR(src, dst, 0.0); EXPECT_MAT_NEAR(src, dst, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(CopyTo, Masked) TEST_P(CopyTo, Masked)
{ {
try cv::Mat src = 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))
{ {
cv::Mat src = randomMat(size, type); try
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 d_src = loadMat(src);
{ cv::gpu::GpuMat dst;
cv::gpu::GpuMat d_src = loadMat(src);
cv::gpu::GpuMat dst;
d_src.copyTo(dst, loadMat(mask, useRoi));
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
}
}
else
{
cv::gpu::GpuMat d_src = loadMat(src, useRoi);
cv::gpu::GpuMat dst = loadMat(cv::Mat::zeros(size, type), useRoi);
d_src.copyTo(dst, loadMat(mask, useRoi)); d_src.copyTo(dst, loadMat(mask, useRoi));
}
cv::Mat dst_gold = cv::Mat::zeros(size, type); catch (const cv::Exception& e)
src.copyTo(dst_gold, mask); {
ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
} }
} }
catch (...) else
{ {
cv::gpu::resetDevice(); cv::gpu::GpuMat d_src = loadMat(src, useRoi);
throw; cv::gpu::GpuMat dst = loadMat(cv::Mat::zeros(size, type), useRoi);
d_src.copyTo(dst, loadMat(mask, useRoi));
cv::Mat dst_gold = cv::Mat::zeros(size, type);
src.copyTo(dst_gold, mask);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
} }
} }
@ -305,79 +257,63 @@ PARAM_TEST_CASE(ConvertTo, cv::gpu::DeviceInfo, cv::Size, MatDepth, MatDepth, Us
TEST_P(ConvertTo, WithOutScaling) TEST_P(ConvertTo, WithOutScaling)
{ {
try cv::Mat src = randomMat(size, depth1);
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE))
{ {
cv::Mat src = randomMat(size, depth1); try
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE))
{ {
try cv::gpu::GpuMat d_src = loadMat(src);
{ cv::gpu::GpuMat dst;
cv::gpu::GpuMat d_src = loadMat(src);
cv::gpu::GpuMat dst;
d_src.convertTo(dst, depth2);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
}
}
else
{
cv::gpu::GpuMat d_src = loadMat(src, useRoi);
cv::gpu::GpuMat dst = createMat(size, depth2, useRoi);
d_src.convertTo(dst, depth2); d_src.convertTo(dst, depth2);
}
cv::Mat dst_gold; catch (const cv::Exception& e)
src.convertTo(dst_gold, depth2); {
ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
} }
} }
catch (...) else
{ {
cv::gpu::resetDevice(); cv::gpu::GpuMat d_src = loadMat(src, useRoi);
throw; cv::gpu::GpuMat dst = createMat(size, depth2, useRoi);
d_src.convertTo(dst, depth2);
cv::Mat dst_gold;
src.convertTo(dst_gold, depth2);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
} }
} }
TEST_P(ConvertTo, WithScaling) TEST_P(ConvertTo, WithScaling)
{ {
try cv::Mat src = randomMat(size, depth1);
double a = randomDouble(0.0, 1.0);
double b = randomDouble(-10.0, 10.0);
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE))
{ {
cv::Mat src = randomMat(size, depth1); try
double a = randomDouble(0.0, 1.0);
double b = randomDouble(-10.0, 10.0);
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE))
{ {
try cv::gpu::GpuMat d_src = loadMat(src);
{ cv::gpu::GpuMat dst;
cv::gpu::GpuMat d_src = loadMat(src);
cv::gpu::GpuMat dst;
d_src.convertTo(dst, depth2, a, b);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
}
}
else
{
cv::gpu::GpuMat d_src = loadMat(src, useRoi);
cv::gpu::GpuMat dst = createMat(size, depth2, useRoi);
d_src.convertTo(dst, depth2, a, b); d_src.convertTo(dst, depth2, a, b);
}
cv::Mat dst_gold; catch (const cv::Exception& e)
src.convertTo(dst_gold, depth2, a, b); {
ASSERT_EQ(CV_StsUnsupportedFormat, e.code);
EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 1.0 : 1e-4);
} }
} }
catch (...) else
{ {
cv::gpu::resetDevice(); cv::gpu::GpuMat d_src = loadMat(src, useRoi);
throw; cv::gpu::GpuMat dst = createMat(size, depth2, useRoi);
d_src.convertTo(dst, depth2, a, b);
cv::Mat dst_gold;
src.convertTo(dst_gold, depth2, a, b);
EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 1.0 : 1e-4);
} }
} }
@ -402,30 +338,22 @@ struct EnsureSizeIsEnough : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(EnsureSizeIsEnough, BufferReuse) TEST_P(EnsureSizeIsEnough, BufferReuse)
{ {
try cv::gpu::GpuMat buffer(100, 100, CV_8U);
{ cv::gpu::GpuMat old = buffer;
cv::gpu::GpuMat buffer(100, 100, CV_8U);
cv::gpu::GpuMat old = buffer;
// don't reallocate memory // don't reallocate memory
cv::gpu::ensureSizeIsEnough(10, 20, CV_8U, buffer); cv::gpu::ensureSizeIsEnough(10, 20, CV_8U, buffer);
EXPECT_EQ(10, buffer.rows); EXPECT_EQ(10, buffer.rows);
EXPECT_EQ(20, buffer.cols); EXPECT_EQ(20, buffer.cols);
EXPECT_EQ(CV_8UC1, buffer.type()); EXPECT_EQ(CV_8UC1, buffer.type());
EXPECT_EQ(reinterpret_cast<intptr_t>(old.data), reinterpret_cast<intptr_t>(buffer.data)); EXPECT_EQ(reinterpret_cast<intptr_t>(old.data), reinterpret_cast<intptr_t>(buffer.data));
// don't reallocate memory // don't reallocate memory
cv::gpu::ensureSizeIsEnough(20, 30, CV_8U, buffer); cv::gpu::ensureSizeIsEnough(20, 30, CV_8U, buffer);
EXPECT_EQ(20, buffer.rows); EXPECT_EQ(20, buffer.rows);
EXPECT_EQ(30, buffer.cols); EXPECT_EQ(30, buffer.cols);
EXPECT_EQ(CV_8UC1, buffer.type()); EXPECT_EQ(CV_8UC1, buffer.type());
EXPECT_EQ(reinterpret_cast<intptr_t>(old.data), reinterpret_cast<intptr_t>(buffer.data)); EXPECT_EQ(reinterpret_cast<intptr_t>(old.data), reinterpret_cast<intptr_t>(buffer.data));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_GpuMat, EnsureSizeIsEnough, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_GpuMat, EnsureSizeIsEnough, ALL_DEVICES);

View File

@ -81,36 +81,28 @@ PARAM_TEST_CASE(HoughLines, cv::gpu::DeviceInfo, cv::Size, UseRoi)
TEST_P(HoughLines, Accuracy) TEST_P(HoughLines, Accuracy)
{ {
try const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
{ cv::gpu::setDevice(devInfo.deviceID());
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0); const cv::Size size = GET_PARAM(1);
cv::gpu::setDevice(devInfo.deviceID()); const bool useRoi = GET_PARAM(2);
const cv::Size size = GET_PARAM(1);
const bool useRoi = GET_PARAM(2);
const float rho = 1.0f; const float rho = 1.0f;
const float theta = (float) (1.5 * CV_PI / 180.0); const float theta = (float) (1.5 * CV_PI / 180.0);
const int threshold = 100; onst int threshold = 100;
cv::Mat src(size, CV_8UC1); cv::Mat src(size, CV_8UC1);
generateLines(src); generateLines(src);
cv::gpu::GpuMat d_lines; cv::gpu::GpuMat d_lines;
cv::gpu::HoughLines(loadMat(src, useRoi), d_lines, rho, theta, threshold); cv::gpu::HoughLines(loadMat(src, useRoi), d_lines, rho, theta, threshold);
std::vector<cv::Vec2f> lines; std::vector<cv::Vec2f> lines;
cv::gpu::HoughLinesDownload(d_lines, lines); cv::gpu::HoughLinesDownload(d_lines, lines);
cv::Mat dst(size, CV_8UC1); cv::Mat dst(size, CV_8UC1);
drawLines(dst, lines); drawLines(dst, lines);
ASSERT_MAT_NEAR(src, dst, 0.0); ASSERT_MAT_NEAR(src, dst, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HoughLines, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HoughLines, testing::Combine(
@ -134,61 +126,53 @@ PARAM_TEST_CASE(HoughCircles, cv::gpu::DeviceInfo, cv::Size, UseRoi)
TEST_P(HoughCircles, Accuracy) TEST_P(HoughCircles, Accuracy)
{ {
try const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
const cv::Size size = GET_PARAM(1);
const bool useRoi = GET_PARAM(2);
const float dp = 2.0f;
const float minDist = 10.0f;
const int minRadius = 10;
const int maxRadius = 20;
const int cannyThreshold = 100;
const int votesThreshold = 20;
std::vector<cv::Vec3f> circles_gold(4);
circles_gold[0] = cv::Vec3i(20, 20, minRadius);
circles_gold[1] = cv::Vec3i(90, 87, minRadius + 3);
circles_gold[2] = cv::Vec3i(30, 70, minRadius + 8);
circles_gold[3] = cv::Vec3i(80, 10, maxRadius);
cv::Mat src(size, CV_8UC1);
drawCircles(src, circles_gold, true);
cv::gpu::GpuMat d_circles;
cv::gpu::HoughCircles(loadMat(src, useRoi), d_circles, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
std::vector<cv::Vec3f> circles;
cv::gpu::HoughCirclesDownload(d_circles, circles);
ASSERT_FALSE(circles.empty());
for (size_t i = 0; i < circles.size(); ++i)
{ {
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Vec3f cur = circles[i];
cv::gpu::setDevice(devInfo.deviceID());
const cv::Size size = GET_PARAM(1);
const bool useRoi = GET_PARAM(2);
const float dp = 2.0f; bool found = false;
const float minDist = 10.0f;
const int minRadius = 10;
const int maxRadius = 20;
const int cannyThreshold = 100;
const int votesThreshold = 20;
std::vector<cv::Vec3f> circles_gold(4); for (size_t j = 0; j < circles_gold.size(); ++j)
circles_gold[0] = cv::Vec3i(20, 20, minRadius);
circles_gold[1] = cv::Vec3i(90, 87, minRadius + 3);
circles_gold[2] = cv::Vec3i(30, 70, minRadius + 8);
circles_gold[3] = cv::Vec3i(80, 10, maxRadius);
cv::Mat src(size, CV_8UC1);
drawCircles(src, circles_gold, true);
cv::gpu::GpuMat d_circles;
cv::gpu::HoughCircles(loadMat(src, useRoi), d_circles, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
std::vector<cv::Vec3f> circles;
cv::gpu::HoughCirclesDownload(d_circles, circles);
ASSERT_FALSE(circles.empty());
for (size_t i = 0; i < circles.size(); ++i)
{ {
cv::Vec3f cur = circles[i]; cv::Vec3f gold = circles_gold[j];
bool found = false; if (std::fabs(cur[0] - gold[0]) < minDist && std::fabs(cur[1] - gold[1]) < minDist && std::fabs(cur[2] - gold[2]) < minDist)
for (size_t j = 0; j < circles_gold.size(); ++j)
{ {
cv::Vec3f gold = circles_gold[j]; found = true;
break;
if (std::fabs(cur[0] - gold[0]) < minDist && std::fabs(cur[1] - gold[1]) < minDist && std::fabs(cur[2] - gold[2]) < minDist)
{
found = true;
break;
}
} }
ASSERT_TRUE(found);
} }
}
catch (...) ASSERT_TRUE(found);
{
cv::gpu::resetDevice();
throw;
} }
} }
@ -206,68 +190,60 @@ PARAM_TEST_CASE(GeneralizedHough, cv::gpu::DeviceInfo, UseRoi)
TEST_P(GeneralizedHough, POSITION) TEST_P(GeneralizedHough, POSITION)
{ {
try const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
const bool useRoi = GET_PARAM(1);
cv::Mat templ = readImage("../cv/shared/templ.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(templ.empty());
cv::Point templCenter(templ.cols / 2, templ.rows / 2);
const size_t gold_count = 3;
cv::Point pos_gold[gold_count];
pos_gold[0] = cv::Point(templCenter.x + 10, templCenter.y + 10);
pos_gold[1] = cv::Point(2 * templCenter.x + 40, templCenter.y + 10);
pos_gold[2] = cv::Point(2 * templCenter.x + 40, 2 * templCenter.y + 40);
cv::Mat image(templ.rows * 3, templ.cols * 3, CV_8UC1, cv::Scalar::all(0));
for (size_t i = 0; i < gold_count; ++i)
{ {
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Rect rec(pos_gold[i].x - templCenter.x, pos_gold[i].y - templCenter.y, templ.cols, templ.rows);
cv::gpu::setDevice(devInfo.deviceID()); cv::Mat imageROI = image(rec);
const bool useRoi = GET_PARAM(1); templ.copyTo(imageROI);
cv::Mat templ = readImage("../cv/shared/templ.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(templ.empty());
cv::Point templCenter(templ.cols / 2, templ.rows / 2);
const size_t gold_count = 3;
cv::Point pos_gold[gold_count];
pos_gold[0] = cv::Point(templCenter.x + 10, templCenter.y + 10);
pos_gold[1] = cv::Point(2 * templCenter.x + 40, templCenter.y + 10);
pos_gold[2] = cv::Point(2 * templCenter.x + 40, 2 * templCenter.y + 40);
cv::Mat image(templ.rows * 3, templ.cols * 3, CV_8UC1, cv::Scalar::all(0));
for (size_t i = 0; i < gold_count; ++i)
{
cv::Rect rec(pos_gold[i].x - templCenter.x, pos_gold[i].y - templCenter.y, templ.cols, templ.rows);
cv::Mat imageROI = image(rec);
templ.copyTo(imageROI);
}
cv::Ptr<cv::gpu::GeneralizedHough_GPU> hough = cv::gpu::GeneralizedHough_GPU::create(cv::GHT_POSITION);
hough->set("votesThreshold", 200);
hough->setTemplate(loadMat(templ, useRoi));
cv::gpu::GpuMat d_pos;
hough->detect(loadMat(image, useRoi), d_pos);
std::vector<cv::Vec4f> pos;
hough->download(d_pos, pos);
ASSERT_EQ(gold_count, pos.size());
for (size_t i = 0; i < gold_count; ++i)
{
cv::Point gold = pos_gold[i];
bool found = false;
for (size_t j = 0; j < pos.size(); ++j)
{
cv::Point2f p(pos[j][0], pos[j][1]);
if (::fabs(p.x - gold.x) < 2 && ::fabs(p.y - gold.y) < 2)
{
found = true;
break;
}
}
ASSERT_TRUE(found);
}
} }
catch (...)
cv::Ptr<cv::gpu::GeneralizedHough_GPU> hough = cv::gpu::GeneralizedHough_GPU::create(cv::GHT_POSITION);
hough->set("votesThreshold", 200);
hough->setTemplate(loadMat(templ, useRoi));
cv::gpu::GpuMat d_pos;
hough->detect(loadMat(image, useRoi), d_pos);
std::vector<cv::Vec4f> pos;
hough->download(d_pos, pos);
ASSERT_EQ(gold_count, pos.size());
for (size_t i = 0; i < gold_count; ++i)
{ {
cv::gpu::resetDevice(); cv::Point gold = pos_gold[i];
throw;
bool found = false;
for (size_t j = 0; j < pos.size(); ++j)
{
cv::Point2f p(pos[j][0], pos[j][1]);
if (::fabs(p.x - gold.x) < 2 && ::fabs(p.y - gold.y) < 2)
{
found = true;
break;
}
}
ASSERT_TRUE(found);
} }
} }

View File

@ -66,23 +66,15 @@ PARAM_TEST_CASE(Integral, cv::gpu::DeviceInfo, cv::Size, UseRoi)
TEST_P(Integral, Accuracy) TEST_P(Integral, Accuracy)
{ {
try cv::Mat src = randomMat(size, CV_8UC1);
{
cv::Mat src = randomMat(size, CV_8UC1);
cv::gpu::GpuMat dst = createMat(cv::Size(src.cols + 1, src.rows + 1), CV_32SC1, useRoi); cv::gpu::GpuMat dst = createMat(cv::Size(src.cols + 1, src.rows + 1), CV_32SC1, useRoi);
cv::gpu::integral(loadMat(src, useRoi), dst); cv::gpu::integral(loadMat(src, useRoi), dst);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::integral(src, dst_gold, CV_32S); cv::integral(src, dst_gold, CV_32S);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Integral, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Integral, testing::Combine(
@ -107,40 +99,32 @@ struct HistEven : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(HistEven, Accuracy) TEST_P(HistEven, Accuracy)
{ {
try cv::Mat img = readImage("stereobm/aloe-L.png");
{ ASSERT_FALSE(img.empty());
cv::Mat img = readImage("stereobm/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::Mat hsv; cv::Mat hsv;
cv::cvtColor(img, hsv, CV_BGR2HSV); cv::cvtColor(img, hsv, CV_BGR2HSV);
int hbins = 30; int hbins = 30;
float hranges[] = {0.0f, 180.0f}; float hranges[] = {0.0f, 180.0f};
std::vector<cv::gpu::GpuMat> srcs; std::vector<cv::gpu::GpuMat> srcs;
cv::gpu::split(loadMat(hsv), srcs); cv::gpu::split(loadMat(hsv), srcs);
cv::gpu::GpuMat hist; cv::gpu::GpuMat hist;
cv::gpu::histEven(srcs[0], hist, hbins, (int)hranges[0], (int)hranges[1]); cv::gpu::histEven(srcs[0], hist, hbins, (int)hranges[0], (int)hranges[1]);
cv::MatND histnd; cv::MatND histnd;
int histSize[] = {hbins}; int histSize[] = {hbins};
const float* ranges[] = {hranges}; const float* ranges[] = {hranges};
int channels[] = {0}; int channels[] = {0};
cv::calcHist(&hsv, 1, channels, cv::Mat(), histnd, 1, histSize, ranges); cv::calcHist(&hsv, 1, channels, cv::Mat(), histnd, 1, histSize, ranges);
cv::Mat hist_gold = histnd; cv::Mat hist_gold = histnd;
hist_gold = hist_gold.t(); hist_gold = hist_gold.t();
hist_gold.convertTo(hist_gold, CV_32S); hist_gold.convertTo(hist_gold, CV_32S);
EXPECT_MAT_NEAR(hist_gold, hist, 0.0); EXPECT_MAT_NEAR(hist_gold, hist, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HistEven, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HistEven, ALL_DEVICES);
@ -180,23 +164,15 @@ PARAM_TEST_CASE(CalcHist, cv::gpu::DeviceInfo, cv::Size)
TEST_P(CalcHist, Accuracy) TEST_P(CalcHist, Accuracy)
{ {
try cv::Mat src = randomMat(size, CV_8UC1);
{
cv::Mat src = randomMat(size, CV_8UC1);
cv::gpu::GpuMat hist; cv::gpu::GpuMat hist;
cv::gpu::calcHist(loadMat(src), hist); cv::gpu::calcHist(loadMat(src), hist);
cv::Mat hist_gold; cv::Mat hist_gold;
calcHistGold(src, hist_gold); calcHistGold(src, hist_gold);
EXPECT_MAT_NEAR(hist_gold, hist, 0.0); EXPECT_MAT_NEAR(hist_gold, hist, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CalcHist, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CalcHist, testing::Combine(
@ -222,23 +198,15 @@ PARAM_TEST_CASE(EqualizeHist, cv::gpu::DeviceInfo, cv::Size)
TEST_P(EqualizeHist, Accuracy) TEST_P(EqualizeHist, Accuracy)
{ {
try cv::Mat src = randomMat(size, CV_8UC1);
{
cv::Mat src = randomMat(size, CV_8UC1);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::equalizeHist(loadMat(src), dst); cv::gpu::equalizeHist(loadMat(src), dst);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::equalizeHist(src, dst_gold); cv::equalizeHist(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 3.0); EXPECT_MAT_NEAR(dst_gold, dst, 3.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, EqualizeHist, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, EqualizeHist, testing::Combine(
@ -264,36 +232,28 @@ PARAM_TEST_CASE(ColumnSum, cv::gpu::DeviceInfo, cv::Size)
TEST_P(ColumnSum, Accuracy) TEST_P(ColumnSum, Accuracy)
{ {
try cv::Mat src = randomMat(size, CV_32FC1);
cv::gpu::GpuMat d_dst;
cv::gpu::columnSum(loadMat(src), d_dst);
cv::Mat dst(d_dst);
for (int j = 0; j < src.cols; ++j)
{ {
cv::Mat src = randomMat(size, CV_32FC1); float gold = src.at<float>(0, j);
float res = dst.at<float>(0, j);
cv::gpu::GpuMat d_dst; ASSERT_NEAR(res, gold, 1e-5);
cv::gpu::columnSum(loadMat(src), d_dst); }
cv::Mat dst(d_dst);
for (int i = 1; i < src.rows; ++i)
{
for (int j = 0; j < src.cols; ++j) for (int j = 0; j < src.cols; ++j)
{ {
float gold = src.at<float>(0, j); float gold = src.at<float>(i, j) += src.at<float>(i - 1, j);
float res = dst.at<float>(0, j); float res = dst.at<float>(i, j);
ASSERT_NEAR(res, gold, 1e-5); ASSERT_NEAR(res, gold, 1e-5);
} }
for (int i = 1; i < src.rows; ++i)
{
for (int j = 0; j < src.cols; ++j)
{
float gold = src.at<float>(i, j) += src.at<float>(i - 1, j);
float res = dst.at<float>(i, j);
ASSERT_NEAR(res, gold, 1e-5);
}
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
@ -327,41 +287,33 @@ PARAM_TEST_CASE(Canny, cv::gpu::DeviceInfo, AppertureSize, L2gradient, UseRoi)
TEST_P(Canny, Accuracy) TEST_P(Canny, Accuracy)
{ {
try cv::Mat img = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
double low_thresh = 50.0;
double high_thresh = 100.0;
if (!supportFeature(devInfo, cv::gpu::SHARED_ATOMICS))
{ {
cv::Mat img = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); try
ASSERT_FALSE(img.empty());
double low_thresh = 50.0;
double high_thresh = 100.0;
if (!supportFeature(devInfo, cv::gpu::SHARED_ATOMICS))
{ {
try cv::gpu::GpuMat edges;
{ cv::gpu::Canny(loadMat(img), edges, low_thresh, high_thresh, apperture_size, useL2gradient);
cv::gpu::GpuMat edges;
cv::gpu::Canny(loadMat(img), edges, low_thresh, high_thresh, apperture_size, useL2gradient);
}
catch (const cv::Exception& e)
{
ASSERT_EQ(CV_StsNotImplemented, e.code);
}
} }
else catch (const cv::Exception& e)
{ {
cv::gpu::GpuMat edges; ASSERT_EQ(CV_StsNotImplemented, e.code);
cv::gpu::Canny(loadMat(img, useRoi), edges, low_thresh, high_thresh, apperture_size, useL2gradient);
cv::Mat edges_gold;
cv::Canny(img, edges_gold, low_thresh, high_thresh, apperture_size, useL2gradient);
EXPECT_MAT_SIMILAR(edges_gold, edges, 2e-2);
} }
} }
catch (...) else
{ {
cv::gpu::resetDevice(); cv::gpu::GpuMat edges;
throw; cv::gpu::Canny(loadMat(img, useRoi), edges, low_thresh, high_thresh, apperture_size, useL2gradient);
cv::Mat edges_gold;
cv::Canny(img, edges_gold, low_thresh, high_thresh, apperture_size, useL2gradient);
EXPECT_MAT_SIMILAR(edges_gold, edges, 2e-2);
} }
} }
@ -399,66 +351,50 @@ struct MeanShift : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(MeanShift, Filtering) TEST_P(MeanShift, Filtering)
{ {
try cv::Mat img_template;
{ if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
cv::Mat img_template; img_template = readImage("meanshift/con_result.png");
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20)) else
img_template = readImage("meanshift/con_result.png"); img_template = readImage("meanshift/con_result_CC1X.png");
else ASSERT_FALSE(img_template.empty());
img_template = readImage("meanshift/con_result_CC1X.png");
ASSERT_FALSE(img_template.empty());
cv::gpu::GpuMat d_dst; cv::gpu::GpuMat d_dst;
cv::gpu::meanShiftFiltering(loadMat(img), d_dst, spatialRad, colorRad); cv::gpu::meanShiftFiltering(loadMat(img), d_dst, spatialRad, colorRad);
ASSERT_EQ(CV_8UC4, d_dst.type()); ASSERT_EQ(CV_8UC4, d_dst.type());
cv::Mat dst(d_dst); cv::Mat dst(d_dst);
cv::Mat result; cv::Mat result;
cv::cvtColor(dst, result, CV_BGRA2BGR); cv::cvtColor(dst, result, CV_BGRA2BGR);
EXPECT_MAT_NEAR(img_template, result, 0.0); EXPECT_MAT_NEAR(img_template, result, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(MeanShift, Proc) TEST_P(MeanShift, Proc)
{ {
try cv::FileStorage fs;
{ if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
cv::FileStorage fs; fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap.yaml", cv::FileStorage::READ);
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20)) else
fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap.yaml", cv::FileStorage::READ); fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap_CC1X.yaml", cv::FileStorage::READ);
else ASSERT_TRUE(fs.isOpened());
fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap_CC1X.yaml", cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
cv::Mat spmap_template; cv::Mat spmap_template;
fs["spmap"] >> spmap_template; fs["spmap"] >> spmap_template;
ASSERT_FALSE(spmap_template.empty()); ASSERT_FALSE(spmap_template.empty());
cv::gpu::GpuMat rmap_filtered; cv::gpu::GpuMat rmap_filtered;
cv::gpu::meanShiftFiltering(loadMat(img), rmap_filtered, spatialRad, colorRad); cv::gpu::meanShiftFiltering(loadMat(img), rmap_filtered, spatialRad, colorRad);
cv::gpu::GpuMat rmap; cv::gpu::GpuMat rmap;
cv::gpu::GpuMat spmap; cv::gpu::GpuMat spmap;
cv::gpu::meanShiftProc(loadMat(img), rmap, spmap, spatialRad, colorRad); cv::gpu::meanShiftProc(loadMat(img), rmap, spmap, spatialRad, colorRad);
ASSERT_EQ(CV_8UC4, rmap.type()); ASSERT_EQ(CV_8UC4, rmap.type());
EXPECT_MAT_NEAR(rmap_filtered, rmap, 0.0); EXPECT_MAT_NEAR(rmap_filtered, rmap, 0.0);
EXPECT_MAT_NEAR(spmap_template, spmap, 0.0); EXPECT_MAT_NEAR(spmap_template, spmap, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MeanShift, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MeanShift, ALL_DEVICES);
@ -484,33 +420,25 @@ PARAM_TEST_CASE(MeanShiftSegmentation, cv::gpu::DeviceInfo, MinSize)
TEST_P(MeanShiftSegmentation, Regression) TEST_P(MeanShiftSegmentation, Regression)
{ {
try cv::Mat img = readImageType("meanshift/cones.png", CV_8UC4);
{ ASSERT_FALSE(img.empty());
cv::Mat img = readImageType("meanshift/cones.png", CV_8UC4);
ASSERT_FALSE(img.empty());
std::ostringstream path; std::ostringstream path;
path << "meanshift/cones_segmented_sp10_sr10_minsize" << minsize; path << "meanshift/cones_segmented_sp10_sr10_minsize" << minsize;
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20)) if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
path << ".png"; path << ".png";
else else
path << "_CC1X.png"; path << "_CC1X.png";
cv::Mat dst_gold = readImage(path.str()); cv::Mat dst_gold = readImage(path.str());
ASSERT_FALSE(dst_gold.empty()); ASSERT_FALSE(dst_gold.empty());
cv::Mat dst; cv::Mat dst;
cv::gpu::meanShiftSegmentation(loadMat(img), dst, 10, 10, minsize); cv::gpu::meanShiftSegmentation(loadMat(img), dst, 10, 10, minsize);
cv::Mat dst_rgb; cv::Mat dst_rgb;
cv::cvtColor(dst, dst_rgb, CV_BGRA2BGR); cv::cvtColor(dst, dst_rgb, CV_BGRA2BGR);
EXPECT_MAT_SIMILAR(dst_gold, dst_rgb, 1e-3); EXPECT_MAT_SIMILAR(dst_gold, dst_rgb, 1e-3);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MeanShiftSegmentation, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MeanShiftSegmentation, testing::Combine(
@ -564,31 +492,23 @@ PARAM_TEST_CASE(Blend, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
TEST_P(Blend, Accuracy) TEST_P(Blend, Accuracy)
{ {
try int depth = CV_MAT_DEPTH(type);
{
int depth = CV_MAT_DEPTH(type);
cv::Mat img1 = randomMat(size, type, 0.0, depth == CV_8U ? 255.0 : 1.0); cv::Mat img1 = randomMat(size, type, 0.0, depth == CV_8U ? 255.0 : 1.0);
cv::Mat img2 = randomMat(size, type, 0.0, depth == CV_8U ? 255.0 : 1.0); cv::Mat img2 = randomMat(size, type, 0.0, depth == CV_8U ? 255.0 : 1.0);
cv::Mat weights1 = randomMat(size, CV_32F, 0, 1); cv::Mat weights1 = randomMat(size, CV_32F, 0, 1);
cv::Mat weights2 = randomMat(size, CV_32F, 0, 1); cv::Mat weights2 = randomMat(size, CV_32F, 0, 1);
cv::gpu::GpuMat result; cv::gpu::GpuMat result;
cv::gpu::blendLinear(loadMat(img1, useRoi), loadMat(img2, useRoi), loadMat(weights1, useRoi), loadMat(weights2, useRoi), result); cv::gpu::blendLinear(loadMat(img1, useRoi), loadMat(img2, useRoi), loadMat(weights1, useRoi), loadMat(weights2, useRoi), result);
cv::Mat result_gold; cv::Mat result_gold;
if (depth == CV_8U) if (depth == CV_8U)
blendLinearGold<uchar>(img1, img2, weights1, weights2, result_gold); blendLinearGold<uchar>(img1, img2, weights1, weights2, result_gold);
else else
blendLinearGold<float>(img1, img2, weights1, weights2, result_gold); blendLinearGold<float>(img1, img2, weights1, weights2, result_gold);
EXPECT_MAT_NEAR(result_gold, result, CV_MAT_DEPTH(type) == CV_8U ? 1.0 : 1e-5); EXPECT_MAT_NEAR(result_gold, result, CV_MAT_DEPTH(type) == CV_8U ? 1.0 : 1e-5);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Blend, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Blend, testing::Combine(
@ -662,24 +582,16 @@ PARAM_TEST_CASE(Convolve, cv::gpu::DeviceInfo, cv::Size, KSize, Ccorr)
TEST_P(Convolve, Accuracy) TEST_P(Convolve, Accuracy)
{ {
try cv::Mat src = randomMat(size, CV_32FC1, 0.0, 100.0);
{ cv::Mat kernel = randomMat(cv::Size(ksize, ksize), CV_32FC1, 0.0, 1.0);
cv::Mat src = randomMat(size, CV_32FC1, 0.0, 100.0);
cv::Mat kernel = randomMat(cv::Size(ksize, ksize), CV_32FC1, 0.0, 1.0);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::convolve(loadMat(src), loadMat(kernel), dst, ccorr); cv::gpu::convolve(loadMat(src), loadMat(kernel), dst, ccorr);
cv::Mat dst_gold; cv::Mat dst_gold;
convolveDFT(src, kernel, dst_gold, ccorr); convolveDFT(src, kernel, dst_gold, ccorr);
EXPECT_MAT_NEAR(dst, dst_gold, 1e-1); EXPECT_MAT_NEAR(dst, dst_gold, 1e-1);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Convolve, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Convolve, testing::Combine(
@ -718,24 +630,16 @@ PARAM_TEST_CASE(MatchTemplate8U, cv::gpu::DeviceInfo, cv::Size, TemplateSize, Ch
TEST_P(MatchTemplate8U, Accuracy) TEST_P(MatchTemplate8U, Accuracy)
{ {
try cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn));
{ cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_8U, cn));
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn));
cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_8U, cn));
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::matchTemplate(loadMat(image), loadMat(templ), dst, method); cv::gpu::matchTemplate(loadMat(image), loadMat(templ), dst, method);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::matchTemplate(image, templ, dst_gold, method); cv::matchTemplate(image, templ, dst_gold, method);
EXPECT_MAT_NEAR(dst_gold, dst, templ_size.area() * 1e-1); EXPECT_MAT_NEAR(dst_gold, dst, templ_size.area() * 1e-1);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplate8U, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplate8U, testing::Combine(
@ -772,24 +676,16 @@ PARAM_TEST_CASE(MatchTemplate32F, cv::gpu::DeviceInfo, cv::Size, TemplateSize, C
TEST_P(MatchTemplate32F, Regression) TEST_P(MatchTemplate32F, Regression)
{ {
try cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn));
{ cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_32F, cn));
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn));
cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_32F, cn));
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::matchTemplate(loadMat(image), loadMat(templ), dst, method); cv::gpu::matchTemplate(loadMat(image), loadMat(templ), dst, method);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::matchTemplate(image, templ, dst_gold, method); cv::matchTemplate(image, templ, dst_gold, method);
EXPECT_MAT_NEAR(dst_gold, dst, templ_size.area() * 1e-1); EXPECT_MAT_NEAR(dst_gold, dst, templ_size.area() * 1e-1);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplate32F, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplate32F, testing::Combine(
@ -818,32 +714,24 @@ PARAM_TEST_CASE(MatchTemplateBlackSource, cv::gpu::DeviceInfo, TemplateMethod)
TEST_P(MatchTemplateBlackSource, Accuracy) TEST_P(MatchTemplateBlackSource, Accuracy)
{ {
try cv::Mat image = readImage("matchtemplate/black.png");
{ ASSERT_FALSE(image.empty());
cv::Mat image = readImage("matchtemplate/black.png");
ASSERT_FALSE(image.empty());
cv::Mat pattern = readImage("matchtemplate/cat.png"); cv::Mat pattern = readImage("matchtemplate/cat.png");
ASSERT_FALSE(pattern.empty()); ASSERT_FALSE(pattern.empty());
cv::gpu::GpuMat d_dst; cv::gpu::GpuMat d_dst;
cv::gpu::matchTemplate(loadMat(image), loadMat(pattern), d_dst, method); cv::gpu::matchTemplate(loadMat(image), loadMat(pattern), d_dst, method);
cv::Mat dst(d_dst); cv::Mat dst(d_dst);
double maxValue; double maxValue;
cv::Point maxLoc; cv::Point maxLoc;
cv::minMaxLoc(dst, NULL, &maxValue, NULL, &maxLoc); cv::minMaxLoc(dst, NULL, &maxValue, NULL, &maxLoc);
cv::Point maxLocGold = cv::Point(284, 12); cv::Point maxLocGold = cv::Point(284, 12);
ASSERT_EQ(maxLocGold, maxLoc); ASSERT_EQ(maxLocGold, maxLoc);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplateBlackSource, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplateBlackSource, testing::Combine(
@ -871,40 +759,32 @@ PARAM_TEST_CASE(MatchTemplate_CCOEF_NORMED, cv::gpu::DeviceInfo, std::pair<std::
TEST_P(MatchTemplate_CCOEF_NORMED, Accuracy) TEST_P(MatchTemplate_CCOEF_NORMED, Accuracy)
{ {
try cv::Mat image = readImage(imageName);
{ ASSERT_FALSE(image.empty());
cv::Mat image = readImage(imageName);
ASSERT_FALSE(image.empty());
cv::Mat pattern = readImage(patternName); cv::Mat pattern = readImage(patternName);
ASSERT_FALSE(pattern.empty()); ASSERT_FALSE(pattern.empty());
cv::gpu::GpuMat d_dst; cv::gpu::GpuMat d_dst;
cv::gpu::matchTemplate(loadMat(image), loadMat(pattern), d_dst, CV_TM_CCOEFF_NORMED); cv::gpu::matchTemplate(loadMat(image), loadMat(pattern), d_dst, CV_TM_CCOEFF_NORMED);
cv::Mat dst(d_dst); cv::Mat dst(d_dst);
cv::Point minLoc, maxLoc; cv::Point minLoc, maxLoc;
double minVal, maxVal; double minVal, maxVal;
cv::minMaxLoc(dst, &minVal, &maxVal, &minLoc, &maxLoc); cv::minMaxLoc(dst, &minVal, &maxVal, &minLoc, &maxLoc);
cv::Mat dstGold; cv::Mat dstGold;
cv::matchTemplate(image, pattern, dstGold, CV_TM_CCOEFF_NORMED); cv::matchTemplate(image, pattern, dstGold, CV_TM_CCOEFF_NORMED);
double minValGold, maxValGold; double minValGold, maxValGold;
cv::Point minLocGold, maxLocGold; cv::Point minLocGold, maxLocGold;
cv::minMaxLoc(dstGold, &minValGold, &maxValGold, &minLocGold, &maxLocGold); cv::minMaxLoc(dstGold, &minValGold, &maxValGold, &minLocGold, &maxLocGold);
ASSERT_EQ(minLocGold, minLoc); ASSERT_EQ(minLocGold, minLoc);
ASSERT_EQ(maxLocGold, maxLoc); ASSERT_EQ(maxLocGold, maxLoc);
ASSERT_LE(maxVal, 1.0); ASSERT_LE(maxVal, 1.0);
ASSERT_GE(minVal, -1.0); ASSERT_GE(minVal, -1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplate_CCOEF_NORMED, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplate_CCOEF_NORMED, testing::Combine(
@ -928,63 +808,47 @@ struct MatchTemplate_CanFindBigTemplate : testing::TestWithParam<cv::gpu::Device
TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF_NORMED) TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF_NORMED)
{ {
try cv::Mat scene = readImage("matchtemplate/scene.png");
{ ASSERT_FALSE(scene.empty());
cv::Mat scene = readImage("matchtemplate/scene.png");
ASSERT_FALSE(scene.empty());
cv::Mat templ = readImage("matchtemplate/template.png"); cv::Mat templ = readImage("matchtemplate/template.png");
ASSERT_FALSE(templ.empty()); ASSERT_FALSE(templ.empty());
cv::gpu::GpuMat d_result; cv::gpu::GpuMat d_result;
cv::gpu::matchTemplate(loadMat(scene), loadMat(templ), d_result, CV_TM_SQDIFF_NORMED); cv::gpu::matchTemplate(loadMat(scene), loadMat(templ), d_result, CV_TM_SQDIFF_NORMED);
cv::Mat result(d_result); cv::Mat result(d_result);
double minVal; double minVal;
cv::Point minLoc; cv::Point minLoc;
cv::minMaxLoc(result, &minVal, 0, &minLoc, 0); cv::minMaxLoc(result, &minVal, 0, &minLoc, 0);
ASSERT_GE(minVal, 0); ASSERT_GE(minVal, 0);
ASSERT_LT(minVal, 1e-3); ASSERT_LT(minVal, 1e-3);
ASSERT_EQ(344, minLoc.x); ASSERT_EQ(344, minLoc.x);
ASSERT_EQ(0, minLoc.y); ASSERT_EQ(0, minLoc.y);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF) TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF)
{ {
try cv::Mat scene = readImage("matchtemplate/scene.png");
{ ASSERT_FALSE(scene.empty());
cv::Mat scene = readImage("matchtemplate/scene.png");
ASSERT_FALSE(scene.empty());
cv::Mat templ = readImage("matchtemplate/template.png"); cv::Mat templ = readImage("matchtemplate/template.png");
ASSERT_FALSE(templ.empty()); ASSERT_FALSE(templ.empty());
cv::gpu::GpuMat d_result; cv::gpu::GpuMat d_result;
cv::gpu::matchTemplate(loadMat(scene), loadMat(templ), d_result, CV_TM_SQDIFF); cv::gpu::matchTemplate(loadMat(scene), loadMat(templ), d_result, CV_TM_SQDIFF);
cv::Mat result(d_result); cv::Mat result(d_result);
double minVal; double minVal;
cv::Point minLoc; cv::Point minLoc;
cv::minMaxLoc(result, &minVal, 0, &minLoc, 0); cv::minMaxLoc(result, &minVal, 0, &minLoc, 0);
ASSERT_GE(minVal, 0); ASSERT_GE(minVal, 0);
ASSERT_EQ(344, minLoc.x); ASSERT_EQ(344, minLoc.x);
ASSERT_EQ(0, minLoc.y); ASSERT_EQ(0, minLoc.y);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplate_CanFindBigTemplate, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MatchTemplate_CanFindBigTemplate, ALL_DEVICES);
@ -1017,43 +881,27 @@ PARAM_TEST_CASE(MulSpectrums, cv::gpu::DeviceInfo, cv::Size, DftFlags)
TEST_P(MulSpectrums, Simple) TEST_P(MulSpectrums, Simple)
{ {
try cv::gpu::GpuMat c;
{ cv::gpu::mulSpectrums(loadMat(a), loadMat(b), c, flag, false);
cv::gpu::GpuMat c;
cv::gpu::mulSpectrums(loadMat(a), loadMat(b), c, flag, false);
cv::Mat c_gold; cv::Mat c_gold;
cv::mulSpectrums(a, b, c_gold, flag, false); cv::mulSpectrums(a, b, c_gold, flag, false);
EXPECT_MAT_NEAR(c_gold, c, 1e-2); EXPECT_MAT_NEAR(c_gold, c, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(MulSpectrums, Scaled) TEST_P(MulSpectrums, Scaled)
{ {
try float scale = 1.f / size.area();
{
float scale = 1.f / size.area();
cv::gpu::GpuMat c; cv::gpu::GpuMat c;
cv::gpu::mulAndScaleSpectrums(loadMat(a), loadMat(b), c, flag, scale, false); cv::gpu::mulAndScaleSpectrums(loadMat(a), loadMat(b), c, flag, scale, false);
cv::Mat c_gold; cv::Mat c_gold;
cv::mulSpectrums(a, b, c_gold, flag, false); cv::mulSpectrums(a, b, c_gold, flag, false);
c_gold.convertTo(c_gold, c_gold.type(), scale); c_gold.convertTo(c_gold, c_gold.type(), scale);
EXPECT_MAT_NEAR(c_gold, c, 1e-2); EXPECT_MAT_NEAR(c_gold, c, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MulSpectrums, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, MulSpectrums, testing::Combine(
@ -1102,34 +950,26 @@ void testC2C(const std::string& hint, int cols, int rows, int flags, bool inplac
TEST_P(Dft, C2C) TEST_P(Dft, C2C)
{ {
try int cols = randomInt(2, 100);
{ int rows = randomInt(2, 100);
int cols = randomInt(2, 100);
int rows = randomInt(2, 100);
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
{
bool inplace = i != 0;
testC2C("no flags", cols, rows, 0, inplace);
testC2C("no flags 0 1", cols, rows + 1, 0, inplace);
testC2C("no flags 1 0", cols, rows + 1, 0, inplace);
testC2C("no flags 1 1", cols + 1, rows, 0, inplace);
testC2C("DFT_INVERSE", cols, rows, cv::DFT_INVERSE, inplace);
testC2C("DFT_ROWS", cols, rows, cv::DFT_ROWS, inplace);
testC2C("single col", 1, rows, 0, inplace);
testC2C("single row", cols, 1, 0, inplace);
testC2C("single col inversed", 1, rows, cv::DFT_INVERSE, inplace);
testC2C("single row inversed", cols, 1, cv::DFT_INVERSE, inplace);
testC2C("single row DFT_ROWS", cols, 1, cv::DFT_ROWS, inplace);
testC2C("size 1 2", 1, 2, 0, inplace);
testC2C("size 2 1", 2, 1, 0, inplace);
}
}
catch (...)
{ {
cv::gpu::resetDevice(); bool inplace = i != 0;
throw;
testC2C("no flags", cols, rows, 0, inplace);
testC2C("no flags 0 1", cols, rows + 1, 0, inplace);
testC2C("no flags 1 0", cols, rows + 1, 0, inplace);
testC2C("no flags 1 1", cols + 1, rows, 0, inplace);
testC2C("DFT_INVERSE", cols, rows, cv::DFT_INVERSE, inplace);
testC2C("DFT_ROWS", cols, rows, cv::DFT_ROWS, inplace);
testC2C("single col", 1, rows, 0, inplace);
testC2C("single row", cols, 1, 0, inplace);
testC2C("single col inversed", 1, rows, cv::DFT_INVERSE, inplace);
testC2C("single row inversed", cols, 1, cv::DFT_INVERSE, inplace);
testC2C("single row DFT_ROWS", cols, 1, cv::DFT_ROWS, inplace);
testC2C("size 1 2", 1, 2, 0, inplace);
testC2C("size 2 1", 2, 1, 0, inplace);
} }
} }
@ -1171,32 +1011,24 @@ void testR2CThenC2R(const std::string& hint, int cols, int rows, bool inplace)
TEST_P(Dft, R2CThenC2R) TEST_P(Dft, R2CThenC2R)
{ {
try int cols = randomInt(2, 100);
{ int rows = randomInt(2, 100);
int cols = randomInt(2, 100);
int rows = randomInt(2, 100);
testR2CThenC2R("sanity", cols, rows, false); testR2CThenC2R("sanity", cols, rows, false);
testR2CThenC2R("sanity 0 1", cols, rows + 1, false); testR2CThenC2R("sanity 0 1", cols, rows + 1, false);
testR2CThenC2R("sanity 1 0", cols + 1, rows, false); testR2CThenC2R("sanity 1 0", cols + 1, rows, false);
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, false); testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, false);
testR2CThenC2R("single col", 1, rows, false); testR2CThenC2R("single col", 1, rows, false);
testR2CThenC2R("single col 1", 1, rows + 1, false); testR2CThenC2R("single col 1", 1, rows + 1, false);
testR2CThenC2R("single row", cols, 1, false); testR2CThenC2R("single row", cols, 1, false);
testR2CThenC2R("single row 1", cols + 1, 1, false); testR2CThenC2R("single row 1", cols + 1, 1, false);
testR2CThenC2R("sanity", cols, rows, true); testR2CThenC2R("sanity", cols, rows, true);
testR2CThenC2R("sanity 0 1", cols, rows + 1, true); testR2CThenC2R("sanity 0 1", cols, rows + 1, true);
testR2CThenC2R("sanity 1 0", cols + 1, rows, true); testR2CThenC2R("sanity 1 0", cols + 1, rows, true);
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, true); testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, true);
testR2CThenC2R("single row", cols, 1, true); testR2CThenC2R("single row", cols, 1, true);
testR2CThenC2R("single row 1", cols + 1, 1, true); testR2CThenC2R("single row 1", cols + 1, 1, true);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Dft, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Dft, ALL_DEVICES);
@ -1229,26 +1061,18 @@ PARAM_TEST_CASE(CornerHarris, cv::gpu::DeviceInfo, MatType, BorderType, BlockSiz
TEST_P(CornerHarris, Accuracy) TEST_P(CornerHarris, Accuracy)
{ {
try cv::Mat src = readImageType("stereobm/aloe-L.png", type);
{ ASSERT_FALSE(src.empty());
cv::Mat src = readImageType("stereobm/aloe-L.png", type);
ASSERT_FALSE(src.empty());
double k = randomDouble(0.1, 0.9); double k = randomDouble(0.1, 0.9);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::cornerHarris(loadMat(src), dst, blockSize, apertureSize, k, borderType); cv::gpu::cornerHarris(loadMat(src), dst, blockSize, apertureSize, k, borderType);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::cornerHarris(src, dst_gold, blockSize, apertureSize, k, borderType); cv::cornerHarris(src, dst_gold, blockSize, apertureSize, k, borderType);
EXPECT_MAT_NEAR(dst_gold, dst, 0.02); EXPECT_MAT_NEAR(dst_gold, dst, 0.02);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CornerHarris, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CornerHarris, testing::Combine(
@ -1283,24 +1107,16 @@ PARAM_TEST_CASE(CornerMinEigen, cv::gpu::DeviceInfo, MatType, BorderType, BlockS
TEST_P(CornerMinEigen, Accuracy) TEST_P(CornerMinEigen, Accuracy)
{ {
try cv::Mat src = readImageType("stereobm/aloe-L.png", type);
{ ASSERT_FALSE(src.empty());
cv::Mat src = readImageType("stereobm/aloe-L.png", type);
ASSERT_FALSE(src.empty());
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::cornerMinEigenVal(loadMat(src), dst, blockSize, apertureSize, borderType); cv::gpu::cornerMinEigenVal(loadMat(src), dst, blockSize, apertureSize, borderType);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::cornerMinEigenVal(src, dst_gold, blockSize, apertureSize, borderType); cv::cornerMinEigenVal(src, dst_gold, blockSize, apertureSize, borderType);
EXPECT_MAT_NEAR(dst_gold, dst, 0.02); EXPECT_MAT_NEAR(dst_gold, dst, 0.02);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CornerMinEigen, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CornerMinEigen, testing::Combine(

View File

@ -168,35 +168,27 @@ struct Labeling : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(Labeling, ConnectedComponents) TEST_P(Labeling, ConnectedComponents)
{ {
try cv::Mat image;
{ cvtColor(loat_image(), image, CV_BGR2GRAY);
cv::Mat image;
cvtColor(loat_image(), image, CV_BGR2GRAY);
cv::threshold(image, image, 150, 255, CV_THRESH_BINARY); cv::threshold(image, image, 150, 255, CV_THRESH_BINARY);
ASSERT_TRUE(image.type() == CV_8UC1); ASSERT_TRUE(image.type() == CV_8UC1);
GreedyLabeling host(image); GreedyLabeling host(image);
host(host._labels); host(host._labels);
cv::gpu::GpuMat mask; cv::gpu::GpuMat mask;
mask.create(image.rows, image.cols, CV_8UC1); mask.create(image.rows, image.cols, CV_8UC1);
cv::gpu::GpuMat components; cv::gpu::GpuMat components;
components.create(image.rows, image.cols, CV_32SC1); components.create(image.rows, image.cols, CV_32SC1);
cv::gpu::connectivityMask(cv::gpu::GpuMat(image), mask, cv::Scalar::all(0), cv::Scalar::all(2)); cv::gpu::connectivityMask(cv::gpu::GpuMat(image), mask, cv::Scalar::all(0), cv::Scalar::all(2));
ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components)); ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components));
host.checkCorrectness(cv::Mat(components)); host.checkCorrectness(cv::Mat(components));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(ConnectedComponents, Labeling, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(ConnectedComponents, Labeling, ALL_DEVICES);

View File

@ -69,169 +69,82 @@ struct NVidiaTest : TestWithParam<cv::gpu::DeviceInfo>
struct NPPST : NVidiaTest {}; struct NPPST : NVidiaTest {};
struct NCV : NVidiaTest {}; struct NCV : NVidiaTest {};
TEST_P(NPPST, Integral) //TEST_P(NPPST, Integral)
{ //{
try // bool res = nvidia_NPPST_Integral_Image(path, nvidiaTestOutputLevel);
{
bool res = nvidia_NPPST_Integral_Image(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); // ASSERT_TRUE(res);
} //}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
}
TEST_P(NPPST, SquaredIntegral) TEST_P(NPPST, SquaredIntegral)
{ {
try bool res = nvidia_NPPST_Squared_Integral_Image(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NPPST_Squared_Integral_Image(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NPPST, RectStdDev) TEST_P(NPPST, RectStdDev)
{ {
try bool res = nvidia_NPPST_RectStdDev(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NPPST_RectStdDev(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NPPST, Resize) TEST_P(NPPST, Resize)
{ {
try bool res = nvidia_NPPST_Resize(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NPPST_Resize(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NPPST, VectorOperations) TEST_P(NPPST, VectorOperations)
{ {
try bool res = nvidia_NPPST_Vector_Operations(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NPPST_Vector_Operations(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NPPST, Transpose) TEST_P(NPPST, Transpose)
{ {
try bool res = nvidia_NPPST_Transpose(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NPPST_Transpose(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NCV, VectorOperations) TEST_P(NCV, VectorOperations)
{ {
try bool res = nvidia_NCV_Vector_Operations(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NCV_Vector_Operations(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NCV, HaarCascadeLoader) TEST_P(NCV, HaarCascadeLoader)
{ {
try bool res = nvidia_NCV_Haar_Cascade_Loader(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NCV_Haar_Cascade_Loader(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NCV, HaarCascadeApplication) TEST_P(NCV, HaarCascadeApplication)
{ {
try bool res = nvidia_NCV_Haar_Cascade_Application(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NCV_Haar_Cascade_Application(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NCV, HypothesesFiltration) TEST_P(NCV, HypothesesFiltration)
{ {
try bool res = nvidia_NCV_Hypotheses_Filtration(_path, nvidiaTestOutputLevel);
{
bool res = nvidia_NCV_Hypotheses_Filtration(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(NCV, Visualization) TEST_P(NCV, Visualization)
{ {
try // this functionality doesn't used in gpu module
{ bool res = nvidia_NCV_Visualization(_path, nvidiaTestOutputLevel);
bool res = nvidia_NCV_Visualization(_path, nvidiaTestOutputLevel);
ASSERT_TRUE(res); ASSERT_TRUE(res);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_NVidia, NPPST, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_NVidia, NPPST, ALL_DEVICES);

View File

@ -175,129 +175,114 @@ struct HOG : testing::TestWithParam<cv::gpu::DeviceInfo>, cv::gpu::HOGDescriptor
} }
}; };
TEST_P(HOG, Detect) // desabled while resize does not fixed
TEST_P(HOG, DISABLED_Detect)
{ {
try cv::Mat img_rgb = readImage("hog/road.png");
{ ASSERT_FALSE(img_rgb.empty());
cv::Mat img_rgb = readImage("hog/road.png");
ASSERT_FALSE(img_rgb.empty());
#ifdef DUMP #ifdef DUMP
f.open((std::string(cvtest::TS::ptr()->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary); f.open((std::string(cvtest::TS::ptr()->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary);
ASSERT_TRUE(f.is_open()); ASSERT_TRUE(f.is_open());
#else #else
f.open((std::string(cvtest::TS::ptr()->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary); f.open((std::string(cvtest::TS::ptr()->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary);
ASSERT_TRUE(f.is_open()); ASSERT_TRUE(f.is_open());
#endif #endif
// Test on color image // Test on color image
cv::Mat img; cv::Mat img;
cv::cvtColor(img_rgb, img, CV_BGR2BGRA); cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
testDetect(img); testDetect(img);
// Test on gray image // Test on gray image
cv::cvtColor(img_rgb, img, CV_BGR2GRAY); cv::cvtColor(img_rgb, img, CV_BGR2GRAY);
testDetect(img); testDetect(img);
f.close(); f.close();
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(HOG, GetDescriptors) TEST_P(HOG, GetDescriptors)
{ {
try // Load image (e.g. train data, composed from windows)
cv::Mat img_rgb = readImage("hog/train_data.png");
ASSERT_FALSE(img_rgb.empty());
// Convert to C4
cv::Mat img;
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
cv::gpu::GpuMat d_img(img);
// Convert train images into feature vectors (train table)
cv::gpu::GpuMat descriptors, descriptors_by_cols;
getDescriptors(d_img, win_size, descriptors, DESCR_FORMAT_ROW_BY_ROW);
getDescriptors(d_img, win_size, descriptors_by_cols, DESCR_FORMAT_COL_BY_COL);
// Check size of the result train table
wins_per_img_x = 3;
wins_per_img_y = 2;
blocks_per_win_x = 7;
blocks_per_win_y = 15;
block_hist_size = 36;
cv::Size descr_size_expected = cv::Size(blocks_per_win_x * blocks_per_win_y * block_hist_size,
wins_per_img_x * wins_per_img_y);
ASSERT_EQ(descr_size_expected, descriptors.size());
// Check both formats of output descriptors are handled correctly
cv::Mat dr(descriptors);
cv::Mat dc(descriptors_by_cols);
for (int i = 0; i < wins_per_img_x * wins_per_img_y; ++i)
{ {
// Load image (e.g. train data, composed from windows) const float* l = dr.rowRange(i, i + 1).ptr<float>();
cv::Mat img_rgb = readImage("hog/train_data.png"); const float* r = dc.rowRange(i, i + 1).ptr<float>();
ASSERT_FALSE(img_rgb.empty()); for (int y = 0; y < blocks_per_win_y; ++y)
for (int x = 0; x < blocks_per_win_x; ++x)
// Convert to C4 for (int k = 0; k < block_hist_size; ++k)
cv::Mat img; ASSERT_EQ(l[(y * blocks_per_win_x + x) * block_hist_size + k],
cv::cvtColor(img_rgb, img, CV_BGR2BGRA); r[(x * blocks_per_win_y + y) * block_hist_size + k]);
cv::gpu::GpuMat d_img(img);
// Convert train images into feature vectors (train table)
cv::gpu::GpuMat descriptors, descriptors_by_cols;
getDescriptors(d_img, win_size, descriptors, DESCR_FORMAT_ROW_BY_ROW);
getDescriptors(d_img, win_size, descriptors_by_cols, DESCR_FORMAT_COL_BY_COL);
// Check size of the result train table
wins_per_img_x = 3;
wins_per_img_y = 2;
blocks_per_win_x = 7;
blocks_per_win_y = 15;
block_hist_size = 36;
cv::Size descr_size_expected = cv::Size(blocks_per_win_x * blocks_per_win_y * block_hist_size,
wins_per_img_x * wins_per_img_y);
ASSERT_EQ(descr_size_expected, descriptors.size());
// Check both formats of output descriptors are handled correctly
cv::Mat dr(descriptors);
cv::Mat dc(descriptors_by_cols);
for (int i = 0; i < wins_per_img_x * wins_per_img_y; ++i)
{
const float* l = dr.rowRange(i, i + 1).ptr<float>();
const float* r = dc.rowRange(i, i + 1).ptr<float>();
for (int y = 0; y < blocks_per_win_y; ++y)
for (int x = 0; x < blocks_per_win_x; ++x)
for (int k = 0; k < block_hist_size; ++k)
ASSERT_EQ(l[(y * blocks_per_win_x + x) * block_hist_size + k],
r[(x * blocks_per_win_y + y) * block_hist_size + k]);
}
/* Now we want to extract the same feature vectors, but from single images. NOTE: results will
be defferent, due to border values interpolation. Using of many small images is slower, however we
wont't call getDescriptors and will use computeBlockHistograms instead of. computeBlockHistograms
works good, it can be checked in the gpu_hog sample */
img_rgb = readImage("hog/positive1.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
// Everything is fine with interpolation for left top subimage
ASSERT_EQ(0.0, cv::norm((cv::Mat)block_hists, (cv::Mat)descriptors.rowRange(0, 1)));
img_rgb = readImage("hog/positive2.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(1, 2)));
img_rgb = readImage("hog/negative1.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(2, 3)));
img_rgb = readImage("hog/negative2.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(3, 4)));
img_rgb = readImage("hog/positive3.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(4, 5)));
img_rgb = readImage("hog/negative3.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(5, 6)));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
/* Now we want to extract the same feature vectors, but from single images. NOTE: results will
be defferent, due to border values interpolation. Using of many small images is slower, however we
wont't call getDescriptors and will use computeBlockHistograms instead of. computeBlockHistograms
works good, it can be checked in the gpu_hog sample */
img_rgb = readImage("hog/positive1.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
// Everything is fine with interpolation for left top subimage
ASSERT_EQ(0.0, cv::norm((cv::Mat)block_hists, (cv::Mat)descriptors.rowRange(0, 1)));
img_rgb = readImage("hog/positive2.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(1, 2)));
img_rgb = readImage("hog/negative1.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(2, 3)));
img_rgb = readImage("hog/negative2.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(3, 4)));
img_rgb = readImage("hog/positive3.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(4, 5)));
img_rgb = readImage("hog/negative3.png");
ASSERT_TRUE(!img_rgb.empty());
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
computeBlockHistograms(cv::gpu::GpuMat(img));
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(5, 6)));
} }
INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, HOG, ALL_DEVICES); INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, HOG, ALL_DEVICES);
@ -320,35 +305,27 @@ struct CalTech : public ::testing::TestWithParam<std::tr1::tuple<cv::gpu::Device
TEST_P(CalTech, HOG) TEST_P(CalTech, HOG)
{ {
try cv::gpu::GpuMat d_img(img);
cv::Mat markedImage(img.clone());
cv::gpu::HOGDescriptor d_hog;
d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
d_hog.nlevels = d_hog.nlevels + 32;
std::vector<cv::Rect> found_locations;
d_hog.detectMultiScale(d_img, found_locations);
#if defined (LOG_CASCADE_STATISTIC)
for (int i = 0; i < (int)found_locations.size(); i++)
{ {
cv::gpu::GpuMat d_img(img); cv::Rect r = found_locations[i];
cv::Mat markedImage(img.clone());
cv::gpu::HOGDescriptor d_hog; std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl;
d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); cv::rectangle(markedImage, r , CV_RGB(255, 0, 0));
d_hog.nlevels = d_hog.nlevels + 32;
std::vector<cv::Rect> found_locations;
d_hog.detectMultiScale(d_img, found_locations);
#if defined (LOG_CASCADE_STATISTIC)
for (int i = 0; i < (int)found_locations.size(); i++)
{
cv::Rect r = found_locations[i];
std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl;
cv::rectangle(markedImage, r , CV_RGB(255, 0, 0));
}
cv::imshow("Res", markedImage); cv::waitKey();
#endif
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
cv::imshow("Res", markedImage); cv::waitKey();
#endif
} }
INSTANTIATE_TEST_CASE_P(detect, CalTech, testing::Combine(ALL_DEVICES, INSTANTIATE_TEST_CASE_P(detect, CalTech, testing::Combine(ALL_DEVICES,
@ -375,17 +352,9 @@ PARAM_TEST_CASE(LBP_Read_classifier, cv::gpu::DeviceInfo, int)
TEST_P(LBP_Read_classifier, Accuracy) TEST_P(LBP_Read_classifier, Accuracy)
{ {
try cv::gpu::CascadeClassifier_GPU classifier;
{ std::string classifierXmlPath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/lbpcascade_frontalface.xml";
cv::gpu::CascadeClassifier_GPU classifier; ASSERT_TRUE(classifier.load(classifierXmlPath));
std::string classifierXmlPath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/lbpcascade_frontalface.xml";
ASSERT_TRUE(classifier.load(classifierXmlPath));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_Read_classifier, INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_Read_classifier,
@ -405,57 +374,49 @@ PARAM_TEST_CASE(LBP_classify, cv::gpu::DeviceInfo, int)
TEST_P(LBP_classify, Accuracy) TEST_P(LBP_classify, Accuracy)
{ {
try std::string classifierXmlPath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/lbpcascade_frontalface.xml";
std::string imagePath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/er.png";
cv::CascadeClassifier cpuClassifier(classifierXmlPath);
ASSERT_FALSE(cpuClassifier.empty());
cv::Mat image = cv::imread(imagePath);
image = image.colRange(0, image.cols/2);
cv::Mat grey;
cvtColor(image, grey, CV_BGR2GRAY);
ASSERT_FALSE(image.empty());
std::vector<cv::Rect> rects;
cpuClassifier.detectMultiScale(grey, rects);
cv::Mat markedImage = image.clone();
std::vector<cv::Rect>::iterator it = rects.begin();
for (; it != rects.end(); ++it)
cv::rectangle(markedImage, *it, CV_RGB(0, 0, 255));
cv::gpu::CascadeClassifier_GPU gpuClassifier;
ASSERT_TRUE(gpuClassifier.load(classifierXmlPath));
cv::gpu::GpuMat gpu_rects;
cv::gpu::GpuMat tested(grey);
int count = gpuClassifier.detectMultiScale(tested, gpu_rects);
#if defined (LOG_CASCADE_STATISTIC)
cv::Mat downloaded(gpu_rects);
const cv::Rect* faces = downloaded.ptr<cv::Rect>();
for (int i = 0; i < count; i++)
{ {
std::string classifierXmlPath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/lbpcascade_frontalface.xml"; cv::Rect r = faces[i];
std::string imagePath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/er.png";
cv::CascadeClassifier cpuClassifier(classifierXmlPath); std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl;
ASSERT_FALSE(cpuClassifier.empty()); cv::rectangle(markedImage, r , CV_RGB(255, 0, 0));
cv::Mat image = cv::imread(imagePath);
image = image.colRange(0, image.cols/2);
cv::Mat grey;
cvtColor(image, grey, CV_BGR2GRAY);
ASSERT_FALSE(image.empty());
std::vector<cv::Rect> rects;
cpuClassifier.detectMultiScale(grey, rects);
cv::Mat markedImage = image.clone();
std::vector<cv::Rect>::iterator it = rects.begin();
for (; it != rects.end(); ++it)
cv::rectangle(markedImage, *it, CV_RGB(0, 0, 255));
cv::gpu::CascadeClassifier_GPU gpuClassifier;
ASSERT_TRUE(gpuClassifier.load(classifierXmlPath));
cv::gpu::GpuMat gpu_rects;
cv::gpu::GpuMat tested(grey);
int count = gpuClassifier.detectMultiScale(tested, gpu_rects);
#if defined (LOG_CASCADE_STATISTIC)
cv::Mat downloaded(gpu_rects);
const cv::Rect* faces = downloaded.ptr<cv::Rect>();
for (int i = 0; i < count; i++)
{
cv::Rect r = faces[i];
std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl;
cv::rectangle(markedImage, r , CV_RGB(255, 0, 0));
}
#endif
#if defined (LOG_CASCADE_STATISTIC)
cv::imshow("Res", markedImage); cv::waitKey();
#endif
(void)count;
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
#endif
#if defined (LOG_CASCADE_STATISTIC)
cv::imshow("Res", markedImage); cv::waitKey();
#endif
(void)count;
} }
INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_classify, INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_classify,

View File

@ -70,402 +70,258 @@ PARAM_TEST_CASE(GlBuffer, cv::Size, MatType)
TEST_P(GlBuffer, Constructor1) TEST_P(GlBuffer, Constructor1)
{ {
try cv::GlBuffer buf(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
{
cv::GlBuffer buf(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_EQ(size.height, buf.rows()); EXPECT_EQ(size.height, buf.rows());
EXPECT_EQ(size.width, buf.cols()); EXPECT_EQ(size.width, buf.cols());
EXPECT_EQ(type, buf.type()); EXPECT_EQ(type, buf.type());
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, Constructor2) TEST_P(GlBuffer, Constructor2)
{ {
try cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
{
cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_EQ(size.height, buf.rows()); EXPECT_EQ(size.height, buf.rows());
EXPECT_EQ(size.width, buf.cols()); EXPECT_EQ(size.width, buf.cols());
EXPECT_EQ(type, buf.type()); EXPECT_EQ(type, buf.type());
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, ConstructorFromMat) TEST_P(GlBuffer, ConstructorFromMat)
{ {
try cv::Mat gold = randomMat(size, type);
{
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, ConstructorFromGpuMat) TEST_P(GlBuffer, ConstructorFromGpuMat)
{ {
try cv::Mat gold = randomMat(size, type);
{ cv::gpu::GpuMat d_gold(gold);
cv::Mat gold = randomMat(size, type);
cv::gpu::GpuMat d_gold(gold);
cv::GlBuffer buf(d_gold, cv::GlBuffer::ARRAY_BUFFER); cv::GlBuffer buf(d_gold, cv::GlBuffer::ARRAY_BUFFER);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, ConstructorFromGlBuffer) TEST_P(GlBuffer, ConstructorFromGlBuffer)
{ {
try cv::GlBuffer buf_gold(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
{
cv::GlBuffer buf_gold(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer buf(buf_gold); cv::GlBuffer buf(buf_gold);
EXPECT_EQ(buf_gold.bufId(), buf.bufId()); EXPECT_EQ(buf_gold.bufId(), buf.bufId());
EXPECT_EQ(buf_gold.rows(), buf.rows()); EXPECT_EQ(buf_gold.rows(), buf.rows());
EXPECT_EQ(buf_gold.cols(), buf.cols()); EXPECT_EQ(buf_gold.cols(), buf.cols());
EXPECT_EQ(buf_gold.type(), buf.type()); EXPECT_EQ(buf_gold.type(), buf.type());
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, ConstructorFromGlTexture2D) TEST_P(GlBuffer, ConstructorFromGlTexture2D)
{ {
try const int depth = CV_MAT_DEPTH(type);
{ const int cn = CV_MAT_CN(type);
const int depth = CV_MAT_DEPTH(type);
const int cn = CV_MAT_CN(type);
if (depth != CV_32F || cn == 2) if (depth != CV_32F || cn == 2)
return; return;
cv::Mat gold = randomMat(size, type, 0, 1.0); cv::Mat gold = randomMat(size, type, 0, 1.0);
cv::GlTexture2D tex_gold(gold, true); cv::GlTexture2D tex_gold(gold, true);
cv::GlBuffer buf(tex_gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true); cv::GlBuffer buf(tex_gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 1e-2); EXPECT_MAT_NEAR(gold, bufData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, Create) TEST_P(GlBuffer, Create)
{ {
try cv::GlBuffer buf;
{ buf.create(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer buf;
buf.create(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_EQ(size.height, buf.rows()); EXPECT_EQ(size.height, buf.rows());
EXPECT_EQ(size.width, buf.cols()); EXPECT_EQ(size.width, buf.cols());
EXPECT_EQ(type, buf.type()); EXPECT_EQ(type, buf.type());
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, CopyFromMat) TEST_P(GlBuffer, CopyFromMat)
{ {
try cv::Mat gold = randomMat(size, type);
{
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.copyFrom(gold, cv::GlBuffer::ARRAY_BUFFER, true); buf.copyFrom(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, CopyFromGpuMat) TEST_P(GlBuffer, CopyFromGpuMat)
{ {
try cv::Mat gold = randomMat(size, type);
{ cv::gpu::GpuMat d_gold(gold);
cv::Mat gold = randomMat(size, type);
cv::gpu::GpuMat d_gold(gold);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.copyFrom(d_gold, cv::GlBuffer::ARRAY_BUFFER, true); buf.copyFrom(d_gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, CopyFromGlBuffer) TEST_P(GlBuffer, CopyFromGlBuffer)
{ {
try cv::Mat gold = randomMat(size, type);
{ cv::GlBuffer buf_gold(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf_gold(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.copyFrom(buf_gold, cv::GlBuffer::ARRAY_BUFFER, true); buf.copyFrom(buf_gold, cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_NE(buf_gold.bufId(), buf.bufId()); EXPECT_NE(buf_gold.bufId(), buf.bufId());
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, CopyFromGlTexture2D) TEST_P(GlBuffer, CopyFromGlTexture2D)
{ {
try const int depth = CV_MAT_DEPTH(type);
{ const int cn = CV_MAT_CN(type);
const int depth = CV_MAT_DEPTH(type);
const int cn = CV_MAT_CN(type);
if (depth != CV_32F || cn == 2) if (depth != CV_32F || cn == 2)
return; return;
cv::Mat gold = randomMat(size, type, 0, 1.0); cv::Mat gold = randomMat(size, type, 0, 1.0);
cv::GlTexture2D tex_gold(gold, true); cv::GlTexture2D tex_gold(gold, true);
cv::GlBuffer buf; cv::GlBuffer buf;
buf.copyFrom(tex_gold, cv::GlBuffer::ARRAY_BUFFER, true); buf.copyFrom(tex_gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 1e-2); EXPECT_MAT_NEAR(gold, bufData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, CopyToGpuMat) TEST_P(GlBuffer, CopyToGpuMat)
{ {
try cv::Mat gold = randomMat(size, type);
{
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
buf.copyTo(dst); buf.copyTo(dst);
EXPECT_MAT_NEAR(gold, dst, 0); EXPECT_MAT_NEAR(gold, dst, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, CopyToGlBuffer) TEST_P(GlBuffer, CopyToGlBuffer)
{ {
try cv::Mat gold = randomMat(size, type);
{
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer dst; cv::GlBuffer dst;
buf.copyTo(dst, cv::GlBuffer::ARRAY_BUFFER, true); buf.copyTo(dst, cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_NE(buf.bufId(), dst.bufId()); EXPECT_NE(buf.bufId(), dst.bufId());
cv::Mat bufData; cv::Mat bufData;
dst.copyTo(bufData); dst.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, CopyToGlTexture2D) TEST_P(GlBuffer, CopyToGlTexture2D)
{ {
try const int depth = CV_MAT_DEPTH(type);
{ const int cn = CV_MAT_CN(type);
const int depth = CV_MAT_DEPTH(type);
const int cn = CV_MAT_CN(type);
if (depth != CV_32F || cn == 2) if (depth != CV_32F || cn == 2)
return; return;
cv::Mat gold = randomMat(size, type, 0, 1.0); cv::Mat gold = randomMat(size, type, 0, 1.0);
cv::GlBuffer buf(gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true); cv::GlBuffer buf(gold, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
cv::GlTexture2D tex; cv::GlTexture2D tex;
buf.copyTo(tex, cv::GlBuffer::PIXEL_PACK_BUFFER, true); buf.copyTo(tex, cv::GlBuffer::PIXEL_PACK_BUFFER, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData); tex.copyTo(texData);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, Clone) TEST_P(GlBuffer, Clone)
{ {
try cv::Mat gold = randomMat(size, type);
{
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::GlBuffer dst = buf.clone(cv::GlBuffer::ARRAY_BUFFER, true); cv::GlBuffer dst = buf.clone(cv::GlBuffer::ARRAY_BUFFER, true);
EXPECT_NE(buf.bufId(), dst.bufId()); EXPECT_NE(buf.bufId(), dst.bufId());
cv::Mat bufData; cv::Mat bufData;
dst.copyTo(bufData); dst.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, MapHostRead) TEST_P(GlBuffer, MapHostRead)
{ {
try cv::Mat gold = randomMat(size, type);
{
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat dst = buf.mapHost(cv::GlBuffer::READ_ONLY); cv::Mat dst = buf.mapHost(cv::GlBuffer::READ_ONLY);
EXPECT_MAT_NEAR(gold, dst, 0); EXPECT_MAT_NEAR(gold, dst, 0);
buf.unmapHost(); buf.unmapHost();
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, MapHostWrite) TEST_P(GlBuffer, MapHostWrite)
{ {
try cv::Mat gold = randomMat(size, type);
{
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true); cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true);
cv::Mat dst = buf.mapHost(cv::GlBuffer::WRITE_ONLY); cv::Mat dst = buf.mapHost(cv::GlBuffer::WRITE_ONLY);
gold.copyTo(dst); gold.copyTo(dst);
buf.unmapHost(); buf.unmapHost();
dst.release(); dst.release();
cv::Mat bufData; cv::Mat bufData;
buf.copyTo(bufData); buf.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 0); EXPECT_MAT_NEAR(gold, bufData, 0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlBuffer, MapDevice) TEST_P(GlBuffer, MapDevice)
{ {
try cv::Mat gold = randomMat(size, type);
{
cv::Mat gold = randomMat(size, type);
cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true); cv::GlBuffer buf(gold, cv::GlBuffer::ARRAY_BUFFER, true);
cv::gpu::GpuMat dst = buf.mapDevice(); cv::gpu::GpuMat dst = buf.mapDevice();
EXPECT_MAT_NEAR(gold, dst, 0); EXPECT_MAT_NEAR(gold, dst, 0);
buf.unmapDevice(); buf.unmapDevice();
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(OpenGL, GlBuffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES)); INSTANTIATE_TEST_CASE_P(OpenGL, GlBuffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES));
@ -504,243 +360,147 @@ PARAM_TEST_CASE(GlTexture2D, cv::Size, MatType)
TEST_P(GlTexture2D, Constructor1) TEST_P(GlTexture2D, Constructor1)
{ {
try cv::GlTexture2D tex(size.height, size.width, format, true);
{
cv::GlTexture2D tex(size.height, size.width, format, true);
EXPECT_EQ(size.height, tex.rows()); EXPECT_EQ(size.height, tex.rows());
EXPECT_EQ(size.width, tex.cols()); EXPECT_EQ(size.width, tex.cols());
EXPECT_EQ(format, tex.format()); EXPECT_EQ(format, tex.format());
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, Constructor2) TEST_P(GlTexture2D, Constructor2)
{ {
try cv::GlTexture2D tex(size, format, true);
{
cv::GlTexture2D tex(size, format, true);
EXPECT_EQ(size.height, tex.rows()); EXPECT_EQ(size.height, tex.rows());
EXPECT_EQ(size.width, tex.cols()); EXPECT_EQ(size.width, tex.cols());
EXPECT_EQ(format, tex.format()); EXPECT_EQ(format, tex.format());
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, ConstructorFromMat) TEST_P(GlTexture2D, ConstructorFromMat)
{ {
try cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
{
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlTexture2D tex(gold, true); cv::GlTexture2D tex(gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, ConstructorFromGpuMat) TEST_P(GlTexture2D, ConstructorFromGpuMat)
{ {
try cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
{ cv::gpu::GpuMat d_gold(gold);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::gpu::GpuMat d_gold(gold);
cv::GlTexture2D tex(d_gold, true); cv::GlTexture2D tex(d_gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, ConstructorFromGlBuffer) TEST_P(GlTexture2D, ConstructorFromGlBuffer)
{ {
try cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
{ cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
cv::GlTexture2D tex(buf_gold, true); cv::GlTexture2D tex(buf_gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, ConstructorFromGlTexture2D) TEST_P(GlTexture2D, ConstructorFromGlTexture2D)
{ {
try cv::GlTexture2D tex_gold(size, format, true);
{ cv::GlTexture2D tex(tex_gold);
cv::GlTexture2D tex_gold(size, format, true);
cv::GlTexture2D tex(tex_gold);
EXPECT_EQ(tex_gold.texId(), tex.texId()); EXPECT_EQ(tex_gold.texId(), tex.texId());
EXPECT_EQ(tex_gold.rows(), tex.rows()); EXPECT_EQ(tex_gold.rows(), tex.rows());
EXPECT_EQ(tex_gold.cols(), tex.cols()); EXPECT_EQ(tex_gold.cols(), tex.cols());
EXPECT_EQ(tex_gold.format(), tex.format()); EXPECT_EQ(tex_gold.format(), tex.format());
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, Create) TEST_P(GlTexture2D, Create)
{ {
try cv::GlTexture2D tex;
{ tex.create(size.height, size.width, format, true);
cv::GlTexture2D tex;
tex.create(size.height, size.width, format, true);
EXPECT_EQ(size.height, tex.rows()); EXPECT_EQ(size.height, tex.rows());
EXPECT_EQ(size.width, tex.cols()); EXPECT_EQ(size.width, tex.cols());
EXPECT_EQ(format, tex.format()); EXPECT_EQ(format, tex.format());
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, CopyFromMat) TEST_P(GlTexture2D, CopyFromMat)
{ {
try cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
{
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlTexture2D tex; cv::GlTexture2D tex;
tex.copyFrom(gold, true); tex.copyFrom(gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, CopyFromGpuMat) TEST_P(GlTexture2D, CopyFromGpuMat)
{ {
try cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
{ cv::gpu::GpuMat d_gold(gold);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::gpu::GpuMat d_gold(gold);
cv::GlTexture2D tex; cv::GlTexture2D tex;
tex.copyFrom(d_gold, true); tex.copyFrom(d_gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, CopyFromGlBuffer) TEST_P(GlTexture2D, CopyFromGlBuffer)
{ {
try cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
{ cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlBuffer buf_gold(gold, cv::GlBuffer::PIXEL_UNPACK_BUFFER, true);
cv::GlTexture2D tex; cv::GlTexture2D tex;
tex.copyFrom(buf_gold, true); tex.copyFrom(buf_gold, true);
cv::Mat texData; cv::Mat texData;
tex.copyTo(texData, depth); tex.copyTo(texData, depth);
EXPECT_MAT_NEAR(gold, texData, 1e-2); EXPECT_MAT_NEAR(gold, texData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, CopyToGpuMat) TEST_P(GlTexture2D, CopyToGpuMat)
{ {
try cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
{
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlTexture2D tex(gold, true); cv::GlTexture2D tex(gold, true);
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
tex.copyTo(dst, depth); tex.copyTo(dst, depth);
EXPECT_MAT_NEAR(gold, dst, 1e-2); EXPECT_MAT_NEAR(gold, dst, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
TEST_P(GlTexture2D, CopyToGlBuffer) TEST_P(GlTexture2D, CopyToGlBuffer)
{ {
try cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
{
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
cv::GlTexture2D tex(gold, true); cv::GlTexture2D tex(gold, true);
cv::GlBuffer dst; cv::GlBuffer dst;
tex.copyTo(dst, depth, true); tex.copyTo(dst, depth, true);
cv::Mat bufData; cv::Mat bufData;
dst.copyTo(bufData); dst.copyTo(bufData);
EXPECT_MAT_NEAR(gold, bufData, 1e-2); EXPECT_MAT_NEAR(gold, bufData, 1e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(OpenGL, GlTexture2D, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4))); INSTANTIATE_TEST_CASE_P(OpenGL, GlTexture2D, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4)));

View File

@ -66,23 +66,15 @@ PARAM_TEST_CASE(PyrDown, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
TEST_P(PyrDown, Accuracy) TEST_P(PyrDown, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat dst = createMat(cv::Size((size.width + 1) / 2, (size.height + 1) / 2), type, useRoi); cv::gpu::GpuMat dst = createMat(cv::Size((size.width + 1) / 2, (size.height + 1) / 2), type, useRoi);
cv::gpu::pyrDown(loadMat(src, useRoi), dst); cv::gpu::pyrDown(loadMat(src, useRoi), dst);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::pyrDown(src, dst_gold); cv::pyrDown(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, PyrDown, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, PyrDown, testing::Combine(
@ -114,23 +106,15 @@ PARAM_TEST_CASE(PyrUp, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
TEST_P(PyrUp, Accuracy) TEST_P(PyrUp, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat dst = createMat(cv::Size(size.width * 2, size.height * 2), type, useRoi); cv::gpu::GpuMat dst = createMat(cv::Size(size.width * 2, size.height * 2), type, useRoi);
cv::gpu::pyrUp(loadMat(src, useRoi), dst); cv::gpu::pyrUp(loadMat(src, useRoi), dst);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::pyrUp(src, dst_gold); cv::pyrUp(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-4 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, PyrUp, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, PyrUp, testing::Combine(

View File

@ -154,24 +154,16 @@ PARAM_TEST_CASE(Remap, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, Bo
TEST_P(Remap, Accuracy) TEST_P(Remap, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ cv::Scalar val = randomScalar(0.0, 255.0);
cv::Mat src = randomMat(size, type);
cv::Scalar val = randomScalar(0.0, 255.0);
cv::gpu::GpuMat dst = createMat(xmap.size(), type, useRoi); cv::gpu::GpuMat dst = createMat(xmap.size(), type, useRoi);
cv::gpu::remap(loadMat(src, useRoi), dst, loadMat(xmap, useRoi), loadMat(ymap, useRoi), interpolation, borderType, val); cv::gpu::remap(loadMat(src, useRoi), dst, loadMat(xmap, useRoi), loadMat(ymap, useRoi), interpolation, borderType, val);
cv::Mat dst_gold; cv::Mat dst_gold;
remapGold(src, xmap, ymap, dst_gold, interpolation, borderType, val); remapGold(src, xmap, ymap, dst_gold, interpolation, borderType, val);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Remap, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Remap, testing::Combine(

View File

@ -138,23 +138,15 @@ PARAM_TEST_CASE(Resize, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpol
TEST_P(Resize, Accuracy) TEST_P(Resize, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi); cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation); cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);
cv::Mat dst_gold; cv::Mat dst_gold;
resizeGold(src, dst_gold, coeff, coeff, interpolation); resizeGold(src, dst_gold, coeff, coeff, interpolation);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Resize, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Resize, testing::Combine(
@ -192,23 +184,15 @@ PARAM_TEST_CASE(ResizeSameAsHost, cv::gpu::DeviceInfo, cv::Size, MatType, double
// downscaling only: used for classifiers // downscaling only: used for classifiers
TEST_P(ResizeSameAsHost, Accuracy) TEST_P(ResizeSameAsHost, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{
cv::Mat src = randomMat(size, type);
cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi); cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation); cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::resize(src, dst_gold, cv::Size(), coeff, coeff, interpolation); cv::resize(src, dst_gold, cv::Size(), coeff, coeff, interpolation);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeSameAsHost, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeSameAsHost, testing::Combine(
@ -242,24 +226,16 @@ PARAM_TEST_CASE(ResizeNPP, cv::gpu::DeviceInfo, MatType, double, Interpolation)
TEST_P(ResizeNPP, Accuracy) TEST_P(ResizeNPP, Accuracy)
{ {
try cv::Mat src = readImageType("stereobp/aloe-L.png", type);
{ ASSERT_FALSE(src.empty());
cv::Mat src = readImageType("stereobp/aloe-L.png", type);
ASSERT_FALSE(src.empty());
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::resize(loadMat(src), dst, cv::Size(), coeff, coeff, interpolation); cv::gpu::resize(loadMat(src), dst, cv::Size(), coeff, coeff, interpolation);
cv::Mat dst_gold; cv::Mat dst_gold;
resizeGold(src, dst_gold, coeff, coeff, interpolation); resizeGold(src, dst_gold, coeff, coeff, interpolation);
EXPECT_MAT_SIMILAR(dst_gold, dst, 1e-1); EXPECT_MAT_SIMILAR(dst_gold, dst, 1e-1);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeNPP, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeNPP, testing::Combine(

View File

@ -40,7 +40,7 @@
// //
//M*/ //M*/
#include "test_precomp.hpp" #include <test_precomp.hpp>
#include <time.h> #include <time.h>
#ifdef HAVE_CUDA #ifdef HAVE_CUDA
@ -158,77 +158,62 @@ GPU_TEST_P(SCascadeTestRoi, detect,
testing::Values(std::string("../cv/cascadeandhog/bahnhof/image_00000000_0.png")), testing::Values(std::string("../cv/cascadeandhog/bahnhof/image_00000000_0.png")),
testing::Range(0, 5))) testing::Range(0, 5)))
{ {
try cv::gpu::setDevice(GET_PARAM(0).deviceID());
cv::Mat coloredCpu = cv::imread(cvtest::TS::ptr()->get_data_path() + GET_PARAM(2));
ASSERT_FALSE(coloredCpu.empty());
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(1)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
GpuMat colored(coloredCpu), objectBoxes(1, 16384, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0);
int nroi = GET_PARAM(3);
cv::Mat result(coloredCpu);
cv::RNG rng;
for (int i = 0; i < nroi; ++i)
{ {
cv::gpu::setDevice(GET_PARAM(0).deviceID()); cv::Rect r = getFromTable(rng(10));
cv::Mat coloredCpu = cv::imread(cvtest::TS::ptr()->get_data_path() + GET_PARAM(2)); GpuMat sub(rois, r);
ASSERT_FALSE(coloredCpu.empty()); sub.setTo(1);
cv::rectangle(result, r, cv::Scalar(0, 0, 255, 255), 1);
cv::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(1)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
GpuMat colored(coloredCpu), objectBoxes(1, 16384, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0);
int nroi = GET_PARAM(3);
cv::Mat result(coloredCpu);
cv::RNG rng;
for (int i = 0; i < nroi; ++i)
{
cv::Rect r = getFromTable(rng(10));
GpuMat sub(rois, r);
sub.setTo(1);
cv::rectangle(result, r, cv::Scalar(0, 0, 255, 255), 1);
}
objectBoxes.setTo(0);
cascade.detect(colored, rois, objectBoxes);
cv::Mat dt(objectBoxes);
typedef cv::gpu::SCascade::Detection Detection;
Detection* dts = ((Detection*)dt.data) + 1;
int* count = dt.ptr<int>(0);
printTotal(std::cout, *count);
for (int i = 0; i < *count; ++i)
{
Detection d = dts[i];
print(std::cout, d);
cv::rectangle(result, cv::Rect(d.x, d.y, d.w, d.h), cv::Scalar(255, 0, 0, 255), 1);
}
SHOW(result);
} }
catch (...) objectBoxes.setTo(0);
cascade.detect(colored, rois, objectBoxes);
cv::Mat dt(objectBoxes);
typedef cv::gpu::SCascade::Detection Detection;
Detection* dts = ((Detection*)dt.data) + 1;
int* count = dt.ptr<int>(0);
printTotal(std::cout, *count);
for (int i = 0; i < *count; ++i)
{ {
cv::gpu::resetDevice(); Detection d = dts[i];
throw; print(std::cout, d);
cv::rectangle(result, cv::Rect(d.x, d.y, d.w, d.h), cv::Scalar(255, 0, 0, 255), 1);
} }
SHOW(result);
} }
TEST(SCascadeTest, readCascade) TEST(SCascadeTest, readCascade)
{ {
try std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/icf-template.xml";
{ cv::gpu::SCascade cascade;
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/icf-template.xml";
cv::gpu::SCascade cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened()); ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
typedef ::testing::TestWithParam<cv::gpu::DeviceInfo > SCascadeTestAll; typedef ::testing::TestWithParam<cv::gpu::DeviceInfo > SCascadeTestAll;
@ -236,129 +221,105 @@ GPU_TEST_P(SCascadeTestAll, detect,
ALL_DEVICES ALL_DEVICES
) )
{ {
try cv::gpu::setDevice(GetParam().deviceID());
{ std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml";
cv::gpu::setDevice(GetParam().deviceID()); cv::gpu::SCascade cascade;
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml";
cv::gpu::SCascade cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened()); ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::Mat coloredCpu = cv::imread(cvtest::TS::ptr()->get_data_path() cv::Mat coloredCpu = cv::imread(cvtest::TS::ptr()->get_data_path()
+ "../cv/cascadeandhog/bahnhof/image_00000000_0.png"); + "../cv/cascadeandhog/bahnhof/image_00000000_0.png");
ASSERT_FALSE(coloredCpu.empty()); ASSERT_FALSE(coloredCpu.empty());
GpuMat colored(coloredCpu), objectBoxes, rois(colored.size(), CV_8UC1); GpuMat colored(coloredCpu), objectBoxes, rois(colored.size(), CV_8UC1);
rois.setTo(0); rois.setTo(0);
GpuMat sub(rois, cv::Rect(rois.cols / 4, rois.rows / 4,rois.cols / 2, rois.rows / 2)); GpuMat sub(rois, cv::Rect(rois.cols / 4, rois.rows / 4,rois.cols / 2, rois.rows / 2));
sub.setTo(cv::Scalar::all(1)); sub.setTo(cv::Scalar::all(1));
objectBoxes.setTo(0); objectBoxes.setTo(0);
cascade.detect(colored, rois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
typedef cv::gpu::SCascade::Detection Detection; typedef cv::gpu::SCascade::Detection Detection;
cv::Mat detections(objectBoxes); cv::Mat detections(objectBoxes);
int a = *(detections.ptr<int>(0)); int a = *(detections.ptr<int>(0));
ASSERT_EQ(a, 2448); ASSERT_EQ(a ,2448);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
GPU_TEST_P(SCascadeTestAll, detectOnIntegral, GPU_TEST_P(SCascadeTestAll, detectOnIntegral,
ALL_DEVICES ALL_DEVICES
) )
{ {
try cv::gpu::setDevice(GetParam().deviceID());
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml";
cv::gpu::SCascade cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
std::string intPath = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/integrals.xml";
cv::FileStorage fsi(intPath, cv::FileStorage::READ);
ASSERT_TRUE(fsi.isOpened());
GpuMat hogluv(121 * 10, 161, CV_32SC1);
for (int i = 0; i < 10; ++i)
{ {
cv::gpu::setDevice(GetParam().deviceID()); cv::Mat channel;
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml"; fsi[std::string("channel") + itoa(i)] >> channel;
cv::gpu::SCascade cascade; GpuMat gchannel(hogluv, cv::Rect(0, 121 * i, 161, 121));
gchannel.upload(channel);
cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
std::string intPath = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/integrals.xml";
cv::FileStorage fsi(intPath, cv::FileStorage::READ);
ASSERT_TRUE(fsi.isOpened());
GpuMat hogluv(121 * 10, 161, CV_32SC1);
for (int i = 0; i < 10; ++i)
{
cv::Mat channel;
fsi[std::string("channel") + itoa(i)] >> channel;
GpuMat gchannel(hogluv, cv::Rect(0, 121 * i, 161, 121));
gchannel.upload(channel);
}
GpuMat objectBoxes(1, 100000, CV_8UC1), rois(cv::Size(640, 480), CV_8UC1);
rois.setTo(1);
objectBoxes.setTo(0);
cascade.detect(hogluv, rois, objectBoxes);
typedef cv::gpu::SCascade::Detection Detection;
cv::Mat detections(objectBoxes);
int a = *(detections.ptr<int>(0));
ASSERT_EQ(a, 1024);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
GpuMat objectBoxes(1, 100000, CV_8UC1), rois(cv::Size(640, 480), CV_8UC1);
rois.setTo(1);
objectBoxes.setTo(0);
cascade.detect(hogluv, rois, objectBoxes);
typedef cv::gpu::SCascade::Detection Detection;
cv::Mat detections(objectBoxes);
int a = *(detections.ptr<int>(0));
ASSERT_EQ( a ,1024);
} }
GPU_TEST_P(SCascadeTestAll, detectStream, GPU_TEST_P(SCascadeTestAll, detectStream,
ALL_DEVICES ALL_DEVICES
) )
{ {
try cv::gpu::setDevice(GetParam().deviceID());
{ std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml";
cv::gpu::setDevice(GetParam().deviceID()); cv::gpu::SCascade cascade;
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml";
cv::gpu::SCascade cascade;
cv::FileStorage fs(xml, cv::FileStorage::READ); cv::FileStorage fs(xml, cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened()); ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::Mat coloredCpu = cv::imread(cvtest::TS::ptr()->get_data_path() cv::Mat coloredCpu = cv::imread(cvtest::TS::ptr()->get_data_path()
+ "../cv/cascadeandhog/bahnhof/image_00000000_0.png"); + "../cv/cascadeandhog/bahnhof/image_00000000_0.png");
ASSERT_FALSE(coloredCpu.empty()); ASSERT_FALSE(coloredCpu.empty());
GpuMat colored(coloredCpu), objectBoxes(1, 100000, CV_8UC1), rois(colored.size(), CV_8UC1); GpuMat colored(coloredCpu), objectBoxes(1, 100000, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0); rois.setTo(0);
GpuMat sub(rois, cv::Rect(rois.cols / 4, rois.rows / 4,rois.cols / 2, rois.rows / 2)); GpuMat sub(rois, cv::Rect(rois.cols / 4, rois.rows / 4,rois.cols / 2, rois.rows / 2));
sub.setTo(cv::Scalar::all(1)); sub.setTo(cv::Scalar::all(1));
cv::gpu::Stream s; cv::gpu::Stream s;
objectBoxes.setTo(0); objectBoxes.setTo(0);
cascade.detect(colored, rois, objectBoxes, s); cascade.detect(colored, rois, objectBoxes, s);
s.waitForCompletion(); s.waitForCompletion();
typedef cv::gpu::SCascade::Detection Detection; typedef cv::gpu::SCascade::Detection Detection;
cv::Mat detections(objectBoxes); cv::Mat detections(objectBoxes);
int a = *(detections.ptr<int>(0)); int a = *(detections.ptr<int>(0));
ASSERT_EQ(a, 2448); ASSERT_EQ(a ,2448);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
#endif #endif

View File

@ -68,25 +68,17 @@ PARAM_TEST_CASE(Threshold, cv::gpu::DeviceInfo, cv::Size, MatType, ThreshOp, Use
TEST_P(Threshold, Accuracy) TEST_P(Threshold, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ double maxVal = randomDouble(20.0, 127.0);
cv::Mat src = randomMat(size, type); double thresh = randomDouble(0.0, maxVal);
double maxVal = randomDouble(20.0, 127.0);
double thresh = randomDouble(0.0, maxVal);
cv::gpu::GpuMat dst = createMat(src.size(), src.type(), useRoi); cv::gpu::GpuMat dst = createMat(src.size(), src.type(), useRoi);
cv::gpu::threshold(loadMat(src, useRoi), dst, thresh, maxVal, threshOp); cv::gpu::threshold(loadMat(src, useRoi), dst, thresh, maxVal, threshOp);
cv::Mat dst_gold; cv::Mat dst_gold;
cv::threshold(src, dst_gold, thresh, maxVal, threshOp); cv::threshold(src, dst_gold, thresh, maxVal, threshOp);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Threshold, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Threshold, testing::Combine(

File diff suppressed because it is too large Load Diff

View File

@ -76,32 +76,24 @@ PARAM_TEST_CASE(BuildWarpAffineMaps, cv::gpu::DeviceInfo, cv::Size, Inverse)
TEST_P(BuildWarpAffineMaps, Accuracy) TEST_P(BuildWarpAffineMaps, Accuracy)
{ {
try cv::Mat M = createTransfomMatrix(size, CV_PI / 4);
{ cv::gpu::GpuMat xmap, ymap;
cv::Mat M = createTransfomMatrix(size, CV_PI / 4); cv::gpu::buildWarpAffineMaps(M, inverse, size, xmap, ymap);
cv::gpu::GpuMat xmap, ymap;
cv::gpu::buildWarpAffineMaps(M, inverse, size, xmap, ymap);
int interpolation = cv::INTER_NEAREST; int interpolation = cv::INTER_NEAREST;
int borderMode = cv::BORDER_CONSTANT; int borderMode = cv::BORDER_CONSTANT;
cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1); cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1);
cv::Mat dst; cv::Mat dst;
cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), interpolation, borderMode); cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), interpolation, borderMode);
int flags = interpolation; int flags = interpolation;
if (inverse) if (inverse)
flags |= cv::WARP_INVERSE_MAP; flags |= cv::WARP_INVERSE_MAP;
cv::Mat dst_gold; cv::Mat dst_gold;
cv::warpAffine(src, dst_gold, M, size, flags, borderMode); cv::warpAffine(src, dst_gold, M, size, flags, borderMode);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BuildWarpAffineMaps, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BuildWarpAffineMaps, testing::Combine(
@ -209,28 +201,20 @@ PARAM_TEST_CASE(WarpAffine, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Int
TEST_P(WarpAffine, Accuracy) TEST_P(WarpAffine, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ cv::Mat M = createTransfomMatrix(size, CV_PI / 3);
cv::Mat src = randomMat(size, type); int flags = interpolation;
cv::Mat M = createTransfomMatrix(size, CV_PI / 3); if (inverse)
int flags = interpolation; flags |= cv::WARP_INVERSE_MAP;
if (inverse) cv::Scalar val = randomScalar(0.0, 255.0);
flags |= cv::WARP_INVERSE_MAP;
cv::Scalar val = randomScalar(0.0, 255.0);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::warpAffine(loadMat(src, useRoi), dst, M, size, flags, borderType, val); cv::gpu::warpAffine(loadMat(src, useRoi), dst, M, size, flags, borderType, val);
cv::Mat dst_gold; cv::Mat dst_gold;
warpAffineGold(src, M, inverse, size, dst_gold, interpolation, borderType, val); warpAffineGold(src, M, inverse, size, dst_gold, interpolation, borderType, val);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffine, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffine, testing::Combine(
@ -265,27 +249,19 @@ PARAM_TEST_CASE(WarpAffineNPP, cv::gpu::DeviceInfo, MatType, Inverse, Interpolat
TEST_P(WarpAffineNPP, Accuracy) TEST_P(WarpAffineNPP, Accuracy)
{ {
try cv::Mat src = readImageType("stereobp/aloe-L.png", type);
{ cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4);
cv::Mat src = readImageType("stereobp/aloe-L.png", type); int flags = interpolation;
cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4); if (inverse)
int flags = interpolation; flags |= cv::WARP_INVERSE_MAP;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::warpAffine(loadMat(src), dst, M, src.size(), flags); cv::gpu::warpAffine(loadMat(src), dst, M, src.size(), flags);
cv::Mat dst_gold; cv::Mat dst_gold;
warpAffineGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0)); warpAffineGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0));
EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2); EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffineNPP, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpAffineNPP, testing::Combine(

View File

@ -77,29 +77,21 @@ PARAM_TEST_CASE(BuildWarpPerspectiveMaps, cv::gpu::DeviceInfo, cv::Size, Inverse
TEST_P(BuildWarpPerspectiveMaps, Accuracy) TEST_P(BuildWarpPerspectiveMaps, Accuracy)
{ {
try cv::Mat M = createTransfomMatrix(size, CV_PI / 4);
{ cv::gpu::GpuMat xmap, ymap;
cv::Mat M = createTransfomMatrix(size, CV_PI / 4); cv::gpu::buildWarpPerspectiveMaps(M, inverse, size, xmap, ymap);
cv::gpu::GpuMat xmap, ymap;
cv::gpu::buildWarpPerspectiveMaps(M, inverse, size, xmap, ymap);
cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1); cv::Mat src = randomMat(randomSize(200, 400), CV_8UC1);
cv::Mat dst; cv::Mat dst;
cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), cv::INTER_NEAREST, cv::BORDER_CONSTANT); cv::remap(src, dst, cv::Mat(xmap), cv::Mat(ymap), cv::INTER_NEAREST, cv::BORDER_CONSTANT);
int flags = cv::INTER_NEAREST; int flags = cv::INTER_NEAREST;
if (inverse) if (inverse)
flags |= cv::WARP_INVERSE_MAP; flags |= cv::WARP_INVERSE_MAP;
cv::Mat dst_gold; cv::Mat dst_gold;
cv::warpPerspective(src, dst_gold, M, size, flags, cv::BORDER_CONSTANT); cv::warpPerspective(src, dst_gold, M, size, flags, cv::BORDER_CONSTANT);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0); EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BuildWarpPerspectiveMaps, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BuildWarpPerspectiveMaps, testing::Combine(
@ -209,28 +201,20 @@ PARAM_TEST_CASE(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse
TEST_P(WarpPerspective, Accuracy) TEST_P(WarpPerspective, Accuracy)
{ {
try cv::Mat src = randomMat(size, type);
{ cv::Mat M = createTransfomMatrix(size, CV_PI / 3);
cv::Mat src = randomMat(size, type); int flags = interpolation;
cv::Mat M = createTransfomMatrix(size, CV_PI / 3); if (inverse)
int flags = interpolation; flags |= cv::WARP_INVERSE_MAP;
if (inverse) cv::Scalar val = randomScalar(0.0, 255.0);
flags |= cv::WARP_INVERSE_MAP;
cv::Scalar val = randomScalar(0.0, 255.0);
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
cv::gpu::warpPerspective(loadMat(src, useRoi), dst, M, size, flags, borderType, val); cv::gpu::warpPerspective(loadMat(src, useRoi), dst, M, size, flags, borderType, val);
cv::Mat dst_gold; cv::Mat dst_gold;
warpPerspectiveGold(src, M, inverse, size, dst_gold, interpolation, borderType, val); warpPerspectiveGold(src, M, inverse, size, dst_gold, interpolation, borderType, val);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0); EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-1 : 1.0);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspective, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspective, testing::Combine(
@ -265,27 +249,19 @@ PARAM_TEST_CASE(WarpPerspectiveNPP, cv::gpu::DeviceInfo, MatType, Inverse, Inter
TEST_P(WarpPerspectiveNPP, Accuracy) TEST_P(WarpPerspectiveNPP, Accuracy)
{ {
try cv::Mat src = readImageType("stereobp/aloe-L.png", type);
{ cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4);
cv::Mat src = readImageType("stereobp/aloe-L.png", type); int flags = interpolation;
cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4); if (inverse)
int flags = interpolation; flags |= cv::WARP_INVERSE_MAP;
if (inverse)
flags |= cv::WARP_INVERSE_MAP;
cv::gpu::GpuMat dst; cv::gpu::GpuMat dst;
cv::gpu::warpPerspective(loadMat(src), dst, M, src.size(), flags); cv::gpu::warpPerspective(loadMat(src), dst, M, src.size(), flags);
cv::Mat dst_gold; cv::Mat dst_gold;
warpPerspectiveGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0)); warpPerspectiveGold(src, M, inverse, src.size(), dst_gold, interpolation, cv::BORDER_CONSTANT, cv::Scalar::all(0));
EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2); EXPECT_MAT_SIMILAR(dst_gold, dst, 2e-2);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspectiveNPP, testing::Combine( INSTANTIATE_TEST_CASE_P(GPU_ImgProc, WarpPerspectiveNPP, testing::Combine(