From f533f0dca95c9888462c8de8f889c0eef57347ed Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 28 Feb 2013 16:43:08 +0400 Subject: [PATCH] fixed gpu sanity tests --- modules/gpu/perf/perf_core.cpp | 46 ++++++++++++++-------------- modules/gpu/perf/perf_features2d.cpp | 2 +- modules/gpu/perf/perf_imgproc.cpp | 14 ++++----- modules/gpu/perf/perf_labeling.cpp | 4 +-- modules/gpu/perf/perf_matop.cpp | 6 ++-- modules/gpu/perf/perf_video.cpp | 14 ++++++--- modules/gpu/src/cuda/bgfg_mog.cu | 4 +-- modules/gpu/src/cuda/ccomponetns.cu | 4 +-- modules/gpu/test/test_bgfg.cpp | 31 +++++++++++++------ 9 files changed, 71 insertions(+), 54 deletions(-) diff --git a/modules/gpu/perf/perf_core.cpp b/modules/gpu/perf/perf_core.cpp index d0529e80a4..22840f9f46 100644 --- a/modules/gpu/perf/perf_core.cpp +++ b/modules/gpu/perf/perf_core.cpp @@ -35,7 +35,7 @@ PERF_TEST_P(Sz_Depth_Cn, Core_Merge, TEST_CYCLE() cv::gpu::merge(d_src, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -72,8 +72,8 @@ PERF_TEST_P(Sz_Depth_Cn, Core_Split, const cv::gpu::GpuMat& dst0 = dst[0]; const cv::gpu::GpuMat& dst1 = dst[1]; - GPU_SANITY_CHECK(dst0); - GPU_SANITY_CHECK(dst1); + GPU_SANITY_CHECK(dst0, 1e-10); + GPU_SANITY_CHECK(dst1, 1e-10); } else { @@ -113,7 +113,7 @@ PERF_TEST_P(Sz_Depth, Core_AddMat, TEST_CYCLE() cv::gpu::add(d_src1, d_src2, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -148,7 +148,7 @@ PERF_TEST_P(Sz_Depth, Core_AddScalar, TEST_CYCLE() cv::gpu::add(d_src, s, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -184,7 +184,7 @@ PERF_TEST_P(Sz_Depth, Core_SubtractMat, TEST_CYCLE() cv::gpu::subtract(d_src1, d_src2, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -219,7 +219,7 @@ PERF_TEST_P(Sz_Depth, Core_SubtractScalar, TEST_CYCLE() cv::gpu::subtract(d_src, s, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -255,7 +255,7 @@ PERF_TEST_P(Sz_Depth, Core_MultiplyMat, TEST_CYCLE() cv::gpu::multiply(d_src1, d_src2, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-6); } else { @@ -290,7 +290,7 @@ PERF_TEST_P(Sz_Depth, Core_MultiplyScalar, TEST_CYCLE() cv::gpu::multiply(d_src, s, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-6); } else { @@ -326,7 +326,7 @@ PERF_TEST_P(Sz_Depth, Core_DivideMat, TEST_CYCLE() cv::gpu::divide(d_src1, d_src2, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-6); } else { @@ -361,7 +361,7 @@ PERF_TEST_P(Sz_Depth, Core_DivideScalar, TEST_CYCLE() cv::gpu::divide(d_src, s, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-6); } else { @@ -396,7 +396,7 @@ PERF_TEST_P(Sz_Depth, Core_DivideScalarInv, TEST_CYCLE() cv::gpu::divide(s[0], d_src, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-6); } else { @@ -432,7 +432,7 @@ PERF_TEST_P(Sz_Depth, Core_AbsDiffMat, TEST_CYCLE() cv::gpu::absdiff(d_src1, d_src2, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -467,7 +467,7 @@ PERF_TEST_P(Sz_Depth, Core_AbsDiffScalar, TEST_CYCLE() cv::gpu::absdiff(d_src, s, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -1247,7 +1247,7 @@ PERF_TEST_P(Sz_3Depth, Core_AddWeighted, TEST_CYCLE() cv::gpu::addWeighted(d_src1, 0.5, d_src2, 0.5, 10.0, dst, dst_depth); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -1296,7 +1296,7 @@ PERF_TEST_P(Sz_Type_Flags, Core_GEMM, TEST_CYCLE() cv::gpu::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, dst, flags); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-6); } else { @@ -1330,7 +1330,7 @@ PERF_TEST_P(Sz_Type, Core_Transpose, TEST_CYCLE() cv::gpu::transpose(d_src, dst); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -1605,7 +1605,7 @@ PERF_TEST_P(Sz_AngleInDegrees, Core_Phase, TEST_CYCLE() cv::gpu::phase(d_src1, d_src2, dst, angleInDegrees); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); } else { @@ -1643,7 +1643,7 @@ PERF_TEST_P(Sz_AngleInDegrees, Core_CartToPolar, TEST_CYCLE() cv::gpu::cartToPolar(d_src1, d_src2, magnitude, angle, angleInDegrees); GPU_SANITY_CHECK(magnitude); - GPU_SANITY_CHECK(angle); + GPU_SANITY_CHECK(angle, 1e-6, ERROR_RELATIVE); } else { @@ -1933,8 +1933,8 @@ PERF_TEST_P(Sz_Depth, Core_MinMax, TEST_CYCLE() cv::gpu::minMax(d_src, &gpu_minVal, &gpu_maxVal, cv::gpu::GpuMat(), d_buf); - SANITY_CHECK(gpu_minVal); - SANITY_CHECK(gpu_maxVal); + SANITY_CHECK(gpu_minVal, 1e-10); + SANITY_CHECK(gpu_maxVal, 1e-10); } else { @@ -1969,8 +1969,8 @@ PERF_TEST_P(Sz_Depth, Core_MinMaxLoc, TEST_CYCLE() cv::gpu::minMaxLoc(d_src, &gpu_minVal, &gpu_maxVal, &gpu_minLoc, &gpu_maxLoc, cv::gpu::GpuMat(), d_valbuf, d_locbuf); - SANITY_CHECK(gpu_minVal); - SANITY_CHECK(gpu_maxVal); + SANITY_CHECK(gpu_minVal, 1e-10); + SANITY_CHECK(gpu_maxVal, 1e-10); } else { diff --git a/modules/gpu/perf/perf_features2d.cpp b/modules/gpu/perf/perf_features2d.cpp index 67de9a1eac..480f582383 100644 --- a/modules/gpu/perf/perf_features2d.cpp +++ b/modules/gpu/perf/perf_features2d.cpp @@ -86,7 +86,7 @@ PERF_TEST_P(Image, Features2D_SURF, sortKeyPoints(gpu_keypoints, gpu_descriptors); SANITY_CHECK_KEYPOINTS(gpu_keypoints); - SANITY_CHECK(gpu_descriptors); + SANITY_CHECK(gpu_descriptors, 1e-3); } else { diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index 62915c85ce..be6eb4877c 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -106,7 +106,7 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, ImgProc_Resize, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F), GPU_CHANNELS_1_3_4, - ALL_INTERPOLATIONS, + Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), Values(0.5, 0.3, 2.0))) { declare.time(20.0); @@ -129,7 +129,7 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, ImgProc_Resize, TEST_CYCLE() cv::gpu::resize(d_src, dst, cv::Size(), f, f, interpolation); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); } else { @@ -224,7 +224,7 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpAffine, TEST_CYCLE() cv::gpu::warpAffine(d_src, dst, M, size, interpolation, borderMode); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1); } else { @@ -272,7 +272,7 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpPerspective, TEST_CYCLE() cv::gpu::warpPerspective(d_src, dst, M, size, interpolation, borderMode); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1); } else { @@ -351,7 +351,7 @@ PERF_TEST_P(Sz_Depth_Op, ImgProc_Threshold, TEST_CYCLE() cv::gpu::threshold(d_src, dst, 100.0, 255.0, threshOp); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -1199,7 +1199,7 @@ PERF_TEST_P(Sz_Depth_Cn_Inter, ImgProc_Rotate, TEST_CYCLE() cv::gpu::rotate(d_src, dst, size, 30.0, 0, 0, interpolation); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); } else { @@ -1425,7 +1425,7 @@ PERF_TEST_P(Sz_Type_Op, ImgProc_AlphaComp, TEST_CYCLE() cv::gpu::alphaComp(d_img1, d_img2, dst, alpha_op); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); } else { diff --git a/modules/gpu/perf/perf_labeling.cpp b/modules/gpu/perf/perf_labeling.cpp index 15d286bafe..f3ad12c949 100644 --- a/modules/gpu/perf/perf_labeling.cpp +++ b/modules/gpu/perf/perf_labeling.cpp @@ -98,7 +98,7 @@ struct GreedyLabeling dot* stack; }; -PERF_TEST_P(Image, Labeling_ConnectivityMask, +PERF_TEST_P(Image, DISABLED_Labeling_ConnectivityMask, Values("gpu/labeling/aloe-disp.png")) { declare.time(1.0); @@ -121,7 +121,7 @@ PERF_TEST_P(Image, Labeling_ConnectivityMask, } } -PERF_TEST_P(Image, Labeling_ConnectedComponents, +PERF_TEST_P(Image, DISABLED_Labeling_ConnectedComponents, Values("gpu/labeling/aloe-disp.png")) { declare.time(1.0); diff --git a/modules/gpu/perf/perf_matop.cpp b/modules/gpu/perf/perf_matop.cpp index aeea1b5181..1696e3a7eb 100644 --- a/modules/gpu/perf/perf_matop.cpp +++ b/modules/gpu/perf/perf_matop.cpp @@ -64,7 +64,7 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked, TEST_CYCLE() dst.setTo(val, d_mask); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -102,7 +102,7 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked, TEST_CYCLE() d_src.copyTo(dst, d_mask); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { @@ -141,7 +141,7 @@ PERF_TEST_P(Sz_2Depth, MatOp_ConvertTo, TEST_CYCLE() d_src.convertTo(dst, depth2, a, b); - GPU_SANITY_CHECK(dst); + GPU_SANITY_CHECK(dst, 1e-10); } else { diff --git a/modules/gpu/perf/perf_video.cpp b/modules/gpu/perf/perf_video.cpp index 7d8fed6231..61c2687ca9 100644 --- a/modules/gpu/perf/perf_video.cpp +++ b/modules/gpu/perf/perf_video.cpp @@ -372,8 +372,8 @@ PERF_TEST_P(ImagePair, Video_OpticalFlowDual_TVL1, TEST_CYCLE() d_alg(d_frame0, d_frame1, u, v); - GPU_SANITY_CHECK(u); - GPU_SANITY_CHECK(v); + GPU_SANITY_CHECK(u, 1e-4); + GPU_SANITY_CHECK(v, 1e-4); } else { @@ -470,8 +470,8 @@ PERF_TEST_P(ImagePair, Video_FastOpticalFlowBM, TEST_CYCLE() fastBM(d_frame0, d_frame1, u, v, max_range.width, block_size.width); - GPU_SANITY_CHECK(u); - GPU_SANITY_CHECK(v); + GPU_SANITY_CHECK(u, 2); + GPU_SANITY_CHECK(v, 2); } else { @@ -675,8 +675,10 @@ PERF_TEST_P(Video_Cn, Video_MOG2, if (PERF_RUN_GPU()) { - cv::gpu::GpuMat d_frame(frame); cv::gpu::MOG2_GPU d_mog2; + d_mog2.bShadowDetection = false; + + cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat foreground; d_mog2(d_frame, foreground); @@ -708,6 +710,8 @@ PERF_TEST_P(Video_Cn, Video_MOG2, else { cv::BackgroundSubtractorMOG2 mog2; + mog2.set("detectShadows", false); + cv::Mat foreground; mog2(frame, foreground); diff --git a/modules/gpu/src/cuda/bgfg_mog.cu b/modules/gpu/src/cuda/bgfg_mog.cu index 4f78dbd2da..d99ffc498a 100644 --- a/modules/gpu/src/cuda/bgfg_mog.cu +++ b/modules/gpu/src/cuda/bgfg_mog.cu @@ -648,7 +648,7 @@ namespace cv { namespace gpu { namespace device tWeight += gmm_weight(mode * frame.rows + y, x); if (tWeight > c_TB) break; - }; + } } fgmask(y, x) = background ? 0 : isShadow ? c_shadowVal : 255; @@ -761,4 +761,4 @@ namespace cv { namespace gpu { namespace device }}} -#endif /* CUDA_DISABLER */ \ No newline at end of file +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/ccomponetns.cu b/modules/gpu/src/cuda/ccomponetns.cu index c094e08c0e..0533522bed 100644 --- a/modules/gpu/src/cuda/ccomponetns.cu +++ b/modules/gpu/src/cuda/ccomponetns.cu @@ -194,10 +194,10 @@ namespace cv { namespace gpu { namespace device if ( y > 0 && connected(intensity, image(y - 1, x))) c |= UP; - if ( x - 1 < image.cols && connected(intensity, image(y, x + 1))) + if ( x + 1 < image.cols && connected(intensity, image(y, x + 1))) c |= RIGHT; - if ( y - 1 < image.rows && connected(intensity, image(y + 1, x))) + if ( y + 1 < image.rows && connected(intensity, image(y + 1, x))) c |= DOWN; components(y, x) = c; diff --git a/modules/gpu/test/test_bgfg.cpp b/modules/gpu/test/test_bgfg.cpp index bac835ef1b..ebf0a88afa 100644 --- a/modules/gpu/test/test_bgfg.cpp +++ b/modules/gpu/test/test_bgfg.cpp @@ -207,11 +207,17 @@ INSTANTIATE_TEST_CASE_P(GPU_Video, MOG, testing::Combine( ////////////////////////////////////////////////////// // MOG2 -PARAM_TEST_CASE(MOG2, cv::gpu::DeviceInfo, std::string, UseGray, UseRoi) +namespace +{ + IMPLEMENT_PARAM_CLASS(DetectShadow, bool) +} + +PARAM_TEST_CASE(MOG2, cv::gpu::DeviceInfo, std::string, UseGray, DetectShadow, UseRoi) { cv::gpu::DeviceInfo devInfo; std::string inputFile; bool useGray; + bool detectShadow; bool useRoi; virtual void SetUp() @@ -220,10 +226,9 @@ PARAM_TEST_CASE(MOG2, cv::gpu::DeviceInfo, std::string, UseGray, UseRoi) cv::gpu::setDevice(devInfo.deviceID()); inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1); - useGray = GET_PARAM(2); - - useRoi = GET_PARAM(3); + detectShadow = GET_PARAM(3); + useRoi = GET_PARAM(4); } }; @@ -237,9 +242,11 @@ GPU_TEST_P(MOG2, Update) ASSERT_FALSE(frame.empty()); cv::gpu::MOG2_GPU mog2; + mog2.bShadowDetection = detectShadow; cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi); cv::BackgroundSubtractorMOG2 mog2_gold; + mog2_gold.set("detectShadows", detectShadow); cv::Mat foreground_gold; for (int i = 0; i < 10; ++i) @@ -258,11 +265,14 @@ GPU_TEST_P(MOG2, Update) mog2_gold(frame, foreground_gold); - double norm = cv::norm(foreground_gold, cv::Mat(foreground), cv::NORM_L1); - - norm /= foreground_gold.size().area(); - - ASSERT_LE(norm, 0.09); + if (detectShadow) + { + ASSERT_MAT_SIMILAR(foreground_gold, foreground, 1e-2); + } + else + { + ASSERT_MAT_NEAR(foreground_gold, foreground, 0); + } } } @@ -277,9 +287,11 @@ GPU_TEST_P(MOG2, getBackgroundImage) cv::Mat frame; cv::gpu::MOG2_GPU mog2; + mog2.bShadowDetection = detectShadow; cv::gpu::GpuMat foreground; cv::BackgroundSubtractorMOG2 mog2_gold; + mog2_gold.set("detectShadows", detectShadow); cv::Mat foreground_gold; for (int i = 0; i < 10; ++i) @@ -305,6 +317,7 @@ INSTANTIATE_TEST_CASE_P(GPU_Video, MOG2, testing::Combine( ALL_DEVICES, testing::Values(std::string("768x576.avi")), testing::Values(UseGray(true), UseGray(false)), + testing::Values(DetectShadow(true), DetectShadow(false)), WHOLE_SUBMAT)); //////////////////////////////////////////////////////