From 476c453ef6ed36f4549f7c7fb0b6114b18708ab5 Mon Sep 17 00:00:00 2001 From: Marina Kolpakova Date: Tue, 24 Apr 2012 10:07:14 +0000 Subject: [PATCH] fixed bug #1821 --- .../gpu/src/nvidia/NPP_staging/NPP_staging.cu | 2 +- modules/gpu/test/test_video.cpp | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/modules/gpu/src/nvidia/NPP_staging/NPP_staging.cu b/modules/gpu/src/nvidia/NPP_staging/NPP_staging.cu index a45eb5b98..1ac44c5e1 100644 --- a/modules/gpu/src/nvidia/NPP_staging/NPP_staging.cu +++ b/modules/gpu/src/nvidia/NPP_staging/NPP_staging.cu @@ -2508,7 +2508,7 @@ __global__ void resizeBicubic(NcvSize32u srcSize, wsum += wx; } } - dst[(ix + dstROI.x)+ (iy + dstROI.y) * dstStep] = sum / wsum; + dst[(ix + dstROI.x)+ (iy + dstROI.y) * dstStep] = (!wsum)? 0 : sum / wsum; } diff --git a/modules/gpu/test/test_video.cpp b/modules/gpu/test/test_video.cpp index 7fe0b271e..4418c1923 100644 --- a/modules/gpu/test/test_video.cpp +++ b/modules/gpu/test/test_video.cpp @@ -375,7 +375,7 @@ TEST_P(FarnebackOpticalFlow, Accuracy) EXPECT_MAT_SIMILAR(flowxy[0], d_flowx, 0.1); EXPECT_MAT_SIMILAR(flowxy[1], d_flowy, 0.1); -} +}; INSTANTIATE_TEST_CASE_P(GPU_Video, FarnebackOpticalFlow, testing::Combine( ALL_DEVICES, @@ -384,4 +384,33 @@ INSTANTIATE_TEST_CASE_P(GPU_Video, FarnebackOpticalFlow, testing::Combine( testing::Values(FarnebackOptFlowFlags(0), FarnebackOptFlowFlags(cv::OPTFLOW_FARNEBACK_GAUSSIAN)), testing::Values(UseInitFlow(false), UseInitFlow(true)))); +struct OpticalFlowNan : public BroxOpticalFlow {}; + +TEST_P(OpticalFlowNan, Regression) +{ + cv::Mat frame0 = readImageType("opticalflow/frame0.png", CV_32FC1); + ASSERT_FALSE(frame0.empty()); + cv::Mat r_frame0, r_frame1; + cv::resize(frame0, r_frame0, cv::Size(1380,1000)); + + cv::Mat frame1 = readImageType("opticalflow/frame1.png", CV_32FC1); + ASSERT_FALSE(frame1.empty()); + cv::resize(frame1, r_frame1, cv::Size(1380,1000)); + + cv::gpu::BroxOpticalFlow brox(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, + 5 /*inner_iterations*/, 150 /*outer_iterations*/, 10 /*solver_iterations*/); + + cv::gpu::GpuMat u; + cv::gpu::GpuMat v; + brox(loadMat(r_frame0), loadMat(r_frame1), u, v); + + cv::Mat h_u, h_v; + u.download(h_u); + v.download(h_v); + EXPECT_TRUE(cv::checkRange(h_u)); + EXPECT_TRUE(cv::checkRange(h_v)); +}; + +INSTANTIATE_TEST_CASE_P(GPU_Video, OpticalFlowNan, ALL_DEVICES); + } // namespace