Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions modules/cudaarithm/src/cuda/absdiff_mat.cu
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#else

#include "opencv2/cudev.hpp"
#include <climits>

using namespace cv::cudev;

Expand Down Expand Up @@ -77,6 +78,16 @@ namespace
}
};

template <> struct AbsDiffOp1<int> : binary_function<int, int, int>
{
__device__ __forceinline__ int operator ()(int a, int b) const
{
const long long diff = static_cast<long long>(a) - static_cast<long long>(b);
const long long absDiff = diff < 0 ? -diff : diff;
return static_cast<int>(absDiff > INT_MAX ? INT_MAX : absDiff);
}
};

template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
{
};
Expand Down
17 changes: 17 additions & 0 deletions modules/cudaarithm/test/test_element_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,23 @@ CUDA_TEST_P(AbsDiff, Array)
}
}

CUDA_TEST_P(AbsDiff, IntMin)
{
if (depth != CV_32S)
return;

cv::Mat src1 = (cv::Mat_<int>(1, 2) << std::numeric_limits<int>::min(), 0);
cv::Mat src2 = (cv::Mat_<int>(1, 2) << 0, std::numeric_limits<int>::min());

cv::Mat expected = (cv::Mat_<int>(1, 2) << std::numeric_limits<int>::max(),
std::numeric_limits<int>::max());

cv::cuda::GpuMat dst;
cv::cuda::absdiff(loadMat(src1), loadMat(src2), dst);

EXPECT_MAT_NEAR(expected, dst, 0.0);
}

CUDA_TEST_P(AbsDiff, Scalar)
{
cv::Mat src = randomMat(size, depth);
Expand Down