From 69d0bc8fd56d6287e7851b2b9ee16e5ec4e61e69 Mon Sep 17 00:00:00 2001 From: Julie Bareeva Date: Fri, 29 Oct 2021 19:46:11 +0300 Subject: [PATCH] Added overflow handling during conversion from float to int for LinearFilter --- modules/core/include/opencv2/core/cuda/filters.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/core/include/opencv2/core/cuda/filters.hpp b/modules/core/include/opencv2/core/cuda/filters.hpp index bb94212299..bf3147edb9 100644 --- a/modules/core/include/opencv2/core/cuda/filters.hpp +++ b/modules/core/include/opencv2/core/cuda/filters.hpp @@ -47,6 +47,7 @@ #include "vec_traits.hpp" #include "vec_math.hpp" #include "type_traits.hpp" +#include "nppdefs.h" /** @file * @deprecated Use @ref cudev instead. @@ -95,6 +96,12 @@ namespace cv { namespace cuda { namespace device const int x1 = __float2int_rd(x); const int y1 = __float2int_rd(y); + if (x1 <= NPP_MIN_32S || x1 >= NPP_MAX_32S || y1 <= NPP_MIN_32S || y1 >= NPP_MAX_32S) + { + elem_type src_reg = src(y1, x1); + out = out + src_reg * 1.0f; + return saturate_cast(out); + } const int x2 = x1 + 1; const int y2 = y1 + 1;