call resetDevice if gpu test fails

pull/258/merge
Vladislav Vinogradov 12 years ago
parent 0973e86d8a
commit ab25fe9e37
  1. 162
      modules/gpu/app/nv_perf_test/main.cpp
  2. 206
      modules/gpu/perf/perf_calib3d.cpp
  3. 963
      modules/gpu/perf/perf_core.cpp
  4. 96
      modules/gpu/perf/perf_denoising.cpp
  5. 160
      modules/gpu/perf/perf_features2d.cpp
  6. 212
      modules/gpu/perf/perf_filters.cpp
  7. 1031
      modules/gpu/perf/perf_imgproc.cpp
  8. 28
      modules/gpu/perf/perf_labeling.cpp
  9. 88
      modules/gpu/perf/perf_matop.cpp
  10. 94
      modules/gpu/perf/perf_objdetect.cpp
  11. 228
      modules/gpu/perf/perf_softcascade.cpp
  12. 700
      modules/gpu/perf/perf_video.cpp
  13. 6
      modules/gpu/test/nvidia/main_nvidia.cpp
  14. 270
      modules/gpu/test/test_calib3d.cpp
  15. 2564
      modules/gpu/test/test_color.cpp
  16. 22
      modules/gpu/test/test_copy_make_border.cpp
  17. 2638
      modules/gpu/test/test_core.cpp
  18. 111
      modules/gpu/test/test_denoising.cpp
  19. 748
      modules/gpu/test/test_features2d.cpp
  20. 218
      modules/gpu/test/test_filters.cpp
  21. 52
      modules/gpu/test/test_global_motion.cpp
  22. 322
      modules/gpu/test/test_gpumat.cpp
  23. 204
      modules/gpu/test/test_hough.cpp
  24. 730
      modules/gpu/test/test_imgproc.cpp
  25. 34
      modules/gpu/test/test_labeling.cpp
  26. 139
      modules/gpu/test/test_nvidia.cpp
  27. 345
      modules/gpu/test/test_objdetect.cpp
  28. 620
      modules/gpu/test/test_opengl.cpp
  29. 40
      modules/gpu/test/test_pyramids.cpp
  30. 22
      modules/gpu/test/test_remap.cpp
  31. 62
      modules/gpu/test/test_resize.cpp
  32. 249
      modules/gpu/test/test_softcascade.cpp
  33. 24
      modules/gpu/test/test_threshold.cpp
  34. 932
      modules/gpu/test/test_video.cpp
  35. 94
      modules/gpu/test/test_warp_affine.cpp
  36. 90
      modules/gpu/test/test_warp_perspective.cpp

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

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

File diff suppressed because it is too large Load Diff

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

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

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

File diff suppressed because it is too large Load Diff

@ -108,22 +108,30 @@ PERF_TEST_P(Image, Labeling_ConnectedComponents, Values<string>("gpu/labeling/al
if (PERF_RUN_GPU()) if (PERF_RUN_GPU())
{ {
cv::gpu::GpuMat mask; try
mask.create(image.rows, image.cols, CV_8UC1); {
cv::gpu::GpuMat mask;
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));
TEST_CYCLE() TEST_CYCLE()
{
cv::gpu::labelComponents(mask, components);
}
GPU_SANITY_CHECK(components);
}
catch (...)
{ {
cv::gpu::labelComponents(mask, components); cv::gpu::resetDevice();
throw;
} }
GPU_SANITY_CHECK(components);
} }
else else
{ {

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

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

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

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

@ -276,6 +276,8 @@ 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();
@ -292,8 +294,6 @@ 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 */

@ -62,20 +62,28 @@ struct StereoBM : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(StereoBM, Regression) TEST_P(StereoBM, Regression)
{ {
cv::Mat left_image = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); try
cv::Mat right_image = readImage("stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE); {
cv::Mat disp_gold = readImage("stereobm/aloe-disp.png", cv::IMREAD_GRAYSCALE); 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 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);
@ -97,23 +105,31 @@ struct StereoBeliefPropagation : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(StereoBeliefPropagation, Regression) TEST_P(StereoBeliefPropagation, Regression)
{ {
cv::Mat left_image = readImage("stereobp/aloe-L.png"); try
cv::Mat right_image = readImage("stereobp/aloe-R.png"); {
cv::Mat disp_gold = readImage("stereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE); cv::Mat left_image = readImage("stereobp/aloe-L.png");
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);
@ -135,29 +151,37 @@ struct StereoConstantSpaceBP : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(StereoConstantSpaceBP, Regression) TEST_P(StereoConstantSpaceBP, Regression)
{ {
cv::Mat left_image = readImage("csstereobp/aloe-L.png"); try
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);
@ -179,32 +203,40 @@ struct TransformPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(TransformPoints, Accuracy) TEST_P(TransformPoints, Accuracy)
{ {
cv::Mat src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10); try
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 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::GpuMat dst;
cv::gpu::transformPoints(loadMat(src), rvec, tvec, dst); cv::gpu::transformPoints(loadMat(src), rvec, tvec, dst);
ASSERT_EQ(src.size(), dst.size()); ASSERT_EQ(src.size(), dst.size());
ASSERT_EQ(src.type(), dst.type()); ASSERT_EQ(src.type(), dst.type());
cv::Mat h_dst(dst); cv::Mat h_dst(dst);
cv::Mat rot; cv::Mat rot;
cv::Rodrigues(rvec, rot); cv::Rodrigues(rvec, rot);
for (int i = 0; i < h_dst.cols; ++i) for (int i = 0; i < h_dst.cols; ++i)
{ {
cv::Point3f res = h_dst.at<cv::Point3f>(0, i); cv::Point3f res = h_dst.at<cv::Point3f>(0, i);
cv::Point3f p = src.at<cv::Point3f>(0, i); cv::Point3f p = src.at<cv::Point3f>(0, i);
cv::Point3f res_gold( 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>(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>(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)); 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); ASSERT_POINT3_NEAR(res_gold, res, 1e-5);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
@ -227,34 +259,42 @@ struct ProjectPoints : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(ProjectPoints, Accuracy) TEST_P(ProjectPoints, Accuracy)
{ {
cv::Mat src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10); try
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 src = randomMat(cv::Size(1000, 1), CV_32FC3, 0, 10);
cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1); cv::Mat rvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
camera_mat.at<float>(0, 1) = 0.f; cv::Mat tvec = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
camera_mat.at<float>(1, 0) = 0.f; cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1);
camera_mat.at<float>(2, 0) = 0.f; camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(2, 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::GpuMat dst;
cv::gpu::projectPoints(loadMat(src), rvec, tvec, camera_mat, cv::Mat(), dst); cv::gpu::projectPoints(loadMat(src), rvec, tvec, camera_mat, cv::Mat(), dst);
ASSERT_EQ(1, dst.rows); ASSERT_EQ(1, dst.rows);
ASSERT_EQ(MatType(CV_32FC2), MatType(dst.type())); ASSERT_EQ(MatType(CV_32FC2), MatType(dst.type()));
std::vector<cv::Point2f> dst_gold; 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); 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)); ASSERT_EQ(dst_gold.size(), static_cast<size_t>(dst.cols));
cv::Mat h_dst(dst); cv::Mat h_dst(dst);
for (size_t i = 0; i < dst_gold.size(); ++i) for (size_t i = 0; i < dst_gold.size(); ++i)
{ {
cv::Point2f res = h_dst.at<cv::Point2f>(0, (int)i); cv::Point2f res = h_dst.at<cv::Point2f>(0, (int)i);
cv::Point2f res_gold = dst_gold[i]; cv::Point2f res_gold = dst_gold[i];
ASSERT_LE(cv::norm(res_gold - res) / cv::norm(res_gold), 1e-3f); ASSERT_LE(cv::norm(res_gold - res) / cv::norm(res_gold), 1e-3f);
}
}
catch (...)
{
cv::gpu::resetDevice();
throw;
} }
} }
@ -277,28 +317,36 @@ struct SolvePnPRansac : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(SolvePnPRansac, Accuracy) TEST_P(SolvePnPRansac, Accuracy)
{ {
cv::Mat object = randomMat(cv::Size(5000, 1), CV_32FC3, 0, 100); try
cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1); {
camera_mat.at<float>(0, 1) = 0.f; cv::Mat object = randomMat(cv::Size(5000, 1), CV_32FC3, 0, 100);
camera_mat.at<float>(1, 0) = 0.f; cv::Mat camera_mat = randomMat(cv::Size(3, 3), CV_32F, 0.5, 1);
camera_mat.at<float>(2, 0) = 0.f; camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(2, 1) = 0.f; camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f;
std::vector<cv::Point2f> image_vec; camera_mat.at<float>(2, 1) = 0.f;
cv::Mat rvec_gold;
cv::Mat tvec_gold; std::vector<cv::Point2f> image_vec;
rvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1); cv::Mat rvec_gold;
tvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1); cv::Mat tvec_gold;
cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), image_vec); rvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
tvec_gold = randomMat(cv::Size(3, 1), CV_32F, 0, 1);
cv::Mat rvec, tvec; cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), image_vec);
std::vector<int> inliers;
cv::gpu::solvePnPRansac(object, cv::Mat(1, (int)image_vec.size(), CV_32FC2, &image_vec[0]), cv::Mat rvec, tvec;
camera_mat, cv::Mat(1, 8, CV_32F, cv::Scalar::all(0)), std::vector<int> inliers;
rvec, tvec, false, 200, 2.f, 100, &inliers); 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)),
ASSERT_LE(cv::norm(rvec - rvec_gold), 1e-3); rvec, tvec, false, 200, 2.f, 100, &inliers);
ASSERT_LE(cv::norm(tvec - tvec_gold), 1e-3);
ASSERT_LE(cv::norm(rvec - rvec_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);
@ -326,16 +374,24 @@ PARAM_TEST_CASE(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth, Use
TEST_P(ReprojectImageTo3D, Accuracy) TEST_P(ReprojectImageTo3D, Accuracy)
{ {
cv::Mat disp = randomMat(size, depth, 5.0, 30.0); try
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

@ -71,16 +71,24 @@ PARAM_TEST_CASE(CopyMakeBorder, cv::gpu::DeviceInfo, cv::Size, MatType, Border,
TEST_P(CopyMakeBorder, Accuracy) TEST_P(CopyMakeBorder, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
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

@ -71,17 +71,25 @@ PARAM_TEST_CASE(BilateralFilter, cv::gpu::DeviceInfo, cv::Size, MatType)
TEST_P(BilateralFilter, Accuracy) TEST_P(BilateralFilter, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
{
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(
@ -107,35 +115,41 @@ struct BruteForceNonLocalMeans: testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(BruteForceNonLocalMeans, Regression) TEST_P(BruteForceNonLocalMeans, Regression)
{ {
using cv::gpu::GpuMat; try
{
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
@ -152,34 +166,41 @@ struct FastNonLocalMeans: testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(FastNonLocalMeans, Regression) TEST_P(FastNonLocalMeans, Regression)
{ {
using cv::gpu::GpuMat; try
{
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

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

@ -88,15 +88,23 @@ PARAM_TEST_CASE(Blur, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Anchor, Use
TEST_P(Blur, Accuracy) TEST_P(Blur, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
{
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(
@ -150,15 +158,23 @@ TEST_P(Sobel, Accuracy)
if (dx == 0 && dy == 0) if (dx == 0 && dy == 0)
return; return;
cv::Mat src = randomMat(size, type); try
{
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(
@ -213,15 +229,23 @@ TEST_P(Scharr, Accuracy)
if (dx + dy != 1) if (dx + dy != 1)
return; return;
cv::Mat src = randomMat(size, type); try
{
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(
@ -270,31 +294,39 @@ PARAM_TEST_CASE(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels,
TEST_P(GaussianBlur, Accuracy) TEST_P(GaussianBlur, Accuracy)
{ {
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::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::gpu::GpuMat dst; try
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);
}
} }
catch (const cv::Exception& e) else
{ {
ASSERT_EQ(CV_StsNotImplemented, e.code); cv::gpu::GpuMat dst = createMat(size, type, useRoi);
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);
} }
} }
else catch (...)
{ {
cv::gpu::GpuMat dst = createMat(size, type, useRoi); cv::gpu::resetDevice();
cv::gpu::GaussianBlur(loadMat(src, useRoi), dst, ksize, sigma1, sigma2, borderType); throw;
cv::Mat dst_gold;
cv::GaussianBlur(src, dst_gold, ksize, sigma1, sigma2, borderType);
EXPECT_MAT_NEAR(dst_gold, dst, 4.0);
} }
} }
@ -349,15 +381,23 @@ PARAM_TEST_CASE(Laplacian, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, UseRoi
TEST_P(Laplacian, Accuracy) TEST_P(Laplacian, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
{
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(
@ -396,18 +436,26 @@ PARAM_TEST_CASE(Erode, cv::gpu::DeviceInfo, cv::Size, MatType, Anchor, Iteration
TEST_P(Erode, Accuracy) TEST_P(Erode, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
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(
@ -445,18 +493,26 @@ PARAM_TEST_CASE(Dilate, cv::gpu::DeviceInfo, cv::Size, MatType, Anchor, Iteratio
TEST_P(Dilate, Accuracy) TEST_P(Dilate, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
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(
@ -499,18 +555,26 @@ PARAM_TEST_CASE(MorphEx, cv::gpu::DeviceInfo, cv::Size, MatType, MorphOp, Anchor
TEST_P(MorphEx, Accuracy) TEST_P(MorphEx, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
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(
@ -553,16 +617,24 @@ PARAM_TEST_CASE(Filter2D, cv::gpu::DeviceInfo, cv::Size, MatType, KSize, Anchor,
TEST_P(Filter2D, Accuracy) TEST_P(Filter2D, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
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(

@ -53,35 +53,43 @@ struct CompactPoints : testing::TestWithParam<gpu::DeviceInfo>
TEST_P(CompactPoints, CanCompactizeSmallInput) TEST_P(CompactPoints, CanCompactizeSmallInput)
{ {
Mat src0(1, 3, CV_32FC2); try
src0.at<Point2f>(0,0) = Point2f(0,0); {
src0.at<Point2f>(0,1) = Point2f(0,1); Mat src0(1, 3, CV_32FC2);
src0.at<Point2f>(0,2) = Point2f(0,2); src0.at<Point2f>(0,0) = Point2f(0,0);
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);

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

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

@ -66,15 +66,23 @@ PARAM_TEST_CASE(Integral, cv::gpu::DeviceInfo, cv::Size, UseRoi)
TEST_P(Integral, Accuracy) TEST_P(Integral, Accuracy)
{ {
cv::Mat src = randomMat(size, CV_8UC1); try
{
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(
@ -99,32 +107,40 @@ struct HistEven : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(HistEven, Accuracy) TEST_P(HistEven, Accuracy)
{ {
cv::Mat img = readImage("stereobm/aloe-L.png"); try
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);
@ -164,15 +180,23 @@ PARAM_TEST_CASE(CalcHist, cv::gpu::DeviceInfo, cv::Size)
TEST_P(CalcHist, Accuracy) TEST_P(CalcHist, Accuracy)
{ {
cv::Mat src = randomMat(size, CV_8UC1); try
{
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(
@ -198,15 +222,23 @@ PARAM_TEST_CASE(EqualizeHist, cv::gpu::DeviceInfo, cv::Size)
TEST_P(EqualizeHist, Accuracy) TEST_P(EqualizeHist, Accuracy)
{ {
cv::Mat src = randomMat(size, CV_8UC1); try
{
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(
@ -232,28 +264,36 @@ PARAM_TEST_CASE(ColumnSum, cv::gpu::DeviceInfo, cv::Size)
TEST_P(ColumnSum, Accuracy) TEST_P(ColumnSum, Accuracy)
{ {
cv::Mat src = randomMat(size, CV_32FC1); try
{
cv::gpu::GpuMat d_dst; cv::Mat src = randomMat(size, CV_32FC1);
cv::gpu::columnSum(loadMat(src), d_dst);
cv::Mat dst(d_dst); cv::gpu::GpuMat d_dst;
cv::gpu::columnSum(loadMat(src), d_dst);
for (int j = 0; j < src.cols; ++j) cv::Mat dst(d_dst);
{
float gold = src.at<float>(0, j);
float res = dst.at<float>(0, j);
ASSERT_NEAR(res, gold, 1e-5);
}
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>(i, j) += src.at<float>(i - 1, j); float gold = src.at<float>(0, j);
float res = dst.at<float>(i, j); float res = dst.at<float>(0, 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;
} }
} }
@ -287,33 +327,41 @@ PARAM_TEST_CASE(Canny, cv::gpu::DeviceInfo, AppertureSize, L2gradient, UseRoi)
TEST_P(Canny, Accuracy) TEST_P(Canny, Accuracy)
{ {
cv::Mat img = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); try
ASSERT_FALSE(img.empty()); {
cv::Mat img = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
double low_thresh = 50.0; double low_thresh = 50.0;
double high_thresh = 100.0; double high_thresh = 100.0;
if (!supportFeature(devInfo, cv::gpu::SHARED_ATOMICS)) if (!supportFeature(devInfo, cv::gpu::SHARED_ATOMICS))
{
try
{ {
cv::gpu::GpuMat edges; try
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);
}
} }
catch (const cv::Exception& e) else
{ {
ASSERT_EQ(CV_StsNotImplemented, e.code); cv::gpu::GpuMat edges;
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);
} }
} }
else catch (...)
{ {
cv::gpu::GpuMat edges; cv::gpu::resetDevice();
cv::gpu::Canny(loadMat(img, useRoi), edges, low_thresh, high_thresh, apperture_size, useL2gradient); throw;
cv::Mat edges_gold;
cv::Canny(img, edges_gold, low_thresh, high_thresh, apperture_size, useL2gradient);
EXPECT_MAT_SIMILAR(edges_gold, edges, 2e-2);
} }
} }
@ -351,50 +399,66 @@ struct MeanShift : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(MeanShift, Filtering) TEST_P(MeanShift, Filtering)
{ {
cv::Mat img_template; try
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20)) {
img_template = readImage("meanshift/con_result.png"); cv::Mat img_template;
else if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
img_template = readImage("meanshift/con_result_CC1X.png"); img_template = readImage("meanshift/con_result.png");
ASSERT_FALSE(img_template.empty()); else
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)
{ {
cv::FileStorage fs; try
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20)) {
fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap.yaml", cv::FileStorage::READ); cv::FileStorage fs;
else if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap_CC1X.yaml", cv::FileStorage::READ); fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap.yaml", cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened()); else
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);
@ -420,25 +484,33 @@ PARAM_TEST_CASE(MeanShiftSegmentation, cv::gpu::DeviceInfo, MinSize)
TEST_P(MeanShiftSegmentation, Regression) TEST_P(MeanShiftSegmentation, Regression)
{ {
cv::Mat img = readImageType("meanshift/cones.png", CV_8UC4); try
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(
@ -492,23 +564,31 @@ PARAM_TEST_CASE(Blend, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
TEST_P(Blend, Accuracy) TEST_P(Blend, Accuracy)
{ {
int depth = CV_MAT_DEPTH(type); try
{
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(
@ -582,16 +662,24 @@ PARAM_TEST_CASE(Convolve, cv::gpu::DeviceInfo, cv::Size, KSize, Ccorr)
TEST_P(Convolve, Accuracy) TEST_P(Convolve, Accuracy)
{ {
cv::Mat src = randomMat(size, CV_32FC1, 0.0, 100.0); try
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(
@ -630,16 +718,24 @@ PARAM_TEST_CASE(MatchTemplate8U, cv::gpu::DeviceInfo, cv::Size, TemplateSize, Ch
TEST_P(MatchTemplate8U, Accuracy) TEST_P(MatchTemplate8U, Accuracy)
{ {
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn)); try
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(
@ -676,16 +772,24 @@ PARAM_TEST_CASE(MatchTemplate32F, cv::gpu::DeviceInfo, cv::Size, TemplateSize, C
TEST_P(MatchTemplate32F, Regression) TEST_P(MatchTemplate32F, Regression)
{ {
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn)); try
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(
@ -714,24 +818,32 @@ PARAM_TEST_CASE(MatchTemplateBlackSource, cv::gpu::DeviceInfo, TemplateMethod)
TEST_P(MatchTemplateBlackSource, Accuracy) TEST_P(MatchTemplateBlackSource, Accuracy)
{ {
cv::Mat image = readImage("matchtemplate/black.png"); try
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(
@ -759,32 +871,40 @@ PARAM_TEST_CASE(MatchTemplate_CCOEF_NORMED, cv::gpu::DeviceInfo, std::pair<std::
TEST_P(MatchTemplate_CCOEF_NORMED, Accuracy) TEST_P(MatchTemplate_CCOEF_NORMED, Accuracy)
{ {
cv::Mat image = readImage(imageName); try
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(
@ -808,47 +928,63 @@ struct MatchTemplate_CanFindBigTemplate : testing::TestWithParam<cv::gpu::Device
TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF_NORMED) TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF_NORMED)
{ {
cv::Mat scene = readImage("matchtemplate/scene.png"); try
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)
{ {
cv::Mat scene = readImage("matchtemplate/scene.png"); try
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);
@ -881,27 +1017,43 @@ PARAM_TEST_CASE(MulSpectrums, cv::gpu::DeviceInfo, cv::Size, DftFlags)
TEST_P(MulSpectrums, Simple) TEST_P(MulSpectrums, Simple)
{ {
cv::gpu::GpuMat c; try
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)
{ {
float scale = 1.f / size.area(); try
{
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(
@ -950,26 +1102,34 @@ void testC2C(const std::string& hint, int cols, int rows, int flags, bool inplac
TEST_P(Dft, C2C) TEST_P(Dft, C2C)
{ {
int cols = randomInt(2, 100); try
int rows = randomInt(2, 100); {
int cols = randomInt(2, 100);
for (int i = 0; i < 2; ++i) int rows = randomInt(2, 100);
{
bool inplace = i != 0; for (int i = 0; i < 2; ++i)
{
testC2C("no flags", cols, rows, 0, inplace); bool inplace = i != 0;
testC2C("no flags 0 1", cols, rows + 1, 0, inplace);
testC2C("no flags 1 0", cols, rows + 1, 0, inplace); testC2C("no flags", cols, rows, 0, inplace);
testC2C("no flags 1 1", cols + 1, rows, 0, inplace); testC2C("no flags 0 1", cols, rows + 1, 0, inplace);
testC2C("DFT_INVERSE", cols, rows, cv::DFT_INVERSE, inplace); testC2C("no flags 1 0", cols, rows + 1, 0, inplace);
testC2C("DFT_ROWS", cols, rows, cv::DFT_ROWS, inplace); testC2C("no flags 1 1", cols + 1, rows, 0, inplace);
testC2C("single col", 1, rows, 0, inplace); testC2C("DFT_INVERSE", cols, rows, cv::DFT_INVERSE, inplace);
testC2C("single row", cols, 1, 0, inplace); testC2C("DFT_ROWS", cols, rows, cv::DFT_ROWS, inplace);
testC2C("single col inversed", 1, rows, cv::DFT_INVERSE, inplace); testC2C("single col", 1, rows, 0, inplace);
testC2C("single row inversed", cols, 1, cv::DFT_INVERSE, inplace); testC2C("single row", cols, 1, 0, inplace);
testC2C("single row DFT_ROWS", cols, 1, cv::DFT_ROWS, inplace); testC2C("single col inversed", 1, rows, cv::DFT_INVERSE, inplace);
testC2C("size 1 2", 1, 2, 0, inplace); testC2C("single row inversed", cols, 1, cv::DFT_INVERSE, inplace);
testC2C("size 2 1", 2, 1, 0, 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();
throw;
} }
} }
@ -1011,24 +1171,32 @@ void testR2CThenC2R(const std::string& hint, int cols, int rows, bool inplace)
TEST_P(Dft, R2CThenC2R) TEST_P(Dft, R2CThenC2R)
{ {
int cols = randomInt(2, 100); try
int rows = randomInt(2, 100); {
int cols = randomInt(2, 100);
testR2CThenC2R("sanity", cols, rows, false); int rows = randomInt(2, 100);
testR2CThenC2R("sanity 0 1", cols, rows + 1, false);
testR2CThenC2R("sanity 1 0", cols + 1, rows, false); testR2CThenC2R("sanity", cols, rows, false);
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, false); testR2CThenC2R("sanity 0 1", cols, rows + 1, false);
testR2CThenC2R("single col", 1, rows, false); testR2CThenC2R("sanity 1 0", cols + 1, rows, false);
testR2CThenC2R("single col 1", 1, rows + 1, false); testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, false);
testR2CThenC2R("single row", cols, 1, false); testR2CThenC2R("single col", 1, rows, false);
testR2CThenC2R("single row 1", cols + 1, 1, false); testR2CThenC2R("single col 1", 1, rows + 1, false);
testR2CThenC2R("single row", cols, 1, false);
testR2CThenC2R("sanity", cols, rows, true); testR2CThenC2R("single row 1", cols + 1, 1, false);
testR2CThenC2R("sanity 0 1", cols, rows + 1, true);
testR2CThenC2R("sanity 1 0", cols + 1, rows, true); testR2CThenC2R("sanity", cols, rows, true);
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, true); testR2CThenC2R("sanity 0 1", cols, rows + 1, true);
testR2CThenC2R("single row", cols, 1, true); testR2CThenC2R("sanity 1 0", cols + 1, rows, true);
testR2CThenC2R("single row 1", cols + 1, 1, true); testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, true);
testR2CThenC2R("single row", cols, 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);
@ -1061,18 +1229,26 @@ PARAM_TEST_CASE(CornerHarris, cv::gpu::DeviceInfo, MatType, BorderType, BlockSiz
TEST_P(CornerHarris, Accuracy) TEST_P(CornerHarris, Accuracy)
{ {
cv::Mat src = readImageType("stereobm/aloe-L.png", type); try
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(
@ -1107,16 +1283,24 @@ PARAM_TEST_CASE(CornerMinEigen, cv::gpu::DeviceInfo, MatType, BorderType, BlockS
TEST_P(CornerMinEigen, Accuracy) TEST_P(CornerMinEigen, Accuracy)
{ {
cv::Mat src = readImageType("stereobm/aloe-L.png", type); try
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(

@ -168,27 +168,35 @@ struct Labeling : testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(Labeling, ConnectedComponents) TEST_P(Labeling, ConnectedComponents)
{ {
cv::Mat image; try
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);

@ -69,82 +69,169 @@ 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)
//{ {
// bool res = nvidia_NPPST_Integral_Image(path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NPPST_Squared_Integral_Image(_path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NPPST_RectStdDev(_path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NPPST_Resize(_path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NPPST_Vector_Operations(_path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NPPST_Transpose(_path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NCV_Vector_Operations(_path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NCV_Haar_Cascade_Loader(_path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NCV_Haar_Cascade_Application(_path, nvidiaTestOutputLevel); try
{
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)
{ {
bool res = nvidia_NCV_Hypotheses_Filtration(_path, nvidiaTestOutputLevel); try
{
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)
{ {
// this functionality doesn't used in gpu module try
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);

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

@ -70,258 +70,402 @@ PARAM_TEST_CASE(GlBuffer, cv::Size, MatType)
TEST_P(GlBuffer, Constructor1) TEST_P(GlBuffer, Constructor1)
{ {
cv::GlBuffer buf(size.height, size.width, type, cv::GlBuffer::ARRAY_BUFFER, true); try
{
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)
{ {
cv::GlBuffer buf(size, type, cv::GlBuffer::ARRAY_BUFFER, true); try
{
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)
{ {
cv::Mat gold = randomMat(size, type); try
{
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)
{ {
cv::Mat gold = randomMat(size, type); try
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)
{ {
cv::GlBuffer buf_gold(size, type, cv::GlBuffer::ARRAY_BUFFER, true); try
{
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)
{ {
const int depth = CV_MAT_DEPTH(type); try
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)
{ {
cv::GlBuffer buf; try
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)
{ {
cv::Mat gold = randomMat(size, type); try
{
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)
{ {
cv::Mat gold = randomMat(size, type); try
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)
{ {
cv::Mat gold = randomMat(size, type); try
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)
{ {
const int depth = CV_MAT_DEPTH(type); try
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)
{ {
cv::Mat gold = randomMat(size, type); try
{
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)
{ {
cv::Mat gold = randomMat(size, type); try
{
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)
{ {
const int depth = CV_MAT_DEPTH(type); try
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)
{ {
cv::Mat gold = randomMat(size, type); try
{
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)
{ {
cv::Mat gold = randomMat(size, type); try
{
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)
{ {
cv::Mat gold = randomMat(size, type); try
{
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)
{ {
cv::Mat gold = randomMat(size, type); try
{
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));
@ -360,147 +504,243 @@ PARAM_TEST_CASE(GlTexture2D, cv::Size, MatType)
TEST_P(GlTexture2D, Constructor1) TEST_P(GlTexture2D, Constructor1)
{ {
cv::GlTexture2D tex(size.height, size.width, format, true); try
{
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)
{ {
cv::GlTexture2D tex(size, format, true); try
{
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)
{ {
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); try
{
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)
{ {
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); try
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)
{ {
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); try
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)
{ {
cv::GlTexture2D tex_gold(size, format, true); try
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)
{ {
cv::GlTexture2D tex; try
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)
{ {
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); try
{
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)
{ {
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); try
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)
{ {
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); try
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)
{ {
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); try
{
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)
{ {
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1); try
{
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)));

@ -66,15 +66,23 @@ PARAM_TEST_CASE(PyrDown, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
TEST_P(PyrDown, Accuracy) TEST_P(PyrDown, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
{
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(
@ -106,15 +114,23 @@ PARAM_TEST_CASE(PyrUp, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
TEST_P(PyrUp, Accuracy) TEST_P(PyrUp, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
{
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(

@ -154,16 +154,24 @@ PARAM_TEST_CASE(Remap, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, Bo
TEST_P(Remap, Accuracy) TEST_P(Remap, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
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(

@ -138,15 +138,23 @@ PARAM_TEST_CASE(Resize, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpol
TEST_P(Resize, Accuracy) TEST_P(Resize, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
{
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(
@ -184,15 +192,23 @@ 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)
{ {
cv::Mat src = randomMat(size, type); try
{
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(
@ -226,16 +242,24 @@ PARAM_TEST_CASE(ResizeNPP, cv::gpu::DeviceInfo, MatType, double, Interpolation)
TEST_P(ResizeNPP, Accuracy) TEST_P(ResizeNPP, Accuracy)
{ {
cv::Mat src = readImageType("stereobp/aloe-L.png", type); try
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(

@ -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,62 +158,77 @@ 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)))
{ {
cv::gpu::setDevice(GET_PARAM(0).deviceID()); try
cv::Mat coloredCpu = cv::imread(cvtest::TS::ptr()->get_data_path() + GET_PARAM(2)); {
ASSERT_FALSE(coloredCpu.empty()); 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::gpu::SCascade cascade;
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(1)), cv::FileStorage::READ); cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(1)), cv::FileStorage::READ);
ASSERT_TRUE(fs.isOpened()); ASSERT_TRUE(fs.isOpened());
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
GpuMat colored(coloredCpu), objectBoxes(1, 16384, CV_8UC1), rois(colored.size(), CV_8UC1); GpuMat colored(coloredCpu), objectBoxes(1, 16384, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0); rois.setTo(0);
int nroi = GET_PARAM(3); int nroi = GET_PARAM(3);
cv::Mat result(coloredCpu); cv::Mat result(coloredCpu);
cv::RNG rng; cv::RNG rng;
for (int i = 0; i < nroi; ++i) for (int i = 0; i < nroi; ++i)
{ {
cv::Rect r = getFromTable(rng(10)); cv::Rect r = getFromTable(rng(10));
GpuMat sub(rois, r); GpuMat sub(rois, r);
sub.setTo(1); sub.setTo(1);
cv::rectangle(result, r, cv::Scalar(0, 0, 255, 255), 1); cv::rectangle(result, r, cv::Scalar(0, 0, 255, 255), 1);
} }
objectBoxes.setTo(0); objectBoxes.setTo(0);
cascade.detect(colored, rois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
cv::Mat dt(objectBoxes); cv::Mat dt(objectBoxes);
typedef cv::gpu::SCascade::Detection Detection; typedef cv::gpu::SCascade::Detection Detection;
Detection* dts = ((Detection*)dt.data) + 1; Detection* dts = ((Detection*)dt.data) + 1;
int* count = dt.ptr<int>(0); int* count = dt.ptr<int>(0);
printTotal(std::cout, *count); printTotal(std::cout, *count);
for (int i = 0; i < *count; ++i) 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 (...)
{ {
Detection d = dts[i]; cv::gpu::resetDevice();
print(std::cout, d); throw;
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)
{ {
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/icf-template.xml"; try
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;
@ -221,105 +236,129 @@ GPU_TEST_P(SCascadeTestAll, detect,
ALL_DEVICES ALL_DEVICES
) )
{ {
cv::gpu::setDevice(GetParam().deviceID()); try
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml"; {
cv::gpu::SCascade cascade; 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); 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
) )
{ {
cv::gpu::setDevice(GetParam().deviceID()); try
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml"; {
cv::gpu::SCascade cascade; 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); 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()));
std::string intPath = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/integrals.xml"; std::string intPath = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/integrals.xml";
cv::FileStorage fsi(intPath, cv::FileStorage::READ); cv::FileStorage fsi(intPath, cv::FileStorage::READ);
ASSERT_TRUE(fsi.isOpened()); ASSERT_TRUE(fsi.isOpened());
GpuMat hogluv(121 * 10, 161, CV_32SC1); GpuMat hogluv(121 * 10, 161, CV_32SC1);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
cv::Mat channel; cv::Mat channel;
fsi[std::string("channel") + itoa(i)] >> channel; fsi[std::string("channel") + itoa(i)] >> channel;
GpuMat gchannel(hogluv, cv::Rect(0, 121 * i, 161, 121)); GpuMat gchannel(hogluv, cv::Rect(0, 121 * i, 161, 121));
gchannel.upload(channel); gchannel.upload(channel);
} }
GpuMat objectBoxes(1, 100000, CV_8UC1), rois(cv::Size(640, 480), CV_8UC1); GpuMat objectBoxes(1, 100000, CV_8UC1), rois(cv::Size(640, 480), CV_8UC1);
rois.setTo(1); rois.setTo(1);
objectBoxes.setTo(0); objectBoxes.setTo(0);
cascade.detect(hogluv, rois, objectBoxes); cascade.detect(hogluv, 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 ,1024); ASSERT_EQ(a, 1024);
}
catch (...)
{
cv::gpu::resetDevice();
throw;
}
} }
GPU_TEST_P(SCascadeTestAll, detectStream, GPU_TEST_P(SCascadeTestAll, detectStream,
ALL_DEVICES ALL_DEVICES
) )
{ {
cv::gpu::setDevice(GetParam().deviceID()); try
std::string xml = cvtest::TS::ptr()->get_data_path() + "../cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml"; {
cv::gpu::SCascade cascade; 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); 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

@ -68,17 +68,25 @@ PARAM_TEST_CASE(Threshold, cv::gpu::DeviceInfo, cv::Size, MatType, ThreshOp, Use
TEST_P(Threshold, Accuracy) TEST_P(Threshold, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
double maxVal = randomDouble(20.0, 127.0); {
double thresh = randomDouble(0.0, maxVal); cv::Mat src = randomMat(size, type);
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

@ -76,24 +76,32 @@ PARAM_TEST_CASE(BuildWarpAffineMaps, cv::gpu::DeviceInfo, cv::Size, Inverse)
TEST_P(BuildWarpAffineMaps, Accuracy) TEST_P(BuildWarpAffineMaps, Accuracy)
{ {
cv::Mat M = createTransfomMatrix(size, CV_PI / 4); try
cv::gpu::GpuMat xmap, ymap; {
cv::gpu::buildWarpAffineMaps(M, inverse, size, xmap, ymap); cv::Mat M = createTransfomMatrix(size, CV_PI / 4);
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(
@ -201,20 +209,28 @@ PARAM_TEST_CASE(WarpAffine, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse, Int
TEST_P(WarpAffine, Accuracy) TEST_P(WarpAffine, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
cv::Mat M = createTransfomMatrix(size, CV_PI / 3); {
int flags = interpolation; cv::Mat src = randomMat(size, type);
if (inverse) cv::Mat M = createTransfomMatrix(size, CV_PI / 3);
flags |= cv::WARP_INVERSE_MAP; int flags = interpolation;
cv::Scalar val = randomScalar(0.0, 255.0); if (inverse)
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(
@ -249,19 +265,27 @@ PARAM_TEST_CASE(WarpAffineNPP, cv::gpu::DeviceInfo, MatType, Inverse, Interpolat
TEST_P(WarpAffineNPP, Accuracy) TEST_P(WarpAffineNPP, Accuracy)
{ {
cv::Mat src = readImageType("stereobp/aloe-L.png", type); try
cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4); {
int flags = interpolation; cv::Mat src = readImageType("stereobp/aloe-L.png", type);
if (inverse) cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4);
flags |= cv::WARP_INVERSE_MAP; int flags = interpolation;
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(

@ -77,21 +77,29 @@ PARAM_TEST_CASE(BuildWarpPerspectiveMaps, cv::gpu::DeviceInfo, cv::Size, Inverse
TEST_P(BuildWarpPerspectiveMaps, Accuracy) TEST_P(BuildWarpPerspectiveMaps, Accuracy)
{ {
cv::Mat M = createTransfomMatrix(size, CV_PI / 4); try
cv::gpu::GpuMat xmap, ymap; {
cv::gpu::buildWarpPerspectiveMaps(M, inverse, size, xmap, ymap); cv::Mat M = createTransfomMatrix(size, CV_PI / 4);
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(
@ -201,20 +209,28 @@ PARAM_TEST_CASE(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Inverse
TEST_P(WarpPerspective, Accuracy) TEST_P(WarpPerspective, Accuracy)
{ {
cv::Mat src = randomMat(size, type); try
cv::Mat M = createTransfomMatrix(size, CV_PI / 3); {
int flags = interpolation; cv::Mat src = randomMat(size, type);
if (inverse) cv::Mat M = createTransfomMatrix(size, CV_PI / 3);
flags |= cv::WARP_INVERSE_MAP; int flags = interpolation;
cv::Scalar val = randomScalar(0.0, 255.0); if (inverse)
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(
@ -249,19 +265,27 @@ PARAM_TEST_CASE(WarpPerspectiveNPP, cv::gpu::DeviceInfo, MatType, Inverse, Inter
TEST_P(WarpPerspectiveNPP, Accuracy) TEST_P(WarpPerspectiveNPP, Accuracy)
{ {
cv::Mat src = readImageType("stereobp/aloe-L.png", type); try
cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4); {
int flags = interpolation; cv::Mat src = readImageType("stereobp/aloe-L.png", type);
if (inverse) cv::Mat M = createTransfomMatrix(src.size(), CV_PI / 4);
flags |= cv::WARP_INVERSE_MAP; int flags = interpolation;
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(

Loading…
Cancel
Save