vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
|
||||
ocv_module_disable(cudaarithm)
|
||||
endif()
|
||||
|
||||
set(the_description "CUDA-accelerated Operations on Matrices")
|
||||
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow)
|
||||
|
||||
set(extra_dependencies "")
|
||||
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
|
||||
if(UNIX AND NOT BUILD_SHARED_LIBS AND CUDA_VERSION_STRING VERSION_GREATER_EQUAL 9.2 AND CUDA_VERSION_STRING VERSION_LESS 13.0 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.23)
|
||||
set(CUDA_FFT_LIB_EXT "_static_nocallback")
|
||||
endif()
|
||||
list(APPEND extra_dependencies CUDA::cudart${CUDA_LIB_EXT} CUDA::nppial${CUDA_LIB_EXT} CUDA::nppc${CUDA_LIB_EXT} CUDA::nppitc${CUDA_LIB_EXT} CUDA::nppig${CUDA_LIB_EXT} CUDA::nppist${CUDA_LIB_EXT} CUDA::nppidei${CUDA_LIB_EXT})
|
||||
if(HAVE_CUBLAS)
|
||||
list(APPEND extra_dependencies CUDA::cublas${CUDA_LIB_EXT})
|
||||
if(NOT CUDA_VERSION VERSION_LESS 10.1)
|
||||
list(APPEND extra_dependencies CUDA::cublasLt${CUDA_LIB_EXT})
|
||||
endif()
|
||||
endif()
|
||||
if(HAVE_CUFFT)
|
||||
# static version requires seperable compilation which is incompatible with opencv's current library structure
|
||||
# the cufft_static_nocallback variant does not requires seperable compilation. callbacks are currently not used.
|
||||
list(APPEND extra_dependencies CUDA::cufft${CUDA_FFT_LIB_EXT})
|
||||
endif()
|
||||
else()
|
||||
if(HAVE_CUBLAS)
|
||||
list(APPEND extra_dependencies ${CUDA_cublas_LIBRARY})
|
||||
endif()
|
||||
if(HAVE_CUFFT)
|
||||
list(APPEND extra_dependencies ${CUDA_cufft_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
ocv_add_module(cudaarithm opencv_core OPTIONAL opencv_cudev WRAP python)
|
||||
|
||||
ocv_module_include_directories()
|
||||
ocv_glob_module_sources()
|
||||
|
||||
ocv_create_module(${extra_dependencies})
|
||||
|
||||
set(test_libs "")
|
||||
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
|
||||
list(APPEND test_libs CUDA::cudart${CUDA_LIB_EXT})
|
||||
endif()
|
||||
ocv_add_accuracy_tests(${test_libs} DEPENDS_ON opencv_imgproc)
|
||||
ocv_add_perf_tests(DEPENDS_ON opencv_imgproc)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,235 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
|
||||
from tests_common import NewOpenCVTests, unittest
|
||||
|
||||
class cudaarithm_test(NewOpenCVTests):
|
||||
def setUp(self):
|
||||
super(cudaarithm_test, self).setUp()
|
||||
if not cv.cuda.getCudaEnabledDeviceCount():
|
||||
self.skipTest("No CUDA-capable device is detected")
|
||||
|
||||
def test_cudaarithm(self):
|
||||
npMat = (np.random.random((128, 128, 3)) * 255).astype(np.uint8)
|
||||
|
||||
cuMat = cv.cuda_GpuMat(npMat)
|
||||
cuMatDst = cv.cuda_GpuMat(cuMat.size(),cuMat.type())
|
||||
cuMatB = cv.cuda_GpuMat(cuMat.size(),cv.CV_8UC1)
|
||||
cuMatG = cv.cuda_GpuMat(cuMat.size(),cv.CV_8UC1)
|
||||
cuMatR = cv.cuda_GpuMat(cuMat.size(),cv.CV_8UC1)
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.merge(cv.cuda.split(cuMat)),npMat))
|
||||
|
||||
cv.cuda.split(cuMat,[cuMatB,cuMatG,cuMatR])
|
||||
cv.cuda.merge([cuMatB,cuMatG,cuMatR],cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),npMat))
|
||||
|
||||
shift = (np.random.random((cuMat.channels(),)) * 8).astype(np.uint8).tolist()
|
||||
self.assertTrue(np.allclose(cv.cuda.rshift(cuMat,shift).download(),npMat >> shift))
|
||||
cv.cuda.rshift(cuMat,shift,cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),npMat >> shift))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.lshift(cuMat,shift).download(),(npMat << shift).astype('uint8')))
|
||||
cv.cuda.lshift(cuMat,shift,cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),(npMat << shift).astype('uint8')))
|
||||
|
||||
def test_arithmetic(self):
|
||||
npMat1 = np.random.random((128, 128, 3)) - 0.5
|
||||
npMat2 = np.random.random((128, 128, 3)) - 0.5
|
||||
scalar = np.random.random()
|
||||
|
||||
cuMat1 = cv.cuda_GpuMat()
|
||||
cuMat2 = cv.cuda_GpuMat()
|
||||
cuMat1.upload(npMat1)
|
||||
cuMat2.upload(npMat2)
|
||||
cuMatDst = cv.cuda_GpuMat(cuMat1.size(),cuMat1.type())
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.add(cuMat1, cuMat2).download(),
|
||||
cv.add(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.addWithScalar(cuMat1, [scalar]*3).download(),
|
||||
cv.add(npMat1, scalar)))
|
||||
|
||||
cv.cuda.add(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.add(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.subtract(cuMat1, cuMat2).download(),
|
||||
cv.subtract(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.subtractWithScalar(cuMat1, [scalar]*3).download(),
|
||||
cv.subtract(npMat1, scalar)))
|
||||
|
||||
cv.cuda.subtract(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.subtract(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.multiply(cuMat1, cuMat2).download(),
|
||||
cv.multiply(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.multiplyWithScalar(cuMat1, [scalar]*3).download(),
|
||||
cv.multiply(npMat1, scalar)))
|
||||
|
||||
cv.cuda.multiply(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.multiply(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.divide(cuMat1, cuMat2).download(),
|
||||
cv.divide(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.divideWithScalar(cuMat1, [scalar]*3).download(),
|
||||
cv.divide(npMat1, scalar)))
|
||||
|
||||
cv.cuda.divide(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.divide(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.absdiff(cuMat1, cuMat2).download(),
|
||||
cv.absdiff(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.absdiffWithScalar(cuMat1, [scalar]*3).download(),
|
||||
cv.absdiff(npMat1, scalar)))
|
||||
|
||||
cv.cuda.absdiff(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.absdiff(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.compare(cuMat1, cuMat2, cv.CMP_GE).download(),
|
||||
cv.compare(npMat1, npMat2, cv.CMP_GE)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.compareWithScalar(cuMat1, [scalar]*3, cv.CMP_GE).download(),
|
||||
cv.compare(npMat1, scalar, cv.CMP_GE)))
|
||||
|
||||
cuMatDst1 = cv.cuda_GpuMat(cuMat1.size(),cv.CV_8UC3)
|
||||
cv.cuda.compare(cuMat1, cuMat2, cv.CMP_GE, cuMatDst1)
|
||||
self.assertTrue(np.allclose(cuMatDst1.download(),cv.compare(npMat1, npMat2, cv.CMP_GE)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.abs(cuMat1).download(),
|
||||
np.abs(npMat1)))
|
||||
|
||||
cv.cuda.abs(cuMat1, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),np.abs(npMat1)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.sqrt(cv.cuda.sqr(cuMat1)).download(),
|
||||
cv.cuda.abs(cuMat1).download()))
|
||||
|
||||
cv.cuda.sqr(cuMat1, cuMatDst)
|
||||
cv.cuda.sqrt(cuMatDst, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.cuda.abs(cuMat1).download()))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.log(cv.cuda.exp(cuMat1)).download(),
|
||||
npMat1))
|
||||
|
||||
cv.cuda.exp(cuMat1, cuMatDst)
|
||||
cv.cuda.log(cuMatDst, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),npMat1))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.pow(cuMat1, 2).download(),
|
||||
cv.pow(npMat1, 2)))
|
||||
|
||||
cv.cuda.pow(cuMat1, 2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.pow(npMat1, 2)))
|
||||
|
||||
def test_logical(self):
|
||||
npMat1 = (np.random.random((128, 128)) * 255).astype(np.uint8)
|
||||
npMat2 = (np.random.random((128, 128)) * 255).astype(np.uint8)
|
||||
scalar = np.random.random()
|
||||
|
||||
cuMat1 = cv.cuda_GpuMat()
|
||||
cuMat2 = cv.cuda_GpuMat()
|
||||
cuMat1.upload(npMat1)
|
||||
cuMat2.upload(npMat2)
|
||||
cuMatDst = cv.cuda_GpuMat(cuMat1.size(),cuMat1.type())
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.bitwise_or(cuMat1, cuMat2).download(),
|
||||
cv.bitwise_or(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.bitwise_or_with_scalar(cuMat1, scalar).download(),
|
||||
cv.bitwise_or(npMat1, scalar)))
|
||||
|
||||
cv.cuda.bitwise_or(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.bitwise_or(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.bitwise_and(cuMat1, cuMat2).download(),
|
||||
cv.bitwise_and(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.bitwise_and_with_scalar(cuMat1, scalar).download(),
|
||||
cv.bitwise_and(npMat1, scalar)))
|
||||
|
||||
cv.cuda.bitwise_and(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.bitwise_and(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.bitwise_xor(cuMat1, cuMat2).download(),
|
||||
cv.bitwise_xor(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.bitwise_xor_with_scalar(cuMat1, scalar).download(),
|
||||
cv.bitwise_xor(npMat1, scalar)))
|
||||
|
||||
cv.cuda.bitwise_xor(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.bitwise_xor(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.bitwise_not(cuMat1).download(),
|
||||
cv.bitwise_not(npMat1)))
|
||||
|
||||
cv.cuda.bitwise_not(cuMat1, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.bitwise_not(npMat1)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.min(cuMat1, cuMat2).download(),
|
||||
cv.min(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.minWithScalar(cuMat1, scalar).download(),
|
||||
cv.min(npMat1, scalar)))
|
||||
|
||||
cv.cuda.min(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.min(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.max(cuMat1, cuMat2).download(),
|
||||
cv.max(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(np.allclose(cv.cuda.maxWithScalar(cuMat1, scalar).download(),
|
||||
cv.max(npMat1, scalar)))
|
||||
|
||||
cv.cuda.max(cuMat1, cuMat2, cuMatDst)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),cv.max(npMat1, npMat2)))
|
||||
|
||||
self.assertTrue(cv.cuda.minMax(cuMat1),cv.minMaxLoc(npMat1)[:2])
|
||||
self.assertTrue(cv.cuda.minMaxLoc(cuMat1),cv.minMaxLoc(npMat1))
|
||||
|
||||
def test_convolution(self):
|
||||
npMat = (np.random.random((128, 128)) * 255).astype(np.float32)
|
||||
npDims = np.array(npMat.shape)
|
||||
kernel = (np.random.random((3, 3)) * 1).astype(np.float32)
|
||||
kernelDims = np.array(kernel.shape)
|
||||
iS = (kernelDims/2).astype(int)
|
||||
iE = npDims - kernelDims + iS
|
||||
|
||||
cuMat = cv.cuda_GpuMat(npMat)
|
||||
cuKernel= cv.cuda_GpuMat(kernel)
|
||||
cuMatDst = cv.cuda_GpuMat(tuple(npDims - kernelDims + 1), cuMat.type())
|
||||
conv = cv.cuda.createConvolution()
|
||||
|
||||
self.assertTrue(np.allclose(conv.convolve(cuMat,cuKernel,ccorr=True).download(),
|
||||
cv.filter2D(npMat,-1,kernel,anchor=(-1,-1))[iS[0]:iE[0]+1,iS[1]:iE[1]+1]))
|
||||
|
||||
conv.convolve(cuMat,cuKernel,cuMatDst,True)
|
||||
self.assertTrue(np.allclose(cuMatDst.download(),
|
||||
cv.filter2D(npMat,-1,kernel,anchor=(-1,-1))[iS[0]:iE[0]+1,iS[1]:iE[1]+1]))
|
||||
|
||||
def test_inrange(self):
|
||||
npMat = (np.random.random((128, 128, 3)) * 255).astype(np.float32)
|
||||
|
||||
bound1 = np.random.random((4,)) * 255
|
||||
bound2 = np.random.random((4,)) * 255
|
||||
lowerb = np.minimum(bound1, bound2).tolist()
|
||||
upperb = np.maximum(bound1, bound2).tolist()
|
||||
|
||||
cuMat = cv.cuda_GpuMat()
|
||||
cuMat.upload(npMat)
|
||||
|
||||
self.assertTrue((cv.cuda.inRange(cuMat, lowerb, upperb).download() ==
|
||||
cv.inRange(npMat, np.array(lowerb), np.array(upperb))).all())
|
||||
|
||||
cuMatDst = cv.cuda_GpuMat(cuMat.size(), cv.CV_8UC1)
|
||||
cv.cuda.inRange(cuMat, lowerb, upperb, cuMatDst)
|
||||
self.assertTrue((cuMatDst.download() ==
|
||||
cv.inRange(npMat, np.array(lowerb), np.array(upperb))).all())
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
@@ -0,0 +1,254 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GEMM
|
||||
|
||||
#ifdef HAVE_CUBLAS
|
||||
|
||||
CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T)
|
||||
#define ALL_GEMM_FLAGS Values(GemmFlags(0), GemmFlags(cv::GEMM_1_T), GemmFlags(cv::GEMM_2_T), GemmFlags(cv::GEMM_3_T), \
|
||||
GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T | cv::GEMM_3_T))
|
||||
|
||||
DEF_PARAM_TEST(Sz_Type_Flags, cv::Size, MatType, GemmFlags);
|
||||
|
||||
PERF_TEST_P(Sz_Type_Flags, GEMM,
|
||||
Combine(Values(cv::Size(512, 512), cv::Size(1024, 1024)),
|
||||
Values(CV_32FC1, CV_32FC2, CV_64FC1),
|
||||
ALL_GEMM_FLAGS))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int type = GET_PARAM(1);
|
||||
const int flags = GET_PARAM(2);
|
||||
|
||||
cv::Mat src1(size, type);
|
||||
declare.in(src1, WARMUP_RNG);
|
||||
|
||||
cv::Mat src2(size, type);
|
||||
declare.in(src2, WARMUP_RNG);
|
||||
|
||||
cv::Mat src3(size, type);
|
||||
declare.in(src3, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
declare.time(5.0);
|
||||
|
||||
const cv::cuda::GpuMat d_src1(src1);
|
||||
const cv::cuda::GpuMat d_src2(src2);
|
||||
const cv::cuda::GpuMat d_src3(src3);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, dst, flags);
|
||||
|
||||
CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
declare.time(50.0);
|
||||
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::gemm(src1, src2, 1.0, src3, 1.0, dst, flags);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// MulSpectrums
|
||||
|
||||
CV_FLAGS(DftFlags, 0, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT)
|
||||
|
||||
DEF_PARAM_TEST(Sz_Flags, cv::Size, DftFlags);
|
||||
|
||||
PERF_TEST_P(Sz_Flags, MulSpectrums,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(0, DftFlags(cv::DFT_ROWS))))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int flag = GET_PARAM(1);
|
||||
|
||||
cv::Mat a(size, CV_32FC2);
|
||||
cv::Mat b(size, CV_32FC2);
|
||||
declare.in(a, b, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_a(a);
|
||||
const cv::cuda::GpuMat d_b(b);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::mulSpectrums(d_a, d_b, dst, flag);
|
||||
|
||||
CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::mulSpectrums(a, b, dst, flag);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// MulAndScaleSpectrums
|
||||
|
||||
PERF_TEST_P(Sz, MulAndScaleSpectrums,
|
||||
CUDA_TYPICAL_MAT_SIZES)
|
||||
{
|
||||
const cv::Size size = GetParam();
|
||||
|
||||
const float scale = 1.f / size.area();
|
||||
|
||||
cv::Mat src1(size, CV_32FC2);
|
||||
cv::Mat src2(size, CV_32FC2);
|
||||
declare.in(src1,src2, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src1(src1);
|
||||
const cv::cuda::GpuMat d_src2(src2);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::mulAndScaleSpectrums(d_src1, d_src2, dst, cv::DFT_ROWS, scale, false);
|
||||
|
||||
CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL_NO_CPU();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Dft
|
||||
|
||||
PERF_TEST_P(Sz_Flags, Dft,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(0, DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE))))
|
||||
{
|
||||
declare.time(10.0);
|
||||
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int flag = GET_PARAM(1);
|
||||
|
||||
cv::Mat src(size, CV_32FC2);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::dft(d_src, dst, size, flag);
|
||||
|
||||
CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::dft(src, dst, flag);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Convolve
|
||||
|
||||
DEF_PARAM_TEST(Sz_KernelSz_Ccorr, cv::Size, int, bool);
|
||||
|
||||
PERF_TEST_P(Sz_KernelSz_Ccorr, Convolve,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(17, 27, 32, 64),
|
||||
Bool()))
|
||||
{
|
||||
declare.time(10.0);
|
||||
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int templ_size = GET_PARAM(1);
|
||||
const bool ccorr = GET_PARAM(2);
|
||||
|
||||
const cv::Mat image(size, CV_32FC1);
|
||||
const cv::Mat templ(templ_size, templ_size, CV_32FC1);
|
||||
declare.in(image, templ, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
cv::cuda::GpuMat d_image = cv::cuda::createContinuous(size, CV_32FC1);
|
||||
d_image.upload(image);
|
||||
|
||||
cv::cuda::GpuMat d_templ = cv::cuda::createContinuous(templ_size, templ_size, CV_32FC1);
|
||||
d_templ.upload(templ);
|
||||
|
||||
cv::Ptr<cv::cuda::Convolution> convolution = cv::cuda::createConvolution();
|
||||
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() convolution->convolve(d_image, d_templ, dst, ccorr);
|
||||
|
||||
CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ccorr)
|
||||
FAIL_NO_CPU();
|
||||
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::filter2D(image, dst, image.depth(), templ);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,323 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
#define ARITHM_MAT_DEPTH Values(CV_8U, CV_16U, CV_32F, CV_64F)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Merge
|
||||
|
||||
DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, MatCn);
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn, Merge,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
ARITHM_MAT_DEPTH,
|
||||
Values(2, 3, 4)))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
|
||||
std::vector<cv::Mat> src(channels);
|
||||
for (int i = 0; i < channels; ++i)
|
||||
{
|
||||
src[i].create(size, depth);
|
||||
declare.in(src[i], WARMUP_RNG);
|
||||
}
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
std::vector<cv::cuda::GpuMat> d_src(channels);
|
||||
for (int i = 0; i < channels; ++i)
|
||||
d_src[i].upload(src[i]);
|
||||
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::merge(d_src, dst);
|
||||
|
||||
CUDA_SANITY_CHECK(dst, 1e-10);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::merge(src, dst);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Split
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn, Split,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
ARITHM_MAT_DEPTH,
|
||||
Values(2, 3, 4)))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
|
||||
cv::Mat src(size, CV_MAKE_TYPE(depth, channels));
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
std::vector<cv::cuda::GpuMat> dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::split(d_src, dst);
|
||||
|
||||
const cv::cuda::GpuMat& dst0 = dst[0];
|
||||
const cv::cuda::GpuMat& dst1 = dst[1];
|
||||
|
||||
CUDA_SANITY_CHECK(dst0, 1e-10);
|
||||
CUDA_SANITY_CHECK(dst1, 1e-10);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<cv::Mat> dst;
|
||||
|
||||
TEST_CYCLE() cv::split(src, dst);
|
||||
|
||||
const cv::Mat& dst0 = dst[0];
|
||||
const cv::Mat& dst1 = dst[1];
|
||||
|
||||
CPU_SANITY_CHECK(dst0);
|
||||
CPU_SANITY_CHECK(dst1);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Transpose
|
||||
|
||||
PERF_TEST_P(Sz_Type, Transpose,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_16SC2, CV_32SC1, CV_32SC2, CV_64FC1)))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int type = GET_PARAM(1);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::transpose(d_src, dst);
|
||||
|
||||
CUDA_SANITY_CHECK(dst, 1e-10);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::transpose(src, dst);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Flip
|
||||
|
||||
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
|
||||
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
|
||||
|
||||
DEF_PARAM_TEST(Sz_Depth_Cn_Code, cv::Size, MatDepth, MatCn, FlipCode);
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn_Code, Flip,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
CUDA_CHANNELS_1_3_4,
|
||||
FlipCode::all()))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
const int flipCode = GET_PARAM(3);
|
||||
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::flip(d_src, dst, flipCode);
|
||||
|
||||
CUDA_SANITY_CHECK(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::flip(src, dst, flipCode);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// LutOneChannel
|
||||
|
||||
PERF_TEST_P(Sz_Type, LutOneChannel,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8UC1, CV_8UC3)))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int type = GET_PARAM(1);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
cv::Mat lut(1, 256, CV_8UC1);
|
||||
declare.in(lut, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
|
||||
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() lutAlg->transform(d_src, dst);
|
||||
|
||||
CUDA_SANITY_CHECK(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::LUT(src, lut, dst);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// LutMultiChannel
|
||||
|
||||
PERF_TEST_P(Sz_Type, LutMultiChannel,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values<MatType>(CV_8UC3)))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int type = GET_PARAM(1);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
cv::Mat lut(1, 256, CV_MAKE_TYPE(CV_8U, src.channels()));
|
||||
declare.in(lut, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
|
||||
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() lutAlg->transform(d_src, dst);
|
||||
|
||||
CUDA_SANITY_CHECK(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::LUT(src, lut, dst);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CopyMakeBorder
|
||||
|
||||
DEF_PARAM_TEST(Sz_Depth_Cn_Border, cv::Size, MatDepth, MatCn, BorderMode);
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn_Border, CopyMakeBorder,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
CUDA_CHANNELS_1_3_4,
|
||||
ALL_BORDER_MODES))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
const int borderMode = GET_PARAM(3);
|
||||
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::copyMakeBorder(d_src, dst, 5, 5, 5, 5, borderMode);
|
||||
|
||||
CUDA_SANITY_CHECK(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace perf;
|
||||
|
||||
CV_PERF_TEST_CUDA_MAIN(cudaarithm)
|
||||
@@ -0,0 +1,55 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__
|
||||
#define __OPENCV_PERF_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/ts/cuda_perf.hpp"
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
|
||||
namespace opencv_test {
|
||||
using namespace perf;
|
||||
using namespace testing;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,520 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Norm
|
||||
|
||||
DEF_PARAM_TEST(Sz_Depth_Norm, cv::Size, MatDepth, NormType);
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Norm, Norm,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32S, CV_32F),
|
||||
Values(NormType(cv::NORM_INF), NormType(cv::NORM_L1), NormType(cv::NORM_L2))))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int normType = GET_PARAM(2);
|
||||
|
||||
cv::Mat src(size, depth);
|
||||
if (depth == CV_8U)
|
||||
cv::randu(src, 0, 254);
|
||||
else
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat d_buf;
|
||||
double gpu_dst;
|
||||
|
||||
TEST_CYCLE() gpu_dst = cv::cuda::norm(d_src, normType, d_buf);
|
||||
|
||||
SANITY_CHECK(gpu_dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
double cpu_dst;
|
||||
|
||||
TEST_CYCLE() cpu_dst = cv::norm(src, normType);
|
||||
|
||||
SANITY_CHECK(cpu_dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// NormDiff
|
||||
|
||||
DEF_PARAM_TEST(Sz_Norm, cv::Size, NormType);
|
||||
|
||||
PERF_TEST_P(Sz_Norm, NormDiff,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(NormType(cv::NORM_INF), NormType(cv::NORM_L1), NormType(cv::NORM_L2))))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int normType = GET_PARAM(1);
|
||||
|
||||
cv::Mat src1(size, CV_8UC1);
|
||||
declare.in(src1, WARMUP_RNG);
|
||||
|
||||
cv::Mat src2(size, CV_8UC1);
|
||||
declare.in(src2, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src1(src1);
|
||||
const cv::cuda::GpuMat d_src2(src2);
|
||||
double gpu_dst;
|
||||
|
||||
TEST_CYCLE() gpu_dst = cv::cuda::norm(d_src1, d_src2, normType);
|
||||
|
||||
SANITY_CHECK(gpu_dst);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
double cpu_dst;
|
||||
|
||||
TEST_CYCLE() cpu_dst = cv::norm(src1, src2, normType);
|
||||
|
||||
SANITY_CHECK(cpu_dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Sum
|
||||
|
||||
DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, MatCn);
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn, Sum,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
CUDA_CHANNELS_1_3_4))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::Scalar gpu_dst;
|
||||
|
||||
TEST_CYCLE() gpu_dst = cv::cuda::sum(d_src);
|
||||
|
||||
SANITY_CHECK(gpu_dst, 1e-5, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Scalar cpu_dst;
|
||||
|
||||
TEST_CYCLE() cpu_dst = cv::sum(src);
|
||||
|
||||
SANITY_CHECK(cpu_dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// SumAbs
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn, SumAbs,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
CUDA_CHANNELS_1_3_4))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::Scalar gpu_dst;
|
||||
|
||||
TEST_CYCLE() gpu_dst = cv::cuda::absSum(d_src);
|
||||
|
||||
SANITY_CHECK(gpu_dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL_NO_CPU();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// SumSqr
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn, SumSqr,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values<MatDepth>(CV_8U, CV_16U, CV_32F),
|
||||
CUDA_CHANNELS_1_3_4))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::Scalar gpu_dst;
|
||||
|
||||
TEST_CYCLE() gpu_dst = cv::cuda::sqrSum(d_src);
|
||||
|
||||
SANITY_CHECK(gpu_dst, 1e-6, ERROR_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL_NO_CPU();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// MinMax
|
||||
|
||||
DEF_PARAM_TEST(Sz_Depth, cv::Size, MatDepth);
|
||||
|
||||
PERF_TEST_P(Sz_Depth, MinMax,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F, CV_64F)))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
|
||||
cv::Mat src(size, depth);
|
||||
if (depth == CV_8U)
|
||||
cv::randu(src, 0, 254);
|
||||
else
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
double gpu_minVal, gpu_maxVal;
|
||||
|
||||
TEST_CYCLE() cv::cuda::minMax(d_src, &gpu_minVal, &gpu_maxVal, cv::cuda::GpuMat());
|
||||
|
||||
SANITY_CHECK(gpu_minVal, 1e-10);
|
||||
SANITY_CHECK(gpu_maxVal, 1e-10);
|
||||
}
|
||||
else
|
||||
{
|
||||
double cpu_minVal, cpu_maxVal;
|
||||
|
||||
TEST_CYCLE() cv::minMaxLoc(src, &cpu_minVal, &cpu_maxVal);
|
||||
|
||||
SANITY_CHECK(cpu_minVal);
|
||||
SANITY_CHECK(cpu_maxVal);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// MinMaxLoc
|
||||
|
||||
PERF_TEST_P(Sz_Depth, MinMaxLoc,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F, CV_64F)))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
|
||||
cv::Mat src(size, depth);
|
||||
if (depth == CV_8U)
|
||||
cv::randu(src, 0, 254);
|
||||
else
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
double gpu_minVal, gpu_maxVal;
|
||||
cv::Point gpu_minLoc, gpu_maxLoc;
|
||||
|
||||
TEST_CYCLE() cv::cuda::minMaxLoc(d_src, &gpu_minVal, &gpu_maxVal, &gpu_minLoc, &gpu_maxLoc);
|
||||
|
||||
SANITY_CHECK(gpu_minVal, 1e-10);
|
||||
SANITY_CHECK(gpu_maxVal, 1e-10);
|
||||
}
|
||||
else
|
||||
{
|
||||
double cpu_minVal, cpu_maxVal;
|
||||
cv::Point cpu_minLoc, cpu_maxLoc;
|
||||
|
||||
TEST_CYCLE() cv::minMaxLoc(src, &cpu_minVal, &cpu_maxVal, &cpu_minLoc, &cpu_maxLoc);
|
||||
|
||||
SANITY_CHECK(cpu_minVal);
|
||||
SANITY_CHECK(cpu_maxVal);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CountNonZero
|
||||
|
||||
PERF_TEST_P(Sz_Depth, CountNonZero,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F, CV_64F)))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
|
||||
cv::Mat src(size, depth);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
int gpu_dst = 0;
|
||||
|
||||
TEST_CYCLE() gpu_dst = cv::cuda::countNonZero(d_src);
|
||||
|
||||
SANITY_CHECK(gpu_dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
int cpu_dst = 0;
|
||||
|
||||
TEST_CYCLE() cpu_dst = cv::countNonZero(src);
|
||||
|
||||
SANITY_CHECK(cpu_dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Reduce
|
||||
|
||||
CV_ENUM(ReduceCode, REDUCE_SUM, REDUCE_AVG, REDUCE_MAX, REDUCE_MIN)
|
||||
|
||||
enum {Rows = 0, Cols = 1};
|
||||
CV_ENUM(ReduceDim, Rows, Cols)
|
||||
|
||||
DEF_PARAM_TEST(Sz_Depth_Cn_Code_Dim, cv::Size, MatDepth, MatCn, ReduceCode, ReduceDim);
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn_Code_Dim, Reduce,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_16S, CV_32F),
|
||||
Values(1, 2, 3, 4),
|
||||
ReduceCode::all(),
|
||||
ReduceDim::all()))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
const int reduceOp = GET_PARAM(3);
|
||||
const int dim = GET_PARAM(4);
|
||||
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::reduce(d_src, dst, dim, reduceOp, CV_32F);
|
||||
|
||||
dst = dst.reshape(dst.channels(), 1);
|
||||
|
||||
CUDA_SANITY_CHECK(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::reduce(src, dst, dim, reduceOp, CV_32F);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Normalize
|
||||
|
||||
DEF_PARAM_TEST(Sz_Depth_NormType, cv::Size, MatDepth, NormType);
|
||||
|
||||
PERF_TEST_P(Sz_Depth_NormType, Normalize,
|
||||
Combine(CUDA_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F, CV_64F),
|
||||
Values(NormType(cv::NORM_INF),
|
||||
NormType(cv::NORM_L1),
|
||||
NormType(cv::NORM_L2),
|
||||
NormType(cv::NORM_MINMAX))))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int type = GET_PARAM(1);
|
||||
const int norm_type = GET_PARAM(2);
|
||||
|
||||
const double alpha = 1;
|
||||
const double beta = 0;
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::normalize(d_src, dst, alpha, beta, norm_type, type, cv::cuda::GpuMat());
|
||||
|
||||
CUDA_SANITY_CHECK(dst, 1e-6);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::normalize(src, dst, alpha, beta, norm_type, type);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// MeanStdDev
|
||||
|
||||
PERF_TEST_P(Sz, MeanStdDev,
|
||||
CUDA_TYPICAL_MAT_SIZES)
|
||||
{
|
||||
const cv::Size size = GetParam();
|
||||
|
||||
cv::Mat src(size, CV_8UC1);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::Scalar gpu_mean;
|
||||
cv::Scalar gpu_stddev;
|
||||
|
||||
TEST_CYCLE() cv::cuda::meanStdDev(d_src, gpu_mean, gpu_stddev);
|
||||
|
||||
SANITY_CHECK(gpu_mean);
|
||||
SANITY_CHECK(gpu_stddev);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Scalar cpu_mean;
|
||||
cv::Scalar cpu_stddev;
|
||||
|
||||
TEST_CYCLE() cv::meanStdDev(src, cpu_mean, cpu_stddev);
|
||||
|
||||
SANITY_CHECK(cpu_mean);
|
||||
SANITY_CHECK(cpu_stddev);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Integral
|
||||
|
||||
PERF_TEST_P(Sz, Integral,
|
||||
CUDA_TYPICAL_MAT_SIZES)
|
||||
{
|
||||
const cv::Size size = GetParam();
|
||||
|
||||
cv::Mat src(size, CV_8UC1);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::integral(d_src, dst);
|
||||
|
||||
CUDA_SANITY_CHECK(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat dst;
|
||||
|
||||
TEST_CYCLE() cv::integral(src, dst);
|
||||
|
||||
CPU_SANITY_CHECK(dst);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// IntegralSqr
|
||||
|
||||
PERF_TEST_P(Sz, IntegralSqr,
|
||||
CUDA_TYPICAL_MAT_SIZES)
|
||||
{
|
||||
const cv::Size size = GetParam();
|
||||
|
||||
cv::Mat src(size, CV_8UC1);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
if (PERF_RUN_CUDA())
|
||||
{
|
||||
const cv::cuda::GpuMat d_src(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
|
||||
TEST_CYCLE() cv::cuda::sqrIntegral(d_src, dst);
|
||||
|
||||
CUDA_SANITY_CHECK(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL_NO_CPU();
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,602 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::cuda::gemm(InputArray, InputArray, double, InputArray, double, OutputArray, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::mulSpectrums(InputArray, InputArray, OutputArray, int, bool, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::mulAndScaleSpectrums(InputArray, InputArray, OutputArray, int, float, bool, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::dft(InputArray, OutputArray, Size, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
Ptr<DFT> cv::cuda::createDFT(Size, int) { throw_no_cuda(); return Ptr<DFT>(); }
|
||||
|
||||
Ptr<Convolution> cv::cuda::createConvolution(Size) { throw_no_cuda(); return Ptr<Convolution>(); }
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
namespace
|
||||
{
|
||||
#define error_entry(entry) { entry, #entry }
|
||||
|
||||
struct ErrorEntry
|
||||
{
|
||||
int code;
|
||||
const char* str;
|
||||
};
|
||||
|
||||
struct ErrorEntryComparer
|
||||
{
|
||||
int code;
|
||||
ErrorEntryComparer(int code_) : code(code_) {}
|
||||
bool operator()(const ErrorEntry& e) const { return e.code == code; }
|
||||
};
|
||||
|
||||
String getErrorString(int code, const ErrorEntry* errors, size_t n)
|
||||
{
|
||||
size_t idx = std::find_if(errors, errors + n, ErrorEntryComparer(code)) - errors;
|
||||
|
||||
const char* msg = (idx != n) ? errors[idx].str : "Unknown error code";
|
||||
String str = cv::format("%s [Code = %d]", msg, code);
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_CUBLAS
|
||||
namespace
|
||||
{
|
||||
const ErrorEntry cublas_errors[] =
|
||||
{
|
||||
error_entry( CUBLAS_STATUS_SUCCESS ),
|
||||
error_entry( CUBLAS_STATUS_NOT_INITIALIZED ),
|
||||
error_entry( CUBLAS_STATUS_ALLOC_FAILED ),
|
||||
error_entry( CUBLAS_STATUS_INVALID_VALUE ),
|
||||
error_entry( CUBLAS_STATUS_ARCH_MISMATCH ),
|
||||
error_entry( CUBLAS_STATUS_MAPPING_ERROR ),
|
||||
error_entry( CUBLAS_STATUS_EXECUTION_FAILED ),
|
||||
error_entry( CUBLAS_STATUS_INTERNAL_ERROR )
|
||||
};
|
||||
|
||||
const size_t cublas_error_num = sizeof(cublas_errors) / sizeof(cublas_errors[0]);
|
||||
|
||||
static inline void ___cublasSafeCall(cublasStatus_t err, const char* file, const int line, const char* func)
|
||||
{
|
||||
if (CUBLAS_STATUS_SUCCESS != err)
|
||||
{
|
||||
String msg = getErrorString(err, cublas_errors, cublas_error_num);
|
||||
cv::error(cv::Error::GpuApiCallError, msg, func, file, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define cublasSafeCall(expr) ___cublasSafeCall(expr, __FILE__, __LINE__, CV_Func)
|
||||
#endif // HAVE_CUBLAS
|
||||
|
||||
#ifdef HAVE_CUFFT
|
||||
namespace
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CUFFT errors
|
||||
|
||||
const ErrorEntry cufft_errors[] =
|
||||
{
|
||||
error_entry( CUFFT_INVALID_PLAN ),
|
||||
error_entry( CUFFT_ALLOC_FAILED ),
|
||||
error_entry( CUFFT_INVALID_TYPE ),
|
||||
error_entry( CUFFT_INVALID_VALUE ),
|
||||
error_entry( CUFFT_INTERNAL_ERROR ),
|
||||
error_entry( CUFFT_EXEC_FAILED ),
|
||||
error_entry( CUFFT_SETUP_FAILED ),
|
||||
error_entry( CUFFT_INVALID_SIZE ),
|
||||
error_entry( CUFFT_UNALIGNED_DATA )
|
||||
};
|
||||
|
||||
const int cufft_error_num = sizeof(cufft_errors) / sizeof(cufft_errors[0]);
|
||||
|
||||
void ___cufftSafeCall(int err, const char* file, const int line, const char* func)
|
||||
{
|
||||
if (CUFFT_SUCCESS != err)
|
||||
{
|
||||
String msg = getErrorString(err, cufft_errors, cufft_error_num);
|
||||
cv::error(cv::Error::GpuApiCallError, msg, func, file, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define cufftSafeCall(expr) ___cufftSafeCall(expr, __FILE__, __LINE__, CV_Func)
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// gemm
|
||||
|
||||
void cv::cuda::gemm(InputArray _src1, InputArray _src2, double alpha, InputArray _src3, double beta, OutputArray _dst, int flags, Stream& stream)
|
||||
{
|
||||
#ifndef HAVE_CUBLAS
|
||||
CV_UNUSED(_src1);
|
||||
CV_UNUSED(_src2);
|
||||
CV_UNUSED(alpha);
|
||||
CV_UNUSED(_src3);
|
||||
CV_UNUSED(beta);
|
||||
CV_UNUSED(_dst);
|
||||
CV_UNUSED(flags);
|
||||
CV_UNUSED(stream);
|
||||
CV_Error(Error::StsNotImplemented, "The library was build without CUBLAS");
|
||||
#else
|
||||
// CUBLAS works with column-major matrices
|
||||
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
GpuMat src3 = getInputMat(_src3, stream);
|
||||
|
||||
CV_Assert( src1.type() == CV_32FC1 || src1.type() == CV_32FC2 || src1.type() == CV_64FC1 || src1.type() == CV_64FC2 );
|
||||
CV_Assert( src2.type() == src1.type() && (src3.empty() || src3.type() == src1.type()) );
|
||||
|
||||
if (src1.depth() == CV_64F)
|
||||
{
|
||||
if (!deviceSupports(NATIVE_DOUBLE))
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double");
|
||||
}
|
||||
|
||||
bool tr1 = (flags & GEMM_1_T) != 0;
|
||||
bool tr2 = (flags & GEMM_2_T) != 0;
|
||||
bool tr3 = (flags & GEMM_3_T) != 0;
|
||||
|
||||
if (src1.type() == CV_64FC2)
|
||||
{
|
||||
if (tr1 || tr2 || tr3)
|
||||
CV_Error(cv::Error::StsNotImplemented, "transpose operation doesn't implemented for CV_64FC2 type");
|
||||
}
|
||||
|
||||
Size src1Size = tr1 ? Size(src1.rows, src1.cols) : src1.size();
|
||||
Size src2Size = tr2 ? Size(src2.rows, src2.cols) : src2.size();
|
||||
Size src3Size = tr3 ? Size(src3.rows, src3.cols) : src3.size();
|
||||
Size dstSize(src2Size.width, src1Size.height);
|
||||
|
||||
CV_Assert( src1Size.width == src2Size.height );
|
||||
CV_Assert( src3.empty() || src3Size == dstSize );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, dstSize, src1.type(), stream);
|
||||
|
||||
if (beta != 0)
|
||||
{
|
||||
if (src3.empty())
|
||||
{
|
||||
dst.setTo(Scalar::all(0), stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tr3)
|
||||
{
|
||||
cuda::transpose(src3, dst, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
src3.copyTo(dst, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cublasHandle_t handle;
|
||||
cublasSafeCall( cublasCreate_v2(&handle) );
|
||||
|
||||
cublasSafeCall( cublasSetStream_v2(handle, StreamAccessor::getStream(stream)) );
|
||||
|
||||
cublasSafeCall( cublasSetPointerMode_v2(handle, CUBLAS_POINTER_MODE_HOST) );
|
||||
|
||||
const float alphaf = static_cast<float>(alpha);
|
||||
const float betaf = static_cast<float>(beta);
|
||||
|
||||
const cuComplex alphacf = make_cuComplex(alphaf, 0);
|
||||
const cuComplex betacf = make_cuComplex(betaf, 0);
|
||||
|
||||
const cuDoubleComplex alphac = make_cuDoubleComplex(alpha, 0);
|
||||
const cuDoubleComplex betac = make_cuDoubleComplex(beta, 0);
|
||||
|
||||
cublasOperation_t transa = tr2 ? CUBLAS_OP_T : CUBLAS_OP_N;
|
||||
cublasOperation_t transb = tr1 ? CUBLAS_OP_T : CUBLAS_OP_N;
|
||||
|
||||
switch (src1.type())
|
||||
{
|
||||
case CV_32FC1:
|
||||
cublasSafeCall( cublasSgemm_v2(handle, transa, transb, tr2 ? src2.rows : src2.cols, tr1 ? src1.cols : src1.rows, tr2 ? src2.cols : src2.rows,
|
||||
&alphaf,
|
||||
src2.ptr<float>(), static_cast<int>(src2.step / sizeof(float)),
|
||||
src1.ptr<float>(), static_cast<int>(src1.step / sizeof(float)),
|
||||
&betaf,
|
||||
dst.ptr<float>(), static_cast<int>(dst.step / sizeof(float))) );
|
||||
break;
|
||||
|
||||
case CV_64FC1:
|
||||
cublasSafeCall( cublasDgemm_v2(handle, transa, transb, tr2 ? src2.rows : src2.cols, tr1 ? src1.cols : src1.rows, tr2 ? src2.cols : src2.rows,
|
||||
&alpha,
|
||||
src2.ptr<double>(), static_cast<int>(src2.step / sizeof(double)),
|
||||
src1.ptr<double>(), static_cast<int>(src1.step / sizeof(double)),
|
||||
&beta,
|
||||
dst.ptr<double>(), static_cast<int>(dst.step / sizeof(double))) );
|
||||
break;
|
||||
|
||||
case CV_32FC2:
|
||||
cublasSafeCall( cublasCgemm_v2(handle, transa, transb, tr2 ? src2.rows : src2.cols, tr1 ? src1.cols : src1.rows, tr2 ? src2.cols : src2.rows,
|
||||
&alphacf,
|
||||
src2.ptr<cuComplex>(), static_cast<int>(src2.step / sizeof(cuComplex)),
|
||||
src1.ptr<cuComplex>(), static_cast<int>(src1.step / sizeof(cuComplex)),
|
||||
&betacf,
|
||||
dst.ptr<cuComplex>(), static_cast<int>(dst.step / sizeof(cuComplex))) );
|
||||
break;
|
||||
|
||||
case CV_64FC2:
|
||||
cublasSafeCall( cublasZgemm_v2(handle, transa, transb, tr2 ? src2.rows : src2.cols, tr1 ? src1.cols : src1.rows, tr2 ? src2.cols : src2.rows,
|
||||
&alphac,
|
||||
src2.ptr<cuDoubleComplex>(), static_cast<int>(src2.step / sizeof(cuDoubleComplex)),
|
||||
src1.ptr<cuDoubleComplex>(), static_cast<int>(src1.step / sizeof(cuDoubleComplex)),
|
||||
&betac,
|
||||
dst.ptr<cuDoubleComplex>(), static_cast<int>(dst.step / sizeof(cuDoubleComplex))) );
|
||||
break;
|
||||
}
|
||||
|
||||
cublasSafeCall( cublasDestroy_v2(handle) );
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DFT function
|
||||
|
||||
void cv::cuda::dft(InputArray _src, OutputArray _dst, Size dft_size, int flags, Stream& stream)
|
||||
{
|
||||
if (getInputMat(_src, stream).channels() == 2)
|
||||
flags |= DFT_COMPLEX_INPUT;
|
||||
|
||||
Ptr<DFT> dft = createDFT(dft_size, flags);
|
||||
dft->compute(_src, _dst, stream);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DFT algorithm
|
||||
|
||||
#ifdef HAVE_CUFFT
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class DFTImpl : public DFT
|
||||
{
|
||||
Size dft_size, dft_size_opt;
|
||||
bool is_1d_input, is_row_dft, is_scaled_dft, is_inverse, is_complex_input, is_complex_output;
|
||||
|
||||
cufftType dft_type;
|
||||
cufftHandle plan;
|
||||
|
||||
public:
|
||||
DFTImpl(Size dft_size, int flags)
|
||||
: dft_size(dft_size),
|
||||
dft_size_opt(dft_size),
|
||||
is_1d_input((dft_size.height == 1) || (dft_size.width == 1)),
|
||||
is_row_dft((flags & DFT_ROWS) != 0),
|
||||
is_scaled_dft((flags & DFT_SCALE) != 0),
|
||||
is_inverse((flags & DFT_INVERSE) != 0),
|
||||
is_complex_input((flags & DFT_COMPLEX_INPUT) != 0),
|
||||
is_complex_output(!(flags & DFT_REAL_OUTPUT)),
|
||||
dft_type(!is_complex_input ? CUFFT_R2C : (is_complex_output ? CUFFT_C2C : CUFFT_C2R))
|
||||
{
|
||||
// We don't support unpacked output (in the case of real input)
|
||||
CV_Assert( !(flags & DFT_COMPLEX_OUTPUT) );
|
||||
|
||||
// We don't support real-to-real transform
|
||||
CV_Assert( is_complex_input || is_complex_output );
|
||||
|
||||
if (is_1d_input && !is_row_dft)
|
||||
{
|
||||
// If the source matrix is single column handle it as single row
|
||||
dft_size_opt.width = std::max(dft_size.width, dft_size.height);
|
||||
dft_size_opt.height = std::min(dft_size.width, dft_size.height);
|
||||
}
|
||||
|
||||
CV_Assert( dft_size_opt.width > 1 );
|
||||
|
||||
if (is_1d_input || is_row_dft)
|
||||
cufftSafeCall( cufftPlan1d(&plan, dft_size_opt.width, dft_type, dft_size_opt.height) );
|
||||
else
|
||||
cufftSafeCall( cufftPlan2d(&plan, dft_size_opt.height, dft_size_opt.width, dft_type) );
|
||||
}
|
||||
|
||||
~DFTImpl()
|
||||
{
|
||||
cufftSafeCall( cufftDestroy(plan) );
|
||||
}
|
||||
|
||||
void compute(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.type() == CV_32FC1 || src.type() == CV_32FC2 );
|
||||
CV_Assert( is_complex_input == (src.channels() == 2) );
|
||||
|
||||
// Make sure here we work with the continuous input,
|
||||
// as CUFFT can't handle gaps
|
||||
GpuMat src_cont;
|
||||
if (src.isContinuous())
|
||||
{
|
||||
src_cont = src;
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferPool pool(stream);
|
||||
src_cont.allocator = pool.getAllocator();
|
||||
createContinuous(src.rows, src.cols, src.type(), src_cont);
|
||||
src.copyTo(src_cont, stream);
|
||||
}
|
||||
|
||||
cufftSafeCall( cufftSetStream(plan, StreamAccessor::getStream(stream)) );
|
||||
|
||||
if (is_complex_input)
|
||||
{
|
||||
if (is_complex_output)
|
||||
{
|
||||
createContinuous(dft_size, CV_32FC2, _dst);
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
cufftSafeCall(cufftExecC2C(
|
||||
plan, src_cont.ptr<cufftComplex>(), dst.ptr<cufftComplex>(),
|
||||
is_inverse ? CUFFT_INVERSE : CUFFT_FORWARD));
|
||||
}
|
||||
else
|
||||
{
|
||||
createContinuous(dft_size, CV_32F, _dst);
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
cufftSafeCall(cufftExecC2R(
|
||||
plan, src_cont.ptr<cufftComplex>(), dst.ptr<cufftReal>()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We could swap dft_size for efficiency. Here we must reflect it
|
||||
if (dft_size == dft_size_opt)
|
||||
createContinuous(Size(dft_size.width / 2 + 1, dft_size.height), CV_32FC2, _dst);
|
||||
else
|
||||
createContinuous(Size(dft_size.width, dft_size.height / 2 + 1), CV_32FC2, _dst);
|
||||
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
cufftSafeCall(cufftExecR2C(
|
||||
plan, src_cont.ptr<cufftReal>(), dst.ptr<cufftComplex>()));
|
||||
}
|
||||
|
||||
if (is_scaled_dft)
|
||||
cuda::multiply(_dst, Scalar::all(1. / dft_size.area()), _dst, 1, -1, stream);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Ptr<DFT> cv::cuda::createDFT(Size dft_size, int flags)
|
||||
{
|
||||
#ifndef HAVE_CUFFT
|
||||
CV_UNUSED(dft_size);
|
||||
CV_UNUSED(flags);
|
||||
CV_Error(Error::StsNotImplemented, "The library was build without CUFFT");
|
||||
return Ptr<DFT>();
|
||||
#else
|
||||
return makePtr<DFTImpl>(dft_size, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Convolution
|
||||
|
||||
#ifdef HAVE_CUFFT
|
||||
|
||||
namespace
|
||||
{
|
||||
class ConvolutionImpl : public Convolution
|
||||
{
|
||||
public:
|
||||
explicit ConvolutionImpl(Size user_block_size_) : user_block_size(user_block_size_), planR2C(0), planC2R(0) {}
|
||||
~ConvolutionImpl();
|
||||
|
||||
void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr = false, Stream& stream = Stream::Null());
|
||||
|
||||
private:
|
||||
void create(Size image_size, Size templ_size);
|
||||
static Size estimateBlockSize(Size result_size);
|
||||
|
||||
Size result_size;
|
||||
Size block_size;
|
||||
Size user_block_size;
|
||||
Size dft_size;
|
||||
|
||||
cufftHandle planR2C, planC2R;
|
||||
Size plan_size;
|
||||
|
||||
GpuMat image_spect, templ_spect, result_spect;
|
||||
GpuMat image_block, templ_block, result_data;
|
||||
};
|
||||
|
||||
void ConvolutionImpl::create(Size image_size, Size templ_size)
|
||||
{
|
||||
result_size = Size(image_size.width - templ_size.width + 1,
|
||||
image_size.height - templ_size.height + 1);
|
||||
|
||||
block_size = user_block_size;
|
||||
if (user_block_size.width == 0 || user_block_size.height == 0)
|
||||
block_size = estimateBlockSize(result_size);
|
||||
|
||||
dft_size.width = 1 << int(ceil(std::log(block_size.width + templ_size.width - 1.) / std::log(2.)));
|
||||
dft_size.height = 1 << int(ceil(std::log(block_size.height + templ_size.height - 1.) / std::log(2.)));
|
||||
|
||||
// CUFFT has hard-coded kernels for power-of-2 sizes (up to 8192),
|
||||
// see CUDA Toolkit 4.1 CUFFT Library Programming Guide
|
||||
if (dft_size.width > 8192)
|
||||
dft_size.width = getOptimalDFTSize(block_size.width + templ_size.width - 1);
|
||||
if (dft_size.height > 8192)
|
||||
dft_size.height = getOptimalDFTSize(block_size.height + templ_size.height - 1);
|
||||
|
||||
// To avoid wasting time doing small DFTs
|
||||
dft_size.width = std::max(dft_size.width, 512);
|
||||
dft_size.height = std::max(dft_size.height, 512);
|
||||
|
||||
createContinuous(dft_size, CV_32F, image_block);
|
||||
createContinuous(dft_size, CV_32F, templ_block);
|
||||
createContinuous(dft_size, CV_32F, result_data);
|
||||
|
||||
int spect_len = dft_size.height * (dft_size.width / 2 + 1);
|
||||
createContinuous(1, spect_len, CV_32FC2, image_spect);
|
||||
createContinuous(1, spect_len, CV_32FC2, templ_spect);
|
||||
createContinuous(1, spect_len, CV_32FC2, result_spect);
|
||||
|
||||
// Use maximum result matrix block size for the estimated DFT block size
|
||||
block_size.width = std::min(dft_size.width - templ_size.width + 1, result_size.width);
|
||||
block_size.height = std::min(dft_size.height - templ_size.height + 1, result_size.height);
|
||||
|
||||
if (dft_size != plan_size)
|
||||
{
|
||||
if (planR2C != 0)
|
||||
cufftSafeCall( cufftDestroy(planR2C) );
|
||||
if (planC2R != 0)
|
||||
cufftSafeCall( cufftDestroy(planC2R) );
|
||||
|
||||
cufftSafeCall( cufftPlan2d(&planC2R, dft_size.height, dft_size.width, CUFFT_C2R) );
|
||||
cufftSafeCall( cufftPlan2d(&planR2C, dft_size.height, dft_size.width, CUFFT_R2C) );
|
||||
|
||||
plan_size = dft_size;
|
||||
}
|
||||
}
|
||||
|
||||
ConvolutionImpl::~ConvolutionImpl()
|
||||
{
|
||||
if (planR2C != 0)
|
||||
cufftSafeCall( cufftDestroy(planR2C) );
|
||||
if (planC2R != 0)
|
||||
cufftSafeCall( cufftDestroy(planC2R) );
|
||||
}
|
||||
|
||||
Size ConvolutionImpl::estimateBlockSize(Size result_size)
|
||||
{
|
||||
int width = (result_size.width + 2) / 3;
|
||||
int height = (result_size.height + 2) / 3;
|
||||
width = std::min(width, result_size.width);
|
||||
height = std::min(height, result_size.height);
|
||||
return Size(width, height);
|
||||
}
|
||||
|
||||
void ConvolutionImpl::convolve(InputArray _image, InputArray _templ, OutputArray _result, bool ccorr, Stream& _stream)
|
||||
{
|
||||
GpuMat image = getInputMat(_image, _stream);
|
||||
GpuMat templ = getInputMat(_templ, _stream);
|
||||
|
||||
CV_Assert( image.type() == CV_32FC1 );
|
||||
CV_Assert( templ.type() == CV_32FC1 );
|
||||
|
||||
create(image.size(), templ.size());
|
||||
|
||||
GpuMat result = getOutputMat(_result, result_size, CV_32FC1, _stream);
|
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
|
||||
cufftSafeCall( cufftSetStream(planR2C, stream) );
|
||||
cufftSafeCall( cufftSetStream(planC2R, stream) );
|
||||
|
||||
GpuMat templ_roi(templ.size(), CV_32FC1, templ.data, templ.step);
|
||||
cuda::copyMakeBorder(templ_roi, templ_block, 0, templ_block.rows - templ_roi.rows, 0,
|
||||
templ_block.cols - templ_roi.cols, 0, Scalar(), _stream);
|
||||
|
||||
cufftSafeCall( cufftExecR2C(planR2C, templ_block.ptr<cufftReal>(), templ_spect.ptr<cufftComplex>()) );
|
||||
|
||||
// Process all blocks of the result matrix
|
||||
for (int y = 0; y < result.rows; y += block_size.height)
|
||||
{
|
||||
for (int x = 0; x < result.cols; x += block_size.width)
|
||||
{
|
||||
Size image_roi_size(std::min(x + dft_size.width, image.cols) - x,
|
||||
std::min(y + dft_size.height, image.rows) - y);
|
||||
GpuMat image_roi(image_roi_size, CV_32F, (void*)(image.ptr<float>(y) + x),
|
||||
image.step);
|
||||
cuda::copyMakeBorder(image_roi, image_block, 0, image_block.rows - image_roi.rows,
|
||||
0, image_block.cols - image_roi.cols, 0, Scalar(), _stream);
|
||||
|
||||
cufftSafeCall(cufftExecR2C(planR2C, image_block.ptr<cufftReal>(),
|
||||
image_spect.ptr<cufftComplex>()));
|
||||
cuda::mulAndScaleSpectrums(image_spect, templ_spect, result_spect, 0,
|
||||
1.f / dft_size.area(), ccorr, _stream);
|
||||
cufftSafeCall(cufftExecC2R(planC2R, result_spect.ptr<cufftComplex>(),
|
||||
result_data.ptr<cufftReal>()));
|
||||
|
||||
Size result_roi_size(std::min(x + block_size.width, result.cols) - x,
|
||||
std::min(y + block_size.height, result.rows) - y);
|
||||
GpuMat result_roi(result_roi_size, result.type(),
|
||||
(void*)(result.ptr<float>(y) + x), result.step);
|
||||
GpuMat result_block(result_roi_size, result_data.type(),
|
||||
result_data.ptr(), result_data.step);
|
||||
|
||||
result_block.copyTo(result_roi, _stream);
|
||||
}
|
||||
}
|
||||
|
||||
syncOutput(result, _result, _stream);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Ptr<Convolution> cv::cuda::createConvolution(Size user_block_size)
|
||||
{
|
||||
#ifndef HAVE_CUFFT
|
||||
CV_UNUSED(user_block_size);
|
||||
CV_Error(Error::StsNotImplemented, "The library was build without CUFFT");
|
||||
return Ptr<Convolution>();
|
||||
#else
|
||||
return makePtr<ConvolutionImpl>(user_block_size);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
@@ -0,0 +1,216 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::cuda::merge(const GpuMat*, size_t, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::merge(const std::vector<GpuMat>&, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::split(InputArray, GpuMat*, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::split(InputArray, std::vector<GpuMat>&, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::transpose(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::flip(InputArray, OutputArray, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::copyMakeBorder(InputArray, OutputArray, int, int, int, int, int, Scalar, Stream&) { throw_no_cuda(); }
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// flip
|
||||
|
||||
namespace
|
||||
{
|
||||
template<int DEPTH> struct NppTypeTraits;
|
||||
template<> struct NppTypeTraits<CV_8U> { typedef Npp8u npp_t; };
|
||||
template<> struct NppTypeTraits<CV_8S> { typedef Npp8s npp_t; };
|
||||
template<> struct NppTypeTraits<CV_16U> { typedef Npp16u npp_t; };
|
||||
template<> struct NppTypeTraits<CV_16S> { typedef Npp16s npp_t; };
|
||||
template<> struct NppTypeTraits<CV_32S> { typedef Npp32s npp_t; };
|
||||
template<> struct NppTypeTraits<CV_32F> { typedef Npp32f npp_t; };
|
||||
template<> struct NppTypeTraits<CV_64F> { typedef Npp64f npp_t; };
|
||||
|
||||
template <int DEPTH> struct NppMirrorFunc
|
||||
{
|
||||
typedef typename NppTypeTraits<DEPTH>::npp_t npp_t;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
typedef NppStatus (*func_t)(const npp_t* pSrc, int nSrcStep, npp_t* pDst, int nDstStep, NppiSize oROI, NppiAxis flip, NppStreamContext ctx);
|
||||
#else
|
||||
typedef NppStatus(*func_t)(const npp_t* pSrc, int nSrcStep, npp_t* pDst, int nDstStep, NppiSize oROI, NppiAxis flip);
|
||||
#endif
|
||||
};
|
||||
|
||||
template <int DEPTH, typename NppMirrorFunc<DEPTH>::func_t func> struct NppMirror
|
||||
{
|
||||
typedef typename NppMirrorFunc<DEPTH>::npp_t npp_t;
|
||||
|
||||
static void call(const GpuMat& src, GpuMat& dst, int flipCode, cudaStream_t stream)
|
||||
{
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = src.cols;
|
||||
sz.height = src.rows;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall( func(src.ptr<npp_t>(), static_cast<int>(src.step),
|
||||
dst.ptr<npp_t>(), static_cast<int>(dst.step), sz,
|
||||
(flipCode == 0 ? NPP_HORIZONTAL_AXIS : (flipCode > 0 ? NPP_VERTICAL_AXIS : NPP_BOTH_AXIS)), h) );
|
||||
#else
|
||||
nppSafeCall( func(src.ptr<npp_t>(), static_cast<int>(src.step),
|
||||
dst.ptr<npp_t>(), static_cast<int>(dst.step), sz,
|
||||
(flipCode == 0 ? NPP_HORIZONTAL_AXIS : (flipCode > 0 ? NPP_VERTICAL_AXIS : NPP_BOTH_AXIS))) );
|
||||
#endif
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
};
|
||||
|
||||
template <int DEPTH> struct NppMirrorIFunc
|
||||
{
|
||||
typedef typename NppTypeTraits<DEPTH>::npp_t npp_t;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
typedef NppStatus (*func_t)(npp_t* pSrcDst, int nSrcDstStep, NppiSize oROI, NppiAxis flip, NppStreamContext ctx);
|
||||
#else
|
||||
typedef NppStatus(*func_t)(npp_t* pSrcDst, int nSrcDstStep, NppiSize oROI, NppiAxis flip);
|
||||
#endif
|
||||
};
|
||||
|
||||
template <int DEPTH, typename NppMirrorIFunc<DEPTH>::func_t func> struct NppMirrorI
|
||||
{
|
||||
typedef typename NppMirrorIFunc<DEPTH>::npp_t npp_t;
|
||||
|
||||
static void call(GpuMat& srcDst, int flipCode, cudaStream_t stream)
|
||||
{
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = srcDst.cols;
|
||||
sz.height = srcDst.rows;
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall(func(srcDst.ptr<npp_t>(), static_cast<int>(srcDst.step),
|
||||
sz,
|
||||
(flipCode == 0 ? NPP_HORIZONTAL_AXIS : (flipCode > 0 ? NPP_VERTICAL_AXIS : NPP_BOTH_AXIS)), h) );
|
||||
#else
|
||||
nppSafeCall( func(srcDst.ptr<npp_t>(), static_cast<int>(srcDst.step),
|
||||
sz,
|
||||
(flipCode == 0 ? NPP_HORIZONTAL_AXIS : (flipCode > 0 ? NPP_VERTICAL_AXIS : NPP_BOTH_AXIS))) );
|
||||
#endif
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void cv::cuda::flip(InputArray _src, OutputArray _dst, int flipCode, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int flipCode, cudaStream_t stream);
|
||||
static const func_t funcs[6][4] =
|
||||
{
|
||||
#if USE_NPP_STREAM_CTX
|
||||
{NppMirror<CV_8U, nppiMirror_8u_C1R_Ctx>::call, 0, NppMirror<CV_8U, nppiMirror_8u_C3R_Ctx>::call, NppMirror<CV_8U, nppiMirror_8u_C4R_Ctx>::call},
|
||||
{0,0,0,0},
|
||||
{NppMirror<CV_16U, nppiMirror_16u_C1R_Ctx>::call, 0, NppMirror<CV_16U, nppiMirror_16u_C3R_Ctx>::call, NppMirror<CV_16U, nppiMirror_16u_C4R_Ctx>::call},
|
||||
{0,0,0,0},
|
||||
{NppMirror<CV_32S, nppiMirror_32s_C1R_Ctx>::call, 0, NppMirror<CV_32S, nppiMirror_32s_C3R_Ctx>::call, NppMirror<CV_32S, nppiMirror_32s_C4R_Ctx>::call},
|
||||
{NppMirror<CV_32F, nppiMirror_32f_C1R_Ctx>::call, 0, NppMirror<CV_32F, nppiMirror_32f_C3R_Ctx>::call, NppMirror<CV_32F, nppiMirror_32f_C4R_Ctx>::call}
|
||||
#else
|
||||
{ NppMirror<CV_8U, nppiMirror_8u_C1R>::call, 0, NppMirror<CV_8U, nppiMirror_8u_C3R>::call, NppMirror<CV_8U, nppiMirror_8u_C4R>::call },
|
||||
{0,0,0,0},
|
||||
{NppMirror<CV_16U, nppiMirror_16u_C1R>::call, 0, NppMirror<CV_16U, nppiMirror_16u_C3R>::call, NppMirror<CV_16U, nppiMirror_16u_C4R>::call},
|
||||
{0,0,0,0},
|
||||
{NppMirror<CV_32S, nppiMirror_32s_C1R>::call, 0, NppMirror<CV_32S, nppiMirror_32s_C3R>::call, NppMirror<CV_32S, nppiMirror_32s_C4R>::call},
|
||||
{NppMirror<CV_32F, nppiMirror_32f_C1R>::call, 0, NppMirror<CV_32F, nppiMirror_32f_C3R>::call, NppMirror<CV_32F, nppiMirror_32f_C4R>::call}
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef void (*ifunc_t)(GpuMat& srcDst, int flipCode, cudaStream_t stream);
|
||||
static const ifunc_t ifuncs[6][4] =
|
||||
{
|
||||
#if USE_NPP_STREAM_CTX
|
||||
{NppMirrorI<CV_8U, nppiMirror_8u_C1IR_Ctx>::call, 0, NppMirrorI<CV_8U, nppiMirror_8u_C3IR_Ctx>::call, NppMirrorI<CV_8U, nppiMirror_8u_C4IR_Ctx>::call},
|
||||
{0,0,0,0},
|
||||
{NppMirrorI<CV_16U, nppiMirror_16u_C1IR_Ctx>::call, 0, NppMirrorI<CV_16U, nppiMirror_16u_C3IR_Ctx>::call, NppMirrorI<CV_16U, nppiMirror_16u_C4IR_Ctx>::call},
|
||||
{0,0,0,0},
|
||||
{NppMirrorI<CV_32S, nppiMirror_32s_C1IR_Ctx>::call, 0, NppMirrorI<CV_32S, nppiMirror_32s_C3IR_Ctx>::call, NppMirrorI<CV_32S, nppiMirror_32s_C4IR_Ctx>::call},
|
||||
{NppMirrorI<CV_32F, nppiMirror_32f_C1IR_Ctx>::call, 0, NppMirrorI<CV_32F, nppiMirror_32f_C3IR_Ctx>::call, NppMirrorI<CV_32F, nppiMirror_32f_C4IR_Ctx>::call}
|
||||
#else
|
||||
{ NppMirrorI<CV_8U, nppiMirror_8u_C1IR>::call, 0, NppMirrorI<CV_8U, nppiMirror_8u_C3IR>::call, NppMirrorI<CV_8U, nppiMirror_8u_C4IR>::call },
|
||||
{0,0,0,0},
|
||||
{NppMirrorI<CV_16U, nppiMirror_16u_C1IR>::call, 0, NppMirrorI<CV_16U, nppiMirror_16u_C3IR>::call, NppMirrorI<CV_16U, nppiMirror_16u_C4IR>::call},
|
||||
{0,0,0,0},
|
||||
{NppMirrorI<CV_32S, nppiMirror_32s_C1IR>::call, 0, NppMirrorI<CV_32S, nppiMirror_32s_C3IR>::call, NppMirrorI<CV_32S, nppiMirror_32s_C4IR>::call},
|
||||
{NppMirrorI<CV_32F, nppiMirror_32f_C1IR>::call, 0, NppMirrorI<CV_32F, nppiMirror_32f_C3IR>::call, NppMirrorI<CV_32F, nppiMirror_32f_C4IR>::call}
|
||||
#endif
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32S || src.depth() == CV_32F);
|
||||
CV_Assert(src.channels() == 1 || src.channels() == 3 || src.channels() == 4);
|
||||
|
||||
_dst.create(src.size(), src.type());
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
bool isInplace = (src.data == dst.data);
|
||||
bool isSizeOdd = (src.cols & 1) == 1 || (src.rows & 1) == 1;
|
||||
if (isInplace && isSizeOdd)
|
||||
CV_Error(Error::BadROISize, "In-place version of flip only accepts even width/height");
|
||||
|
||||
if (isInplace == false)
|
||||
funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream));
|
||||
else // in-place
|
||||
ifuncs[src.depth()][src.channels() - 1](src, flipCode, StreamAccessor::getStream(stream));
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
@@ -0,0 +1,188 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void absDiffMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int);
|
||||
|
||||
namespace
|
||||
{
|
||||
__device__ __forceinline__ int _abs(int a)
|
||||
{
|
||||
return ::abs(a);
|
||||
}
|
||||
__device__ __forceinline__ float _abs(float a)
|
||||
{
|
||||
return ::fabsf(a);
|
||||
}
|
||||
__device__ __forceinline__ double _abs(double a)
|
||||
{
|
||||
return ::fabs(a);
|
||||
}
|
||||
|
||||
template <typename T> struct AbsDiffOp1 : binary_function<T, T, T>
|
||||
{
|
||||
__device__ __forceinline__ T operator ()(T a, T b) const
|
||||
{
|
||||
return saturate_cast<T>(_abs(a - b));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void absDiffMat_v1(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformBinary_< TransformPolicy<T> >(globPtr<T>(src1), globPtr<T>(src2), globPtr<T>(dst), AbsDiffOp1<T>(), stream);
|
||||
}
|
||||
|
||||
struct AbsDiffOp2 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vabsdiff2(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
void absDiffMat_v2(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 1;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, AbsDiffOp2(), stream);
|
||||
}
|
||||
|
||||
struct AbsDiffOp4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vabsdiff4(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
void absDiffMat_v4(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 2;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, AbsDiffOp4(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void absDiffMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX] =
|
||||
{
|
||||
absDiffMat_v1<uchar>,
|
||||
absDiffMat_v1<schar>,
|
||||
absDiffMat_v1<ushort>,
|
||||
absDiffMat_v1<short>,
|
||||
absDiffMat_v1<int>,
|
||||
absDiffMat_v1<float>,
|
||||
absDiffMat_v1<double>
|
||||
};
|
||||
|
||||
const int depth = src1.depth();
|
||||
|
||||
CV_DbgAssert( depth <= CV_64F );
|
||||
|
||||
GpuMat src1_ = src1.reshape(1);
|
||||
GpuMat src2_ = src2.reshape(1);
|
||||
GpuMat dst_ = dst.reshape(1);
|
||||
|
||||
if (depth == CV_8U || depth == CV_16U)
|
||||
{
|
||||
const intptr_t src1ptr = reinterpret_cast<intptr_t>(src1_.data);
|
||||
const intptr_t src2ptr = reinterpret_cast<intptr_t>(src2_.data);
|
||||
const intptr_t dstptr = reinterpret_cast<intptr_t>(dst_.data);
|
||||
|
||||
const bool isAllAligned = (src1ptr & 31) == 0 && (src2ptr & 31) == 0 && (dstptr & 31) == 0;
|
||||
|
||||
if (isAllAligned)
|
||||
{
|
||||
if (depth == CV_8U && (src1_.cols & 3) == 0)
|
||||
{
|
||||
absDiffMat_v4(src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
else if (depth == CV_16U && (src1_.cols & 1) == 0)
|
||||
{
|
||||
absDiffMat_v2(src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const func_t func = funcs[depth];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src1_, src2_, dst_, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,135 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/cuda/cuda_compat.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void absDiffScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int);
|
||||
|
||||
namespace
|
||||
{
|
||||
using cv::cuda::device::compat::double4Compat;
|
||||
template <typename SrcType, typename ScalarType, typename DstType> struct AbsDiffScalarOp : unary_function<SrcType, DstType>
|
||||
{
|
||||
ScalarType val;
|
||||
|
||||
__device__ __forceinline__ DstType operator ()(SrcType a) const
|
||||
{
|
||||
abs_func<ScalarType> f;
|
||||
return saturate_cast<DstType>(f(saturate_cast<ScalarType>(a) - val));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename SrcType, typename ScalarDepth>
|
||||
void absDiffScalarImpl(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<ScalarDepth, VecTraits<SrcType>::cn>::type ScalarType;
|
||||
|
||||
cv::Scalar_<ScalarDepth> value_ = value;
|
||||
|
||||
AbsDiffScalarOp<SrcType, ScalarType, SrcType> op;
|
||||
op.val = VecTraits<ScalarType>::make(value_.val);
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<SrcType>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void absDiffScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, cv::Scalar val, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX][4] =
|
||||
{
|
||||
{
|
||||
absDiffScalarImpl<uchar, float>, absDiffScalarImpl<uchar2, float>, absDiffScalarImpl<uchar3, float>, absDiffScalarImpl<uchar4, float>
|
||||
},
|
||||
{
|
||||
absDiffScalarImpl<schar, float>, absDiffScalarImpl<char2, float>, absDiffScalarImpl<char3, float>, absDiffScalarImpl<char4, float>
|
||||
},
|
||||
{
|
||||
absDiffScalarImpl<ushort, float>, absDiffScalarImpl<ushort2, float>, absDiffScalarImpl<ushort3, float>, absDiffScalarImpl<ushort4, float>
|
||||
},
|
||||
{
|
||||
absDiffScalarImpl<short, float>, absDiffScalarImpl<short2, float>, absDiffScalarImpl<short3, float>, absDiffScalarImpl<short4, float>
|
||||
},
|
||||
{
|
||||
absDiffScalarImpl<int, float>, absDiffScalarImpl<int2, float>, absDiffScalarImpl<int3, float>, absDiffScalarImpl<int4, float>
|
||||
},
|
||||
{
|
||||
absDiffScalarImpl<float, float>, absDiffScalarImpl<float2, float>, absDiffScalarImpl<float3, float>, absDiffScalarImpl<float4, float>
|
||||
},
|
||||
{
|
||||
absDiffScalarImpl<double, double>, absDiffScalarImpl<double2, double>, absDiffScalarImpl<double3, double>, absDiffScalarImpl<double4Compat, double>
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src.depth();
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_DbgAssert( sdepth <= CV_64F && cn <= 4 && src.type() == dst.type());
|
||||
|
||||
const func_t func = funcs[sdepth][cn - 1];
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src, val, dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,225 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void addMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& _stream, int);
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename D> struct AddOp1 : binary_function<T, T, D>
|
||||
{
|
||||
__device__ __forceinline__ D operator ()(T a, T b) const
|
||||
{
|
||||
return saturate_cast<D>(a + b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename D>
|
||||
void addMat_v1(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
if (mask.data)
|
||||
gridTransformBinary(globPtr<T>(src1), globPtr<T>(src2), globPtr<D>(dst), AddOp1<T, D>(), globPtr<uchar>(mask), stream);
|
||||
else
|
||||
gridTransformBinary(globPtr<T>(src1), globPtr<T>(src2), globPtr<D>(dst), AddOp1<T, D>(), stream);
|
||||
}
|
||||
|
||||
struct AddOp2 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vadd2(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
void addMat_v2(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 1;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, AddOp2(), stream);
|
||||
}
|
||||
|
||||
struct AddOp4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vadd4(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
void addMat_v4(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 2;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, AddOp4(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void addMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, Stream& stream);
|
||||
static const func_t funcs[7][7] =
|
||||
{
|
||||
{
|
||||
addMat_v1<uchar, uchar>,
|
||||
addMat_v1<uchar, schar>,
|
||||
addMat_v1<uchar, ushort>,
|
||||
addMat_v1<uchar, short>,
|
||||
addMat_v1<uchar, int>,
|
||||
addMat_v1<uchar, float>,
|
||||
addMat_v1<uchar, double>
|
||||
},
|
||||
{
|
||||
addMat_v1<schar, uchar>,
|
||||
addMat_v1<schar, schar>,
|
||||
addMat_v1<schar, ushort>,
|
||||
addMat_v1<schar, short>,
|
||||
addMat_v1<schar, int>,
|
||||
addMat_v1<schar, float>,
|
||||
addMat_v1<schar, double>
|
||||
},
|
||||
{
|
||||
0 /*addMat_v1<ushort, uchar>*/,
|
||||
0 /*addMat_v1<ushort, schar>*/,
|
||||
addMat_v1<ushort, ushort>,
|
||||
addMat_v1<ushort, short>,
|
||||
addMat_v1<ushort, int>,
|
||||
addMat_v1<ushort, float>,
|
||||
addMat_v1<ushort, double>
|
||||
},
|
||||
{
|
||||
0 /*addMat_v1<short, uchar>*/,
|
||||
0 /*addMat_v1<short, schar>*/,
|
||||
addMat_v1<short, ushort>,
|
||||
addMat_v1<short, short>,
|
||||
addMat_v1<short, int>,
|
||||
addMat_v1<short, float>,
|
||||
addMat_v1<short, double>
|
||||
},
|
||||
{
|
||||
0 /*addMat_v1<int, uchar>*/,
|
||||
0 /*addMat_v1<int, schar>*/,
|
||||
0 /*addMat_v1<int, ushort>*/,
|
||||
0 /*addMat_v1<int, short>*/,
|
||||
addMat_v1<int, int>,
|
||||
addMat_v1<int, float>,
|
||||
addMat_v1<int, double>
|
||||
},
|
||||
{
|
||||
0 /*addMat_v1<float, uchar>*/,
|
||||
0 /*addMat_v1<float, schar>*/,
|
||||
0 /*addMat_v1<float, ushort>*/,
|
||||
0 /*addMat_v1<float, short>*/,
|
||||
0 /*addMat_v1<float, int>*/,
|
||||
addMat_v1<float, float>,
|
||||
addMat_v1<float, double>
|
||||
},
|
||||
{
|
||||
0 /*addMat_v1<double, uchar>*/,
|
||||
0 /*addMat_v1<double, schar>*/,
|
||||
0 /*addMat_v1<double, ushort>*/,
|
||||
0 /*addMat_v1<double, short>*/,
|
||||
0 /*addMat_v1<double, int>*/,
|
||||
0 /*addMat_v1<double, float>*/,
|
||||
addMat_v1<double, double>
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src1.depth();
|
||||
const int ddepth = dst.depth();
|
||||
|
||||
CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F );
|
||||
|
||||
GpuMat src1_ = src1.reshape(1);
|
||||
GpuMat src2_ = src2.reshape(1);
|
||||
GpuMat dst_ = dst.reshape(1);
|
||||
|
||||
if (mask.empty() && (sdepth == CV_8U || sdepth == CV_16U) && ddepth == sdepth)
|
||||
{
|
||||
const intptr_t src1ptr = reinterpret_cast<intptr_t>(src1_.data);
|
||||
const intptr_t src2ptr = reinterpret_cast<intptr_t>(src2_.data);
|
||||
const intptr_t dstptr = reinterpret_cast<intptr_t>(dst_.data);
|
||||
|
||||
const bool isAllAligned = (src1ptr & 31) == 0 && (src2ptr & 31) == 0 && (dstptr & 31) == 0;
|
||||
|
||||
if (isAllAligned)
|
||||
{
|
||||
if (sdepth == CV_8U && (src1_.cols & 3) == 0)
|
||||
{
|
||||
addMat_v4(src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
else if (sdepth == CV_16U && (src1_.cols & 1) == 0)
|
||||
{
|
||||
addMat_v2(src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const func_t func = funcs[sdepth][ddepth];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src1_, src2_, dst_, mask, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,182 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/cuda/cuda_compat.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void addScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int);
|
||||
|
||||
namespace
|
||||
{
|
||||
using cv::cuda::device::compat::double4Compat;
|
||||
template <typename SrcType, typename ScalarType, typename DstType> struct AddScalarOp : unary_function<SrcType, DstType>
|
||||
{
|
||||
ScalarType val;
|
||||
|
||||
__device__ __forceinline__ DstType operator ()(SrcType a) const
|
||||
{
|
||||
return saturate_cast<DstType>(saturate_cast<ScalarType>(a) + val);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename SrcType, typename ScalarDepth, typename DstType>
|
||||
void addScalarImpl(const GpuMat& src, cv::Scalar value, GpuMat& dst, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<ScalarDepth, VecTraits<SrcType>::cn>::type ScalarType;
|
||||
|
||||
cv::Scalar_<ScalarDepth> value_ = value;
|
||||
|
||||
AddScalarOp<SrcType, ScalarType, DstType> op;
|
||||
op.val = VecTraits<ScalarType>::make(value_.val);
|
||||
|
||||
if (mask.data)
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, globPtr<uchar>(mask), stream);
|
||||
else
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void addScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, cv::Scalar val, GpuMat& dst, const GpuMat& mask, Stream& stream);
|
||||
static const func_t funcs[7][7][4] =
|
||||
{
|
||||
{
|
||||
{addScalarImpl<uchar, float, uchar>, addScalarImpl<uchar2, float, uchar2>, addScalarImpl<uchar3, float, uchar3>, addScalarImpl<uchar4, float, uchar4>},
|
||||
{addScalarImpl<uchar, float, schar>, addScalarImpl<uchar2, float, char2>, addScalarImpl<uchar3, float, char3>, addScalarImpl<uchar4, float, char4>},
|
||||
{addScalarImpl<uchar, float, ushort>, addScalarImpl<uchar2, float, ushort2>, addScalarImpl<uchar3, float, ushort3>, addScalarImpl<uchar4, float, ushort4>},
|
||||
{addScalarImpl<uchar, float, short>, addScalarImpl<uchar2, float, short2>, addScalarImpl<uchar3, float, short3>, addScalarImpl<uchar4, float, short4>},
|
||||
{addScalarImpl<uchar, float, int>, addScalarImpl<uchar2, float, int2>, addScalarImpl<uchar3, float, int3>, addScalarImpl<uchar4, float, int4>},
|
||||
{addScalarImpl<uchar, float, float>, addScalarImpl<uchar2, float, float2>, addScalarImpl<uchar3, float, float3>, addScalarImpl<uchar4, float, float4>},
|
||||
{addScalarImpl<uchar, double, double>, addScalarImpl<uchar2, double, double2>, addScalarImpl<uchar3, double, double3>, addScalarImpl<uchar4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{addScalarImpl<schar, float, uchar>, addScalarImpl<char2, float, uchar2>, addScalarImpl<char3, float, uchar3>, addScalarImpl<char4, float, uchar4>},
|
||||
{addScalarImpl<schar, float, schar>, addScalarImpl<char2, float, char2>, addScalarImpl<char3, float, char3>, addScalarImpl<char4, float, char4>},
|
||||
{addScalarImpl<schar, float, ushort>, addScalarImpl<char2, float, ushort2>, addScalarImpl<char3, float, ushort3>, addScalarImpl<char4, float, ushort4>},
|
||||
{addScalarImpl<schar, float, short>, addScalarImpl<char2, float, short2>, addScalarImpl<char3, float, short3>, addScalarImpl<char4, float, short4>},
|
||||
{addScalarImpl<schar, float, int>, addScalarImpl<char2, float, int2>, addScalarImpl<char3, float, int3>, addScalarImpl<char4, float, int4>},
|
||||
{addScalarImpl<schar, float, float>, addScalarImpl<char2, float, float2>, addScalarImpl<char3, float, float3>, addScalarImpl<char4, float, float4>},
|
||||
{addScalarImpl<schar, double, double>, addScalarImpl<char2, double, double2>, addScalarImpl<char3, double, double3>, addScalarImpl<char4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*addScalarImpl<ushort, float, uchar>*/, 0 /*addScalarImpl<ushort2, float, uchar2>*/, 0 /*addScalarImpl<ushort3, float, uchar3>*/, 0 /*addScalarImpl<ushort4, float, uchar4>*/},
|
||||
{0 /*addScalarImpl<ushort, float, schar>*/, 0 /*addScalarImpl<ushort2, float, char2>*/, 0 /*addScalarImpl<ushort3, float, char3>*/, 0 /*addScalarImpl<ushort4, float, char4>*/},
|
||||
{addScalarImpl<ushort, float, ushort>, addScalarImpl<ushort2, float, ushort2>, addScalarImpl<ushort3, float, ushort3>, addScalarImpl<ushort4, float, ushort4>},
|
||||
{addScalarImpl<ushort, float, short>, addScalarImpl<ushort2, float, short2>, addScalarImpl<ushort3, float, short3>, addScalarImpl<ushort4, float, short4>},
|
||||
{addScalarImpl<ushort, float, int>, addScalarImpl<ushort2, float, int2>, addScalarImpl<ushort3, float, int3>, addScalarImpl<ushort4, float, int4>},
|
||||
{addScalarImpl<ushort, float, float>, addScalarImpl<ushort2, float, float2>, addScalarImpl<ushort3, float, float3>, addScalarImpl<ushort4, float, float4>},
|
||||
{addScalarImpl<ushort, double, double>, addScalarImpl<ushort2, double, double2>, addScalarImpl<ushort3, double, double3>, addScalarImpl<ushort4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*addScalarImpl<short, float, uchar>*/, 0 /*addScalarImpl<short2, float, uchar2>*/, 0 /*addScalarImpl<short3, float, uchar3>*/, 0 /*addScalarImpl<short4, float, uchar4>*/},
|
||||
{0 /*addScalarImpl<short, float, schar>*/, 0 /*addScalarImpl<short2, float, char2>*/, 0 /*addScalarImpl<short3, float, char3>*/, 0 /*addScalarImpl<short4, float, char4>*/},
|
||||
{addScalarImpl<short, float, ushort>, addScalarImpl<short2, float, ushort2>, addScalarImpl<short3, float, ushort3>, addScalarImpl<short4, float, ushort4>},
|
||||
{addScalarImpl<short, float, short>, addScalarImpl<short2, float, short2>, addScalarImpl<short3, float, short3>, addScalarImpl<short4, float, short4>},
|
||||
{addScalarImpl<short, float, int>, addScalarImpl<short2, float, int2>, addScalarImpl<short3, float, int3>, addScalarImpl<short4, float, int4>},
|
||||
{addScalarImpl<short, float, float>, addScalarImpl<short2, float, float2>, addScalarImpl<short3, float, float3>, addScalarImpl<short4, float, float4>},
|
||||
{addScalarImpl<short, double, double>, addScalarImpl<short2, double, double2>, addScalarImpl<short3, double, double3>, addScalarImpl<short4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*addScalarImpl<int, float, uchar>*/, 0 /*addScalarImpl<int2, float, uchar2>*/, 0 /*addScalarImpl<int3, float, uchar3>*/, 0 /*addScalarImpl<int4, float, uchar4>*/},
|
||||
{0 /*addScalarImpl<int, float, schar>*/, 0 /*addScalarImpl<int2, float, char2>*/, 0 /*addScalarImpl<int3, float, char3>*/, 0 /*addScalarImpl<int4, float, char4>*/},
|
||||
{0 /*addScalarImpl<int, float, ushort>*/, 0 /*addScalarImpl<int2, float, ushort2>*/, 0 /*addScalarImpl<int3, float, ushort3>*/, 0 /*addScalarImpl<int4, float, ushort4>*/},
|
||||
{0 /*addScalarImpl<int, float, short>*/, 0 /*addScalarImpl<int2, float, short2>*/, 0 /*addScalarImpl<int3, float, short3>*/, 0 /*addScalarImpl<int4, float, short4>*/},
|
||||
{addScalarImpl<int, float, int>, addScalarImpl<int2, float, int2>, addScalarImpl<int3, float, int3>, addScalarImpl<int4, float, int4>},
|
||||
{addScalarImpl<int, float, float>, addScalarImpl<int2, float, float2>, addScalarImpl<int3, float, float3>, addScalarImpl<int4, float, float4>},
|
||||
{addScalarImpl<int, double, double>, addScalarImpl<int2, double, double2>, addScalarImpl<int3, double, double3>, addScalarImpl<int4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*addScalarImpl<float, float, uchar>*/, 0 /*addScalarImpl<float2, float, uchar2>*/, 0 /*addScalarImpl<float3, float, uchar3>*/, 0 /*addScalarImpl<float4, float, uchar4>*/},
|
||||
{0 /*addScalarImpl<float, float, schar>*/, 0 /*addScalarImpl<float2, float, char2>*/, 0 /*addScalarImpl<float3, float, char3>*/, 0 /*addScalarImpl<float4, float, char4>*/},
|
||||
{0 /*addScalarImpl<float, float, ushort>*/, 0 /*addScalarImpl<float2, float, ushort2>*/, 0 /*addScalarImpl<float3, float, ushort3>*/, 0 /*addScalarImpl<float4, float, ushort4>*/},
|
||||
{0 /*addScalarImpl<float, float, short>*/, 0 /*addScalarImpl<float2, float, short2>*/, 0 /*addScalarImpl<float3, float, short3>*/, 0 /*addScalarImpl<float4, float, short4>*/},
|
||||
{0 /*addScalarImpl<float, float, int>*/, 0 /*addScalarImpl<float2, float, int2>*/, 0 /*addScalarImpl<float3, float, int3>*/, 0 /*addScalarImpl<float4, float, int4>*/},
|
||||
{addScalarImpl<float, float, float>, addScalarImpl<float2, float, float2>, addScalarImpl<float3, float, float3>, addScalarImpl<float4, float, float4>},
|
||||
{addScalarImpl<float, double, double>, addScalarImpl<float2, double, double2>, addScalarImpl<float3, double, double3>, addScalarImpl<float4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*addScalarImpl<double, double, uchar>*/, 0 /*addScalarImpl<double2, double, uchar2>*/, 0 /*addScalarImpl<double3, double, uchar3>*/, 0 /*addScalarImpl<double4, double, uchar4>*/},
|
||||
{0 /*addScalarImpl<double, double, schar>*/, 0 /*addScalarImpl<double2, double, char2>*/, 0 /*addScalarImpl<double3, double, char3>*/, 0 /*addScalarImpl<double4, double, char4>*/},
|
||||
{0 /*addScalarImpl<double, double, ushort>*/, 0 /*addScalarImpl<double2, double, ushort2>*/, 0 /*addScalarImpl<double3, double, ushort3>*/, 0 /*addScalarImpl<double4, double, ushort4>*/},
|
||||
{0 /*addScalarImpl<double, double, short>*/, 0 /*addScalarImpl<double2, double, short2>*/, 0 /*addScalarImpl<double3, double, short3>*/, 0 /*addScalarImpl<double4, double, short4>*/},
|
||||
{0 /*addScalarImpl<double, double, int>*/, 0 /*addScalarImpl<double2, double, int2>*/, 0 /*addScalarImpl<double3, double, int3>*/, 0 /*addScalarImpl<double4, double, int4>*/},
|
||||
{0 /*addScalarImpl<double, double, float>*/, 0 /*addScalarImpl<double2, double, float2>*/, 0 /*addScalarImpl<double3, double, float3>*/, 0 /*addScalarImpl<double4, double, float4>*/},
|
||||
{addScalarImpl<double, double, double>, addScalarImpl<double2, double, double2>, addScalarImpl<double3, double, double3>, addScalarImpl<double4Compat, double, double4Compat>}
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src.depth();
|
||||
const int ddepth = dst.depth();
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F && cn <= 4 );
|
||||
|
||||
const func_t func = funcs[sdepth][ddepth][cn - 1];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src, val, dst, mask, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,596 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T1, typename T2, typename D, typename S> struct AddWeightedOp : binary_function<T1, T2, D>
|
||||
{
|
||||
S alpha;
|
||||
S beta;
|
||||
S gamma;
|
||||
|
||||
__device__ __forceinline__ D operator ()(T1 a, T2 b) const
|
||||
{
|
||||
return cudev::saturate_cast<D>(a * alpha + b * beta + gamma);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T1, typename T2, typename D>
|
||||
void addWeightedImpl(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
typedef typename LargerType<T1, T2>::type larger_type1;
|
||||
typedef typename LargerType<larger_type1, D>::type larger_type2;
|
||||
typedef typename LargerType<larger_type2, float>::type scalar_type;
|
||||
|
||||
AddWeightedOp<T1, T2, D, scalar_type> op;
|
||||
op.alpha = static_cast<scalar_type>(alpha);
|
||||
op.beta = static_cast<scalar_type>(beta);
|
||||
op.gamma = static_cast<scalar_type>(gamma);
|
||||
|
||||
gridTransformBinary_< TransformPolicy<scalar_type> >(globPtr<T1>(src1), globPtr<T2>(src2), globPtr<D>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::addWeighted(InputArray _src1, double alpha, InputArray _src2, double beta, double gamma, OutputArray _dst, int ddepth, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[7][7][7] =
|
||||
{
|
||||
{
|
||||
{
|
||||
addWeightedImpl<uchar, uchar, uchar >,
|
||||
addWeightedImpl<uchar, uchar, schar >,
|
||||
addWeightedImpl<uchar, uchar, ushort>,
|
||||
addWeightedImpl<uchar, uchar, short >,
|
||||
addWeightedImpl<uchar, uchar, int >,
|
||||
addWeightedImpl<uchar, uchar, float >,
|
||||
addWeightedImpl<uchar, uchar, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<uchar, schar, uchar >,
|
||||
addWeightedImpl<uchar, schar, schar >,
|
||||
addWeightedImpl<uchar, schar, ushort>,
|
||||
addWeightedImpl<uchar, schar, short >,
|
||||
addWeightedImpl<uchar, schar, int >,
|
||||
addWeightedImpl<uchar, schar, float >,
|
||||
addWeightedImpl<uchar, schar, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<uchar, ushort, uchar >,
|
||||
addWeightedImpl<uchar, ushort, schar >,
|
||||
addWeightedImpl<uchar, ushort, ushort>,
|
||||
addWeightedImpl<uchar, ushort, short >,
|
||||
addWeightedImpl<uchar, ushort, int >,
|
||||
addWeightedImpl<uchar, ushort, float >,
|
||||
addWeightedImpl<uchar, ushort, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<uchar, short, uchar >,
|
||||
addWeightedImpl<uchar, short, schar >,
|
||||
addWeightedImpl<uchar, short, ushort>,
|
||||
addWeightedImpl<uchar, short, short >,
|
||||
addWeightedImpl<uchar, short, int >,
|
||||
addWeightedImpl<uchar, short, float >,
|
||||
addWeightedImpl<uchar, short, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<uchar, int, uchar >,
|
||||
addWeightedImpl<uchar, int, schar >,
|
||||
addWeightedImpl<uchar, int, ushort>,
|
||||
addWeightedImpl<uchar, int, short >,
|
||||
addWeightedImpl<uchar, int, int >,
|
||||
addWeightedImpl<uchar, int, float >,
|
||||
addWeightedImpl<uchar, int, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<uchar, float, uchar >,
|
||||
addWeightedImpl<uchar, float, schar >,
|
||||
addWeightedImpl<uchar, float, ushort>,
|
||||
addWeightedImpl<uchar, float, short >,
|
||||
addWeightedImpl<uchar, float, int >,
|
||||
addWeightedImpl<uchar, float, float >,
|
||||
addWeightedImpl<uchar, float, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<uchar, double, uchar >,
|
||||
addWeightedImpl<uchar, double, schar >,
|
||||
addWeightedImpl<uchar, double, ushort>,
|
||||
addWeightedImpl<uchar, double, short >,
|
||||
addWeightedImpl<uchar, double, int >,
|
||||
addWeightedImpl<uchar, double, float >,
|
||||
addWeightedImpl<uchar, double, double>
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
0/*addWeightedImpl<schar, uchar, uchar >*/,
|
||||
0/*addWeightedImpl<schar, uchar, schar >*/,
|
||||
0/*addWeightedImpl<schar, uchar, ushort>*/,
|
||||
0/*addWeightedImpl<schar, uchar, short >*/,
|
||||
0/*addWeightedImpl<schar, uchar, int >*/,
|
||||
0/*addWeightedImpl<schar, uchar, float >*/,
|
||||
0/*addWeightedImpl<schar, uchar, double>*/
|
||||
},
|
||||
{
|
||||
addWeightedImpl<schar, schar, uchar >,
|
||||
addWeightedImpl<schar, schar, schar >,
|
||||
addWeightedImpl<schar, schar, ushort>,
|
||||
addWeightedImpl<schar, schar, short >,
|
||||
addWeightedImpl<schar, schar, int >,
|
||||
addWeightedImpl<schar, schar, float >,
|
||||
addWeightedImpl<schar, schar, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<schar, ushort, uchar >,
|
||||
addWeightedImpl<schar, ushort, schar >,
|
||||
addWeightedImpl<schar, ushort, ushort>,
|
||||
addWeightedImpl<schar, ushort, short >,
|
||||
addWeightedImpl<schar, ushort, int >,
|
||||
addWeightedImpl<schar, ushort, float >,
|
||||
addWeightedImpl<schar, ushort, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<schar, short, uchar >,
|
||||
addWeightedImpl<schar, short, schar >,
|
||||
addWeightedImpl<schar, short, ushort>,
|
||||
addWeightedImpl<schar, short, short >,
|
||||
addWeightedImpl<schar, short, int >,
|
||||
addWeightedImpl<schar, short, float >,
|
||||
addWeightedImpl<schar, short, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<schar, int, uchar >,
|
||||
addWeightedImpl<schar, int, schar >,
|
||||
addWeightedImpl<schar, int, ushort>,
|
||||
addWeightedImpl<schar, int, short >,
|
||||
addWeightedImpl<schar, int, int >,
|
||||
addWeightedImpl<schar, int, float >,
|
||||
addWeightedImpl<schar, int, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<schar, float, uchar >,
|
||||
addWeightedImpl<schar, float, schar >,
|
||||
addWeightedImpl<schar, float, ushort>,
|
||||
addWeightedImpl<schar, float, short >,
|
||||
addWeightedImpl<schar, float, int >,
|
||||
addWeightedImpl<schar, float, float >,
|
||||
addWeightedImpl<schar, float, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<schar, double, uchar >,
|
||||
addWeightedImpl<schar, double, schar >,
|
||||
addWeightedImpl<schar, double, ushort>,
|
||||
addWeightedImpl<schar, double, short >,
|
||||
addWeightedImpl<schar, double, int >,
|
||||
addWeightedImpl<schar, double, float >,
|
||||
addWeightedImpl<schar, double, double>
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
0/*addWeightedImpl<ushort, uchar, uchar >*/,
|
||||
0/*addWeightedImpl<ushort, uchar, schar >*/,
|
||||
0/*addWeightedImpl<ushort, uchar, ushort>*/,
|
||||
0/*addWeightedImpl<ushort, uchar, short >*/,
|
||||
0/*addWeightedImpl<ushort, uchar, int >*/,
|
||||
0/*addWeightedImpl<ushort, uchar, float >*/,
|
||||
0/*addWeightedImpl<ushort, uchar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<ushort, schar, uchar >*/,
|
||||
0/*addWeightedImpl<ushort, schar, schar >*/,
|
||||
0/*addWeightedImpl<ushort, schar, ushort>*/,
|
||||
0/*addWeightedImpl<ushort, schar, short >*/,
|
||||
0/*addWeightedImpl<ushort, schar, int >*/,
|
||||
0/*addWeightedImpl<ushort, schar, float >*/,
|
||||
0/*addWeightedImpl<ushort, schar, double>*/
|
||||
},
|
||||
{
|
||||
addWeightedImpl<ushort, ushort, uchar >,
|
||||
addWeightedImpl<ushort, ushort, schar >,
|
||||
addWeightedImpl<ushort, ushort, ushort>,
|
||||
addWeightedImpl<ushort, ushort, short >,
|
||||
addWeightedImpl<ushort, ushort, int >,
|
||||
addWeightedImpl<ushort, ushort, float >,
|
||||
addWeightedImpl<ushort, ushort, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<ushort, short, uchar >,
|
||||
addWeightedImpl<ushort, short, schar >,
|
||||
addWeightedImpl<ushort, short, ushort>,
|
||||
addWeightedImpl<ushort, short, short >,
|
||||
addWeightedImpl<ushort, short, int >,
|
||||
addWeightedImpl<ushort, short, float >,
|
||||
addWeightedImpl<ushort, short, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<ushort, int, uchar >,
|
||||
addWeightedImpl<ushort, int, schar >,
|
||||
addWeightedImpl<ushort, int, ushort>,
|
||||
addWeightedImpl<ushort, int, short >,
|
||||
addWeightedImpl<ushort, int, int >,
|
||||
addWeightedImpl<ushort, int, float >,
|
||||
addWeightedImpl<ushort, int, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<ushort, float, uchar >,
|
||||
addWeightedImpl<ushort, float, schar >,
|
||||
addWeightedImpl<ushort, float, ushort>,
|
||||
addWeightedImpl<ushort, float, short >,
|
||||
addWeightedImpl<ushort, float, int >,
|
||||
addWeightedImpl<ushort, float, float >,
|
||||
addWeightedImpl<ushort, float, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<ushort, double, uchar >,
|
||||
addWeightedImpl<ushort, double, schar >,
|
||||
addWeightedImpl<ushort, double, ushort>,
|
||||
addWeightedImpl<ushort, double, short >,
|
||||
addWeightedImpl<ushort, double, int >,
|
||||
addWeightedImpl<ushort, double, float >,
|
||||
addWeightedImpl<ushort, double, double>
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
0/*addWeightedImpl<short, uchar, uchar >*/,
|
||||
0/*addWeightedImpl<short, uchar, schar >*/,
|
||||
0/*addWeightedImpl<short, uchar, ushort>*/,
|
||||
0/*addWeightedImpl<short, uchar, short >*/,
|
||||
0/*addWeightedImpl<short, uchar, int >*/,
|
||||
0/*addWeightedImpl<short, uchar, float >*/,
|
||||
0/*addWeightedImpl<short, uchar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<short, schar, uchar >*/,
|
||||
0/*addWeightedImpl<short, schar, schar >*/,
|
||||
0/*addWeightedImpl<short, schar, ushort>*/,
|
||||
0/*addWeightedImpl<short, schar, short >*/,
|
||||
0/*addWeightedImpl<short, schar, int >*/,
|
||||
0/*addWeightedImpl<short, schar, float >*/,
|
||||
0/*addWeightedImpl<short, schar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<short, ushort, uchar >*/,
|
||||
0/*addWeightedImpl<short, ushort, schar >*/,
|
||||
0/*addWeightedImpl<short, ushort, ushort>*/,
|
||||
0/*addWeightedImpl<short, ushort, short >*/,
|
||||
0/*addWeightedImpl<short, ushort, int >*/,
|
||||
0/*addWeightedImpl<short, ushort, float >*/,
|
||||
0/*addWeightedImpl<short, ushort, double>*/
|
||||
},
|
||||
{
|
||||
addWeightedImpl<short, short, uchar >,
|
||||
addWeightedImpl<short, short, schar >,
|
||||
addWeightedImpl<short, short, ushort>,
|
||||
addWeightedImpl<short, short, short >,
|
||||
addWeightedImpl<short, short, int >,
|
||||
addWeightedImpl<short, short, float >,
|
||||
addWeightedImpl<short, short, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<short, int, uchar >,
|
||||
addWeightedImpl<short, int, schar >,
|
||||
addWeightedImpl<short, int, ushort>,
|
||||
addWeightedImpl<short, int, short >,
|
||||
addWeightedImpl<short, int, int >,
|
||||
addWeightedImpl<short, int, float >,
|
||||
addWeightedImpl<short, int, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<short, float, uchar >,
|
||||
addWeightedImpl<short, float, schar >,
|
||||
addWeightedImpl<short, float, ushort>,
|
||||
addWeightedImpl<short, float, short >,
|
||||
addWeightedImpl<short, float, int >,
|
||||
addWeightedImpl<short, float, float >,
|
||||
addWeightedImpl<short, float, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<short, double, uchar >,
|
||||
addWeightedImpl<short, double, schar >,
|
||||
addWeightedImpl<short, double, ushort>,
|
||||
addWeightedImpl<short, double, short >,
|
||||
addWeightedImpl<short, double, int >,
|
||||
addWeightedImpl<short, double, float >,
|
||||
addWeightedImpl<short, double, double>
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
0/*addWeightedImpl<int, uchar, uchar >*/,
|
||||
0/*addWeightedImpl<int, uchar, schar >*/,
|
||||
0/*addWeightedImpl<int, uchar, ushort>*/,
|
||||
0/*addWeightedImpl<int, uchar, short >*/,
|
||||
0/*addWeightedImpl<int, uchar, int >*/,
|
||||
0/*addWeightedImpl<int, uchar, float >*/,
|
||||
0/*addWeightedImpl<int, uchar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<int, schar, uchar >*/,
|
||||
0/*addWeightedImpl<int, schar, schar >*/,
|
||||
0/*addWeightedImpl<int, schar, ushort>*/,
|
||||
0/*addWeightedImpl<int, schar, short >*/,
|
||||
0/*addWeightedImpl<int, schar, int >*/,
|
||||
0/*addWeightedImpl<int, schar, float >*/,
|
||||
0/*addWeightedImpl<int, schar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<int, ushort, uchar >*/,
|
||||
0/*addWeightedImpl<int, ushort, schar >*/,
|
||||
0/*addWeightedImpl<int, ushort, ushort>*/,
|
||||
0/*addWeightedImpl<int, ushort, short >*/,
|
||||
0/*addWeightedImpl<int, ushort, int >*/,
|
||||
0/*addWeightedImpl<int, ushort, float >*/,
|
||||
0/*addWeightedImpl<int, ushort, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<int, short, uchar >*/,
|
||||
0/*addWeightedImpl<int, short, schar >*/,
|
||||
0/*addWeightedImpl<int, short, ushort>*/,
|
||||
0/*addWeightedImpl<int, short, short >*/,
|
||||
0/*addWeightedImpl<int, short, int >*/,
|
||||
0/*addWeightedImpl<int, short, float >*/,
|
||||
0/*addWeightedImpl<int, short, double>*/
|
||||
},
|
||||
{
|
||||
addWeightedImpl<int, int, uchar >,
|
||||
addWeightedImpl<int, int, schar >,
|
||||
addWeightedImpl<int, int, ushort>,
|
||||
addWeightedImpl<int, int, short >,
|
||||
addWeightedImpl<int, int, int >,
|
||||
addWeightedImpl<int, int, float >,
|
||||
addWeightedImpl<int, int, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<int, float, uchar >,
|
||||
addWeightedImpl<int, float, schar >,
|
||||
addWeightedImpl<int, float, ushort>,
|
||||
addWeightedImpl<int, float, short >,
|
||||
addWeightedImpl<int, float, int >,
|
||||
addWeightedImpl<int, float, float >,
|
||||
addWeightedImpl<int, float, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<int, double, uchar >,
|
||||
addWeightedImpl<int, double, schar >,
|
||||
addWeightedImpl<int, double, ushort>,
|
||||
addWeightedImpl<int, double, short >,
|
||||
addWeightedImpl<int, double, int >,
|
||||
addWeightedImpl<int, double, float >,
|
||||
addWeightedImpl<int, double, double>
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
0/*addWeightedImpl<float, uchar, uchar >*/,
|
||||
0/*addWeightedImpl<float, uchar, schar >*/,
|
||||
0/*addWeightedImpl<float, uchar, ushort>*/,
|
||||
0/*addWeightedImpl<float, uchar, short >*/,
|
||||
0/*addWeightedImpl<float, uchar, int >*/,
|
||||
0/*addWeightedImpl<float, uchar, float >*/,
|
||||
0/*addWeightedImpl<float, uchar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<float, schar, uchar >*/,
|
||||
0/*addWeightedImpl<float, schar, schar >*/,
|
||||
0/*addWeightedImpl<float, schar, ushort>*/,
|
||||
0/*addWeightedImpl<float, schar, short >*/,
|
||||
0/*addWeightedImpl<float, schar, int >*/,
|
||||
0/*addWeightedImpl<float, schar, float >*/,
|
||||
0/*addWeightedImpl<float, schar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<float, ushort, uchar >*/,
|
||||
0/*addWeightedImpl<float, ushort, schar >*/,
|
||||
0/*addWeightedImpl<float, ushort, ushort>*/,
|
||||
0/*addWeightedImpl<float, ushort, short >*/,
|
||||
0/*addWeightedImpl<float, ushort, int >*/,
|
||||
0/*addWeightedImpl<float, ushort, float >*/,
|
||||
0/*addWeightedImpl<float, ushort, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<float, short, uchar >*/,
|
||||
0/*addWeightedImpl<float, short, schar >*/,
|
||||
0/*addWeightedImpl<float, short, ushort>*/,
|
||||
0/*addWeightedImpl<float, short, short >*/,
|
||||
0/*addWeightedImpl<float, short, int >*/,
|
||||
0/*addWeightedImpl<float, short, float >*/,
|
||||
0/*addWeightedImpl<float, short, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<float, int, uchar >*/,
|
||||
0/*addWeightedImpl<float, int, schar >*/,
|
||||
0/*addWeightedImpl<float, int, ushort>*/,
|
||||
0/*addWeightedImpl<float, int, short >*/,
|
||||
0/*addWeightedImpl<float, int, int >*/,
|
||||
0/*addWeightedImpl<float, int, float >*/,
|
||||
0/*addWeightedImpl<float, int, double>*/
|
||||
},
|
||||
{
|
||||
addWeightedImpl<float, float, uchar >,
|
||||
addWeightedImpl<float, float, schar >,
|
||||
addWeightedImpl<float, float, ushort>,
|
||||
addWeightedImpl<float, float, short >,
|
||||
addWeightedImpl<float, float, int >,
|
||||
addWeightedImpl<float, float, float >,
|
||||
addWeightedImpl<float, float, double>
|
||||
},
|
||||
{
|
||||
addWeightedImpl<float, double, uchar >,
|
||||
addWeightedImpl<float, double, schar >,
|
||||
addWeightedImpl<float, double, ushort>,
|
||||
addWeightedImpl<float, double, short >,
|
||||
addWeightedImpl<float, double, int >,
|
||||
addWeightedImpl<float, double, float >,
|
||||
addWeightedImpl<float, double, double>
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
0/*addWeightedImpl<double, uchar, uchar >*/,
|
||||
0/*addWeightedImpl<double, uchar, schar >*/,
|
||||
0/*addWeightedImpl<double, uchar, ushort>*/,
|
||||
0/*addWeightedImpl<double, uchar, short >*/,
|
||||
0/*addWeightedImpl<double, uchar, int >*/,
|
||||
0/*addWeightedImpl<double, uchar, float >*/,
|
||||
0/*addWeightedImpl<double, uchar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<double, schar, uchar >*/,
|
||||
0/*addWeightedImpl<double, schar, schar >*/,
|
||||
0/*addWeightedImpl<double, schar, ushort>*/,
|
||||
0/*addWeightedImpl<double, schar, short >*/,
|
||||
0/*addWeightedImpl<double, schar, int >*/,
|
||||
0/*addWeightedImpl<double, schar, float >*/,
|
||||
0/*addWeightedImpl<double, schar, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<double, ushort, uchar >*/,
|
||||
0/*addWeightedImpl<double, ushort, schar >*/,
|
||||
0/*addWeightedImpl<double, ushort, ushort>*/,
|
||||
0/*addWeightedImpl<double, ushort, short >*/,
|
||||
0/*addWeightedImpl<double, ushort, int >*/,
|
||||
0/*addWeightedImpl<double, ushort, float >*/,
|
||||
0/*addWeightedImpl<double, ushort, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<double, short, uchar >*/,
|
||||
0/*addWeightedImpl<double, short, schar >*/,
|
||||
0/*addWeightedImpl<double, short, ushort>*/,
|
||||
0/*addWeightedImpl<double, short, short >*/,
|
||||
0/*addWeightedImpl<double, short, int >*/,
|
||||
0/*addWeightedImpl<double, short, float >*/,
|
||||
0/*addWeightedImpl<double, short, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<double, int, uchar >*/,
|
||||
0/*addWeightedImpl<double, int, schar >*/,
|
||||
0/*addWeightedImpl<double, int, ushort>*/,
|
||||
0/*addWeightedImpl<double, int, short >*/,
|
||||
0/*addWeightedImpl<double, int, int >*/,
|
||||
0/*addWeightedImpl<double, int, float >*/,
|
||||
0/*addWeightedImpl<double, int, double>*/
|
||||
},
|
||||
{
|
||||
0/*addWeightedImpl<double, float, uchar >*/,
|
||||
0/*addWeightedImpl<double, float, schar >*/,
|
||||
0/*addWeightedImpl<double, float, ushort>*/,
|
||||
0/*addWeightedImpl<double, float, short >*/,
|
||||
0/*addWeightedImpl<double, float, int >*/,
|
||||
0/*addWeightedImpl<double, float, float >*/,
|
||||
0/*addWeightedImpl<double, float, double>*/
|
||||
},
|
||||
{
|
||||
addWeightedImpl<double, double, uchar >,
|
||||
addWeightedImpl<double, double, schar >,
|
||||
addWeightedImpl<double, double, ushort>,
|
||||
addWeightedImpl<double, double, short >,
|
||||
addWeightedImpl<double, double, int >,
|
||||
addWeightedImpl<double, double, float >,
|
||||
addWeightedImpl<double, double, double>
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
|
||||
int sdepth1 = src1.depth();
|
||||
int sdepth2 = src2.depth();
|
||||
|
||||
ddepth = ddepth >= 0 ? CV_MAT_DEPTH(ddepth) : std::max(sdepth1, sdepth2);
|
||||
const int cn = src1.channels();
|
||||
|
||||
CV_Assert( src2.size() == src1.size() && src2.channels() == cn );
|
||||
CV_Assert( sdepth1 <= CV_64F && sdepth2 <= CV_64F && ddepth <= CV_64F );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src1.size(), CV_MAKE_TYPE(ddepth, cn), stream);
|
||||
|
||||
GpuMat src1_single = src1.reshape(1);
|
||||
GpuMat src2_single = src2.reshape(1);
|
||||
GpuMat dst_single = dst.reshape(1);
|
||||
|
||||
if (sdepth1 > sdepth2)
|
||||
{
|
||||
src1_single.swap(src2_single);
|
||||
std::swap(alpha, beta);
|
||||
std::swap(sdepth1, sdepth2);
|
||||
}
|
||||
|
||||
const func_t func = funcs[sdepth1][sdepth2][ddepth];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src1_single, alpha, src2_single, beta, gamma, dst_single, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,230 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
void bitMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int op);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// bitwise_not
|
||||
|
||||
void cv::cuda::bitwise_not(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
const int depth = src.depth();
|
||||
|
||||
CV_DbgAssert( depth <= CV_32F );
|
||||
CV_DbgAssert( mask.empty() || (mask.type() == CV_8UC1 && mask.size() == src.size()) );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
const int bcols = (int) (src.cols * src.elemSize());
|
||||
|
||||
if ((bcols & 3) == 0)
|
||||
{
|
||||
const int vcols = bcols >> 2;
|
||||
|
||||
GlobPtrSz<uint> vsrc = globPtr((uint*) src.data, src.step, src.rows, vcols);
|
||||
GlobPtrSz<uint> vdst = globPtr((uint*) dst.data, dst.step, src.rows, vcols);
|
||||
|
||||
gridTransformUnary(vsrc, vdst, bit_not<uint>(), stream);
|
||||
}
|
||||
else if ((bcols & 1) == 0)
|
||||
{
|
||||
const int vcols = bcols >> 1;
|
||||
|
||||
GlobPtrSz<ushort> vsrc = globPtr((ushort*) src.data, src.step, src.rows, vcols);
|
||||
GlobPtrSz<ushort> vdst = globPtr((ushort*) dst.data, dst.step, src.rows, vcols);
|
||||
|
||||
gridTransformUnary(vsrc, vdst, bit_not<ushort>(), stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobPtrSz<uchar> vsrc = globPtr((uchar*) src.data, src.step, src.rows, bcols);
|
||||
GlobPtrSz<uchar> vdst = globPtr((uchar*) dst.data, dst.step, src.rows, bcols);
|
||||
|
||||
gridTransformUnary(vsrc, vdst, bit_not<uchar>(), stream);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (depth == CV_32F || depth == CV_32S)
|
||||
{
|
||||
GlobPtrSz<uint> vsrc = globPtr((uint*) src.data, src.step, src.rows, src.cols * src.channels());
|
||||
GlobPtrSz<uint> vdst = globPtr((uint*) dst.data, dst.step, src.rows, src.cols * src.channels());
|
||||
|
||||
gridTransformUnary(vsrc, vdst, bit_not<uint>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
|
||||
}
|
||||
else if (depth == CV_16S || depth == CV_16U)
|
||||
{
|
||||
GlobPtrSz<ushort> vsrc = globPtr((ushort*) src.data, src.step, src.rows, src.cols * src.channels());
|
||||
GlobPtrSz<ushort> vdst = globPtr((ushort*) dst.data, dst.step, src.rows, src.cols * src.channels());
|
||||
|
||||
gridTransformUnary(vsrc, vdst, bit_not<ushort>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobPtrSz<uchar> vsrc = globPtr((uchar*) src.data, src.step, src.rows, src.cols * src.channels());
|
||||
GlobPtrSz<uchar> vdst = globPtr((uchar*) dst.data, dst.step, src.rows, src.cols * src.channels());
|
||||
|
||||
gridTransformUnary(vsrc, vdst, bit_not<uchar>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
|
||||
}
|
||||
}
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// Binary bitwise logical operations
|
||||
|
||||
namespace
|
||||
{
|
||||
template <template <typename> class Op, typename T>
|
||||
void bitMatOp(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
GlobPtrSz<T> vsrc1 = globPtr((T*) src1.data, src1.step, src1.rows, src1.cols * src1.channels());
|
||||
GlobPtrSz<T> vsrc2 = globPtr((T*) src2.data, src2.step, src1.rows, src1.cols * src1.channels());
|
||||
GlobPtrSz<T> vdst = globPtr((T*) dst.data, dst.step, src1.rows, src1.cols * src1.channels());
|
||||
|
||||
if (mask.data)
|
||||
gridTransformBinary(vsrc1, vsrc2, vdst, Op<T>(), singleMaskChannels(globPtr<uchar>(mask), src1.channels()), stream);
|
||||
else
|
||||
gridTransformBinary(vsrc1, vsrc2, vdst, Op<T>(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void bitMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int op)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, Stream& stream);
|
||||
static const func_t funcs32[] =
|
||||
{
|
||||
bitMatOp<bit_and, uint>,
|
||||
bitMatOp<bit_or, uint>,
|
||||
bitMatOp<bit_xor, uint>
|
||||
};
|
||||
static const func_t funcs16[] =
|
||||
{
|
||||
bitMatOp<bit_and, ushort>,
|
||||
bitMatOp<bit_or, ushort>,
|
||||
bitMatOp<bit_xor, ushort>
|
||||
};
|
||||
static const func_t funcs8[] =
|
||||
{
|
||||
bitMatOp<bit_and, uchar>,
|
||||
bitMatOp<bit_or, uchar>,
|
||||
bitMatOp<bit_xor, uchar>
|
||||
};
|
||||
|
||||
const int depth = src1.depth();
|
||||
|
||||
CV_DbgAssert( depth <= CV_32F );
|
||||
CV_DbgAssert( op >= 0 && op < 3 );
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
const int bcols = (int) (src1.cols * src1.elemSize());
|
||||
|
||||
if ((bcols & 3) == 0)
|
||||
{
|
||||
const int vcols = bcols >> 2;
|
||||
|
||||
GpuMat vsrc1(src1.rows, vcols, CV_32SC1, src1.data, src1.step);
|
||||
GpuMat vsrc2(src1.rows, vcols, CV_32SC1, src2.data, src2.step);
|
||||
GpuMat vdst(src1.rows, vcols, CV_32SC1, dst.data, dst.step);
|
||||
|
||||
funcs32[op](vsrc1, vsrc2, vdst, GpuMat(), stream);
|
||||
}
|
||||
else if ((bcols & 1) == 0)
|
||||
{
|
||||
const int vcols = bcols >> 1;
|
||||
|
||||
GpuMat vsrc1(src1.rows, vcols, CV_16UC1, src1.data, src1.step);
|
||||
GpuMat vsrc2(src1.rows, vcols, CV_16UC1, src2.data, src2.step);
|
||||
GpuMat vdst(src1.rows, vcols, CV_16UC1, dst.data, dst.step);
|
||||
|
||||
funcs16[op](vsrc1, vsrc2, vdst, GpuMat(), stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
GpuMat vsrc1(src1.rows, bcols, CV_8UC1, src1.data, src1.step);
|
||||
GpuMat vsrc2(src1.rows, bcols, CV_8UC1, src2.data, src2.step);
|
||||
GpuMat vdst(src1.rows, bcols, CV_8UC1, dst.data, dst.step);
|
||||
|
||||
funcs8[op](vsrc1, vsrc2, vdst, GpuMat(), stream);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (depth == CV_32F || depth == CV_32S)
|
||||
{
|
||||
funcs32[op](src1, src2, dst, mask, stream);
|
||||
}
|
||||
else if (depth == CV_16S || depth == CV_16U)
|
||||
{
|
||||
funcs16[op](src1, src2, dst, mask, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
funcs8[op](src1, src2, dst, mask, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,206 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void bitScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int op);
|
||||
|
||||
namespace
|
||||
{
|
||||
template <template <typename> class Op, typename T>
|
||||
void bitScalarOp(const GpuMat& src, uint value, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformUnary(globPtr<T>(src), globPtr<T>(dst), bind2nd(Op<T>(), value), stream);
|
||||
}
|
||||
|
||||
typedef void (*bit_scalar_func_t)(const GpuMat& src, uint value, GpuMat& dst, Stream& stream);
|
||||
|
||||
template <typename T, bit_scalar_func_t func> struct BitScalar
|
||||
{
|
||||
static void call(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
func(src, cv::saturate_cast<T>(value[0]), dst, stream);
|
||||
}
|
||||
};
|
||||
|
||||
template <bit_scalar_func_t func> struct BitScalar4
|
||||
{
|
||||
static void call(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
uint packedVal = 0;
|
||||
|
||||
packedVal |= cv::saturate_cast<uchar>(value[0]);
|
||||
packedVal |= cv::saturate_cast<uchar>(value[1]) << 8;
|
||||
packedVal |= cv::saturate_cast<uchar>(value[2]) << 16;
|
||||
packedVal |= cv::saturate_cast<uchar>(value[3]) << 24;
|
||||
|
||||
func(src, packedVal, dst, stream);
|
||||
}
|
||||
};
|
||||
|
||||
template <int DEPTH, int cn> struct NppBitwiseCFunc
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_type;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
typedef NppStatus(*func_t)(const npp_type* pSrc1, int nSrc1Step, const npp_type* pConstants, npp_type* pDst, int nDstStep, NppiSize oSizeROI, NppStreamContext ctx);
|
||||
#else
|
||||
typedef NppStatus (*func_t)(const npp_type* pSrc1, int nSrc1Step, const npp_type* pConstants, npp_type* pDst, int nDstStep, NppiSize oSizeROI);
|
||||
#endif
|
||||
};
|
||||
|
||||
template <int DEPTH, int cn, typename NppBitwiseCFunc<DEPTH, cn>::func_t func> struct NppBitwiseC
|
||||
{
|
||||
typedef typename NppBitwiseCFunc<DEPTH, cn>::npp_type npp_type;
|
||||
|
||||
static void call(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& _stream)
|
||||
{
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize oSizeROI;
|
||||
oSizeROI.width = src.cols;
|
||||
oSizeROI.height = src.rows;
|
||||
|
||||
const npp_type pConstants[] =
|
||||
{
|
||||
cv::saturate_cast<npp_type>(value[0]),
|
||||
cv::saturate_cast<npp_type>(value[1]),
|
||||
cv::saturate_cast<npp_type>(value[2]),
|
||||
cv::saturate_cast<npp_type>(value[3])
|
||||
};
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall(func(src.ptr<npp_type>(), static_cast<int>(src.step), pConstants, dst.ptr<npp_type>(), static_cast<int>(dst.step), oSizeROI, h));
|
||||
#else
|
||||
nppSafeCall( func(src.ptr<npp_type>(), static_cast<int>(src.step), pConstants, dst.ptr<npp_type>(), static_cast<int>(dst.step), oSizeROI) );
|
||||
#endif
|
||||
|
||||
if (stream == 0)
|
||||
CV_CUDEV_SAFE_CALL( cudaDeviceSynchronize() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void bitScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int op)
|
||||
{
|
||||
CV_UNUSED(mask);
|
||||
|
||||
typedef void (*func_t)(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[3][6][4] =
|
||||
{
|
||||
#if USE_NPP_STREAM_CTX
|
||||
{
|
||||
{BitScalar<uchar, bitScalarOp<bit_and, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiAndC_8u_C3R_Ctx >::call, BitScalar4< bitScalarOp<bit_and, uint> >::call},
|
||||
{BitScalar<uchar, bitScalarOp<bit_and, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiAndC_8u_C3R_Ctx >::call, BitScalar4< bitScalarOp<bit_and, uint> >::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_and, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiAndC_16u_C3R_Ctx>::call, NppBitwiseC<CV_16U, 4, nppiAndC_16u_C4R_Ctx>::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_and, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiAndC_16u_C3R_Ctx>::call, NppBitwiseC<CV_16U, 4, nppiAndC_16u_C4R_Ctx>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_and, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiAndC_32s_C3R_Ctx>::call, NppBitwiseC<CV_32S, 4, nppiAndC_32s_C4R_Ctx>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_and, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiAndC_32s_C3R_Ctx>::call, NppBitwiseC<CV_32S, 4, nppiAndC_32s_C4R_Ctx>::call}
|
||||
},
|
||||
{
|
||||
{BitScalar<uchar, bitScalarOp<bit_or, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiOrC_8u_C3R_Ctx >::call, BitScalar4< bitScalarOp<bit_or, uint> >::call},
|
||||
{BitScalar<uchar, bitScalarOp<bit_or, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiOrC_8u_C3R_Ctx >::call, BitScalar4< bitScalarOp<bit_or, uint> >::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_or, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiOrC_16u_C3R_Ctx>::call, NppBitwiseC<CV_16U, 4, nppiOrC_16u_C4R_Ctx>::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_or, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiOrC_16u_C3R_Ctx>::call, NppBitwiseC<CV_16U, 4, nppiOrC_16u_C4R_Ctx>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_or, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiOrC_32s_C3R_Ctx>::call, NppBitwiseC<CV_32S, 4, nppiOrC_32s_C4R_Ctx>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_or, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiOrC_32s_C3R_Ctx>::call, NppBitwiseC<CV_32S, 4, nppiOrC_32s_C4R_Ctx>::call}
|
||||
},
|
||||
{
|
||||
{BitScalar<uchar, bitScalarOp<bit_xor, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiXorC_8u_C3R_Ctx >::call, BitScalar4< bitScalarOp<bit_xor, uint> >::call},
|
||||
{BitScalar<uchar, bitScalarOp<bit_xor, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiXorC_8u_C3R_Ctx >::call, BitScalar4< bitScalarOp<bit_xor, uint> >::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_xor, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiXorC_16u_C3R_Ctx>::call, NppBitwiseC<CV_16U, 4, nppiXorC_16u_C4R_Ctx>::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_xor, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiXorC_16u_C3R_Ctx>::call, NppBitwiseC<CV_16U, 4, nppiXorC_16u_C4R_Ctx>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_xor, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiXorC_32s_C3R_Ctx>::call, NppBitwiseC<CV_32S, 4, nppiXorC_32s_C4R_Ctx>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_xor, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiXorC_32s_C3R_Ctx>::call, NppBitwiseC<CV_32S, 4, nppiXorC_32s_C4R_Ctx>::call}
|
||||
}
|
||||
#else
|
||||
{
|
||||
{ BitScalar<uchar, bitScalarOp<bit_and, uchar> >::call, 0, NppBitwiseC<CV_8U, 3, nppiAndC_8u_C3R >::call, BitScalar4< bitScalarOp<bit_and, uint> >::call },
|
||||
{ BitScalar<uchar, bitScalarOp<bit_and, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiAndC_8u_C3R >::call, BitScalar4< bitScalarOp<bit_and, uint> >::call },
|
||||
{ BitScalar<ushort, bitScalarOp<bit_and, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiAndC_16u_C3R>::call, NppBitwiseC<CV_16U, 4, nppiAndC_16u_C4R>::call },
|
||||
{ BitScalar<ushort, bitScalarOp<bit_and, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiAndC_16u_C3R>::call, NppBitwiseC<CV_16U, 4, nppiAndC_16u_C4R>::call },
|
||||
{ BitScalar<uint, bitScalarOp<bit_and, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiAndC_32s_C3R>::call, NppBitwiseC<CV_32S, 4, nppiAndC_32s_C4R>::call },
|
||||
{ BitScalar<uint, bitScalarOp<bit_and, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiAndC_32s_C3R>::call, NppBitwiseC<CV_32S, 4, nppiAndC_32s_C4R>::call }
|
||||
},
|
||||
{
|
||||
{BitScalar<uchar, bitScalarOp<bit_or, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiOrC_8u_C3R >::call, BitScalar4< bitScalarOp<bit_or, uint> >::call},
|
||||
{BitScalar<uchar, bitScalarOp<bit_or, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiOrC_8u_C3R >::call, BitScalar4< bitScalarOp<bit_or, uint> >::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_or, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiOrC_16u_C3R>::call, NppBitwiseC<CV_16U, 4, nppiOrC_16u_C4R>::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_or, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiOrC_16u_C3R>::call, NppBitwiseC<CV_16U, 4, nppiOrC_16u_C4R>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_or, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiOrC_32s_C3R>::call, NppBitwiseC<CV_32S, 4, nppiOrC_32s_C4R>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_or, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiOrC_32s_C3R>::call, NppBitwiseC<CV_32S, 4, nppiOrC_32s_C4R>::call}
|
||||
},
|
||||
{
|
||||
{BitScalar<uchar, bitScalarOp<bit_xor, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiXorC_8u_C3R >::call, BitScalar4< bitScalarOp<bit_xor, uint> >::call},
|
||||
{BitScalar<uchar, bitScalarOp<bit_xor, uchar> >::call , 0, NppBitwiseC<CV_8U , 3, nppiXorC_8u_C3R >::call, BitScalar4< bitScalarOp<bit_xor, uint> >::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_xor, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiXorC_16u_C3R>::call, NppBitwiseC<CV_16U, 4, nppiXorC_16u_C4R>::call},
|
||||
{BitScalar<ushort, bitScalarOp<bit_xor, ushort> >::call, 0, NppBitwiseC<CV_16U, 3, nppiXorC_16u_C3R>::call, NppBitwiseC<CV_16U, 4, nppiXorC_16u_C4R>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_xor, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiXorC_32s_C3R>::call, NppBitwiseC<CV_32S, 4, nppiXorC_32s_C4R>::call},
|
||||
{BitScalar<uint, bitScalarOp<bit_xor, uint> >::call , 0, NppBitwiseC<CV_32S, 3, nppiXorC_32s_C3R>::call, NppBitwiseC<CV_32S, 4, nppiXorC_32s_C4R>::call}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
const int depth = src.depth();
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_DbgAssert( depth <= CV_32F );
|
||||
CV_DbgAssert( cn == 1 || cn == 3 || cn == 4 );
|
||||
CV_DbgAssert( mask.empty() );
|
||||
CV_DbgAssert( op >= 0 && op < 3 );
|
||||
|
||||
funcs[op][depth][cn - 1](src, value, dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,219 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void cmpMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int cmpop);
|
||||
|
||||
namespace
|
||||
{
|
||||
template <class Op, typename T> struct CmpOp : binary_function<T, T, uchar>
|
||||
{
|
||||
__device__ __forceinline__ uchar operator()(T a, T b) const
|
||||
{
|
||||
Op op;
|
||||
return -op(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <template <typename> class Op, typename T>
|
||||
void cmpMat_v1(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
CmpOp<Op<T>, T> op;
|
||||
gridTransformBinary_< TransformPolicy<T> >(globPtr<T>(src1), globPtr<T>(src2), globPtr<uchar>(dst), op, stream);
|
||||
}
|
||||
|
||||
struct VCmpEq4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vcmpeq4(a, b);
|
||||
}
|
||||
};
|
||||
struct VCmpNe4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vcmpne4(a, b);
|
||||
}
|
||||
};
|
||||
struct VCmpLt4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vcmplt4(a, b);
|
||||
}
|
||||
};
|
||||
struct VCmpLe4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vcmple4(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
void cmpMatEq_v4(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 2;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, VCmpEq4(), stream);
|
||||
}
|
||||
void cmpMatNe_v4(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 2;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, VCmpNe4(), stream);
|
||||
}
|
||||
void cmpMatLt_v4(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 2;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, VCmpLt4(), stream);
|
||||
}
|
||||
void cmpMatLe_v4(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 2;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, VCmpLe4(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cmpMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int cmpop)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[7][4] =
|
||||
{
|
||||
{cmpMat_v1<equal_to, uchar> , cmpMat_v1<not_equal_to, uchar> , cmpMat_v1<less, uchar> , cmpMat_v1<less_equal, uchar> },
|
||||
{cmpMat_v1<equal_to, schar> , cmpMat_v1<not_equal_to, schar> , cmpMat_v1<less, schar> , cmpMat_v1<less_equal, schar> },
|
||||
{cmpMat_v1<equal_to, ushort>, cmpMat_v1<not_equal_to, ushort>, cmpMat_v1<less, ushort>, cmpMat_v1<less_equal, ushort>},
|
||||
{cmpMat_v1<equal_to, short> , cmpMat_v1<not_equal_to, short> , cmpMat_v1<less, short> , cmpMat_v1<less_equal, short> },
|
||||
{cmpMat_v1<equal_to, int> , cmpMat_v1<not_equal_to, int> , cmpMat_v1<less, int> , cmpMat_v1<less_equal, int> },
|
||||
{cmpMat_v1<equal_to, float> , cmpMat_v1<not_equal_to, float> , cmpMat_v1<less, float> , cmpMat_v1<less_equal, float> },
|
||||
{cmpMat_v1<equal_to, double>, cmpMat_v1<not_equal_to, double>, cmpMat_v1<less, double>, cmpMat_v1<less_equal, double>}
|
||||
};
|
||||
|
||||
typedef void (*func_v4_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
static const func_v4_t funcs_v4[] =
|
||||
{
|
||||
cmpMatEq_v4, cmpMatNe_v4, cmpMatLt_v4, cmpMatLe_v4
|
||||
};
|
||||
|
||||
const int depth = src1.depth();
|
||||
|
||||
CV_DbgAssert( depth <= CV_64F );
|
||||
|
||||
static const int codes[] =
|
||||
{
|
||||
0, 2, 3, 2, 3, 1
|
||||
};
|
||||
const GpuMat* psrc1[] =
|
||||
{
|
||||
&src1, &src2, &src2, &src1, &src1, &src1
|
||||
};
|
||||
const GpuMat* psrc2[] =
|
||||
{
|
||||
&src2, &src1, &src1, &src2, &src2, &src2
|
||||
};
|
||||
|
||||
const int code = codes[cmpop];
|
||||
|
||||
GpuMat src1_ = psrc1[cmpop]->reshape(1);
|
||||
GpuMat src2_ = psrc2[cmpop]->reshape(1);
|
||||
GpuMat dst_ = dst.reshape(1);
|
||||
|
||||
if (depth == CV_8U && (src1_.cols & 3) == 0)
|
||||
{
|
||||
const intptr_t src1ptr = reinterpret_cast<intptr_t>(src1_.data);
|
||||
const intptr_t src2ptr = reinterpret_cast<intptr_t>(src2_.data);
|
||||
const intptr_t dstptr = reinterpret_cast<intptr_t>(dst_.data);
|
||||
|
||||
const bool isAllAligned = (src1ptr & 31) == 0 && (src2ptr & 31) == 0 && (dstptr & 31) == 0;
|
||||
|
||||
if (isAllAligned)
|
||||
{
|
||||
funcs_v4[code](src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const func_t func = funcs[depth][code];
|
||||
|
||||
func(src1_, src2_, dst_, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,225 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void cmpScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const GpuMat&, double, Stream& stream, int cmpop);
|
||||
|
||||
namespace
|
||||
{
|
||||
template <class Op, typename T> struct CmpOp : binary_function<T, T, uchar>
|
||||
{
|
||||
__device__ __forceinline__ uchar operator()(T a, T b) const
|
||||
{
|
||||
Op op;
|
||||
return -op(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
#define MAKE_VEC(_type, _cn) typename MakeVec<_type, _cn>::type
|
||||
|
||||
template <class Op, typename T, int cn> struct CmpScalarOp;
|
||||
|
||||
template <class Op, typename T>
|
||||
struct CmpScalarOp<Op, T, 1> : unary_function<T, uchar>
|
||||
{
|
||||
T val;
|
||||
|
||||
__device__ __forceinline__ uchar operator()(T src) const
|
||||
{
|
||||
CmpOp<Op, T> op;
|
||||
return op(src, val);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Op, typename T>
|
||||
struct CmpScalarOp<Op, T, 2> : unary_function<MAKE_VEC(T, 2), MAKE_VEC(uchar, 2)>
|
||||
{
|
||||
MAKE_VEC(T, 2) val;
|
||||
|
||||
__device__ __forceinline__ MAKE_VEC(uchar, 2) operator()(const MAKE_VEC(T, 2) & src) const
|
||||
{
|
||||
CmpOp<Op, T> op;
|
||||
return VecTraits<MAKE_VEC(uchar, 2)>::make(op(src.x, val.x), op(src.y, val.y));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Op, typename T>
|
||||
struct CmpScalarOp<Op, T, 3> : unary_function<MAKE_VEC(T, 3), MAKE_VEC(uchar, 3)>
|
||||
{
|
||||
MAKE_VEC(T, 3) val;
|
||||
|
||||
__device__ __forceinline__ MAKE_VEC(uchar, 3) operator()(const MAKE_VEC(T, 3) & src) const
|
||||
{
|
||||
CmpOp<Op, T> op;
|
||||
return VecTraits<MAKE_VEC(uchar, 3)>::make(op(src.x, val.x), op(src.y, val.y), op(src.z, val.z));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Op, typename T>
|
||||
struct CmpScalarOp<Op, T, 4> : unary_function<MAKE_VEC(T, 4), MAKE_VEC(uchar, 4)>
|
||||
{
|
||||
MAKE_VEC(T, 4) val;
|
||||
|
||||
__device__ __forceinline__ MAKE_VEC(uchar, 4) operator()(const MAKE_VEC(T, 4) & src) const
|
||||
{
|
||||
CmpOp<Op, T> op;
|
||||
return VecTraits<MAKE_VEC(uchar, 4)>::make(op(src.x, val.x), op(src.y, val.y), op(src.z, val.z), op(src.w, val.w));
|
||||
}
|
||||
};
|
||||
|
||||
#undef TYPE_VEC
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <template <typename> class Op, typename T, int cn>
|
||||
void cmpScalarImpl(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<T, cn>::type src_type;
|
||||
typedef typename MakeVec<uchar, cn>::type dst_type;
|
||||
|
||||
cv::Scalar_<T> value_ = value;
|
||||
|
||||
CmpScalarOp<Op<T>, T, cn> op;
|
||||
op.val = VecTraits<src_type>::make(value_.val);
|
||||
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<src_type>(src), globPtr<dst_type>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cmpScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const GpuMat&, double, Stream& stream, int cmpop)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[7][6][4] =
|
||||
{
|
||||
{
|
||||
{cmpScalarImpl<equal_to, uchar, 1>, cmpScalarImpl<equal_to, uchar, 2>, cmpScalarImpl<equal_to, uchar, 3>, cmpScalarImpl<equal_to, uchar, 4>},
|
||||
{cmpScalarImpl<greater, uchar, 1>, cmpScalarImpl<greater, uchar, 2>, cmpScalarImpl<greater, uchar, 3>, cmpScalarImpl<greater, uchar, 4>},
|
||||
{cmpScalarImpl<greater_equal, uchar, 1>, cmpScalarImpl<greater_equal, uchar, 2>, cmpScalarImpl<greater_equal, uchar, 3>, cmpScalarImpl<greater_equal, uchar, 4>},
|
||||
{cmpScalarImpl<less, uchar, 1>, cmpScalarImpl<less, uchar, 2>, cmpScalarImpl<less, uchar, 3>, cmpScalarImpl<less, uchar, 4>},
|
||||
{cmpScalarImpl<less_equal, uchar, 1>, cmpScalarImpl<less_equal, uchar, 2>, cmpScalarImpl<less_equal, uchar, 3>, cmpScalarImpl<less_equal, uchar, 4>},
|
||||
{cmpScalarImpl<not_equal_to, uchar, 1>, cmpScalarImpl<not_equal_to, uchar, 2>, cmpScalarImpl<not_equal_to, uchar, 3>, cmpScalarImpl<not_equal_to, uchar, 4>}
|
||||
},
|
||||
{
|
||||
{cmpScalarImpl<equal_to, schar, 1>, cmpScalarImpl<equal_to, schar, 2>, cmpScalarImpl<equal_to, schar, 3>, cmpScalarImpl<equal_to, schar, 4>},
|
||||
{cmpScalarImpl<greater, schar, 1>, cmpScalarImpl<greater, schar, 2>, cmpScalarImpl<greater, schar, 3>, cmpScalarImpl<greater, schar, 4>},
|
||||
{cmpScalarImpl<greater_equal, schar, 1>, cmpScalarImpl<greater_equal, schar, 2>, cmpScalarImpl<greater_equal, schar, 3>, cmpScalarImpl<greater_equal, schar, 4>},
|
||||
{cmpScalarImpl<less, schar, 1>, cmpScalarImpl<less, schar, 2>, cmpScalarImpl<less, schar, 3>, cmpScalarImpl<less, schar, 4>},
|
||||
{cmpScalarImpl<less_equal, schar, 1>, cmpScalarImpl<less_equal, schar, 2>, cmpScalarImpl<less_equal, schar, 3>, cmpScalarImpl<less_equal, schar, 4>},
|
||||
{cmpScalarImpl<not_equal_to, schar, 1>, cmpScalarImpl<not_equal_to, schar, 2>, cmpScalarImpl<not_equal_to, schar, 3>, cmpScalarImpl<not_equal_to, schar, 4>}
|
||||
},
|
||||
{
|
||||
{cmpScalarImpl<equal_to, ushort, 1>, cmpScalarImpl<equal_to, ushort, 2>, cmpScalarImpl<equal_to, ushort, 3>, cmpScalarImpl<equal_to, ushort, 4>},
|
||||
{cmpScalarImpl<greater, ushort, 1>, cmpScalarImpl<greater, ushort, 2>, cmpScalarImpl<greater, ushort, 3>, cmpScalarImpl<greater, ushort, 4>},
|
||||
{cmpScalarImpl<greater_equal, ushort, 1>, cmpScalarImpl<greater_equal, ushort, 2>, cmpScalarImpl<greater_equal, ushort, 3>, cmpScalarImpl<greater_equal, ushort, 4>},
|
||||
{cmpScalarImpl<less, ushort, 1>, cmpScalarImpl<less, ushort, 2>, cmpScalarImpl<less, ushort, 3>, cmpScalarImpl<less, ushort, 4>},
|
||||
{cmpScalarImpl<less_equal, ushort, 1>, cmpScalarImpl<less_equal, ushort, 2>, cmpScalarImpl<less_equal, ushort, 3>, cmpScalarImpl<less_equal, ushort, 4>},
|
||||
{cmpScalarImpl<not_equal_to, ushort, 1>, cmpScalarImpl<not_equal_to, ushort, 2>, cmpScalarImpl<not_equal_to, ushort, 3>, cmpScalarImpl<not_equal_to, ushort, 4>}
|
||||
},
|
||||
{
|
||||
{cmpScalarImpl<equal_to, short, 1>, cmpScalarImpl<equal_to, short, 2>, cmpScalarImpl<equal_to, short, 3>, cmpScalarImpl<equal_to, short, 4>},
|
||||
{cmpScalarImpl<greater, short, 1>, cmpScalarImpl<greater, short, 2>, cmpScalarImpl<greater, short, 3>, cmpScalarImpl<greater, short, 4>},
|
||||
{cmpScalarImpl<greater_equal, short, 1>, cmpScalarImpl<greater_equal, short, 2>, cmpScalarImpl<greater_equal, short, 3>, cmpScalarImpl<greater_equal, short, 4>},
|
||||
{cmpScalarImpl<less, short, 1>, cmpScalarImpl<less, short, 2>, cmpScalarImpl<less, short, 3>, cmpScalarImpl<less, short, 4>},
|
||||
{cmpScalarImpl<less_equal, short, 1>, cmpScalarImpl<less_equal, short, 2>, cmpScalarImpl<less_equal, short, 3>, cmpScalarImpl<less_equal, short, 4>},
|
||||
{cmpScalarImpl<not_equal_to, short, 1>, cmpScalarImpl<not_equal_to, short, 2>, cmpScalarImpl<not_equal_to, short, 3>, cmpScalarImpl<not_equal_to, short, 4>}
|
||||
},
|
||||
{
|
||||
{cmpScalarImpl<equal_to, int, 1>, cmpScalarImpl<equal_to, int, 2>, cmpScalarImpl<equal_to, int, 3>, cmpScalarImpl<equal_to, int, 4>},
|
||||
{cmpScalarImpl<greater, int, 1>, cmpScalarImpl<greater, int, 2>, cmpScalarImpl<greater, int, 3>, cmpScalarImpl<greater, int, 4>},
|
||||
{cmpScalarImpl<greater_equal, int, 1>, cmpScalarImpl<greater_equal, int, 2>, cmpScalarImpl<greater_equal, int, 3>, cmpScalarImpl<greater_equal, int, 4>},
|
||||
{cmpScalarImpl<less, int, 1>, cmpScalarImpl<less, int, 2>, cmpScalarImpl<less, int, 3>, cmpScalarImpl<less, int, 4>},
|
||||
{cmpScalarImpl<less_equal, int, 1>, cmpScalarImpl<less_equal, int, 2>, cmpScalarImpl<less_equal, int, 3>, cmpScalarImpl<less_equal, int, 4>},
|
||||
{cmpScalarImpl<not_equal_to, int, 1>, cmpScalarImpl<not_equal_to, int, 2>, cmpScalarImpl<not_equal_to, int, 3>, cmpScalarImpl<not_equal_to, int, 4>}
|
||||
},
|
||||
{
|
||||
{cmpScalarImpl<equal_to, float, 1>, cmpScalarImpl<equal_to, float, 2>, cmpScalarImpl<equal_to, float, 3>, cmpScalarImpl<equal_to, float, 4>},
|
||||
{cmpScalarImpl<greater, float, 1>, cmpScalarImpl<greater, float, 2>, cmpScalarImpl<greater, float, 3>, cmpScalarImpl<greater, float, 4>},
|
||||
{cmpScalarImpl<greater_equal, float, 1>, cmpScalarImpl<greater_equal, float, 2>, cmpScalarImpl<greater_equal, float, 3>, cmpScalarImpl<greater_equal, float, 4>},
|
||||
{cmpScalarImpl<less, float, 1>, cmpScalarImpl<less, float, 2>, cmpScalarImpl<less, float, 3>, cmpScalarImpl<less, float, 4>},
|
||||
{cmpScalarImpl<less_equal, float, 1>, cmpScalarImpl<less_equal, float, 2>, cmpScalarImpl<less_equal, float, 3>, cmpScalarImpl<less_equal, float, 4>},
|
||||
{cmpScalarImpl<not_equal_to, float, 1>, cmpScalarImpl<not_equal_to, float, 2>, cmpScalarImpl<not_equal_to, float, 3>, cmpScalarImpl<not_equal_to, float, 4>}
|
||||
},
|
||||
{
|
||||
{cmpScalarImpl<equal_to, double, 1>, cmpScalarImpl<equal_to, double, 2>, cmpScalarImpl<equal_to, double, 3>, cmpScalarImpl<equal_to, double, 4>},
|
||||
{cmpScalarImpl<greater, double, 1>, cmpScalarImpl<greater, double, 2>, cmpScalarImpl<greater, double, 3>, cmpScalarImpl<greater, double, 4>},
|
||||
{cmpScalarImpl<greater_equal, double, 1>, cmpScalarImpl<greater_equal, double, 2>, cmpScalarImpl<greater_equal, double, 3>, cmpScalarImpl<greater_equal, double, 4>},
|
||||
{cmpScalarImpl<less, double, 1>, cmpScalarImpl<less, double, 2>, cmpScalarImpl<less, double, 3>, cmpScalarImpl<less, double, 4>},
|
||||
{cmpScalarImpl<less_equal, double, 1>, cmpScalarImpl<less_equal, double, 2>, cmpScalarImpl<less_equal, double, 3>, cmpScalarImpl<less_equal, double, 4>},
|
||||
{cmpScalarImpl<not_equal_to, double, 1>, cmpScalarImpl<not_equal_to, double, 2>, cmpScalarImpl<not_equal_to, double, 3>, cmpScalarImpl<not_equal_to, double, 4>}
|
||||
}
|
||||
};
|
||||
|
||||
if (inv)
|
||||
{
|
||||
// src1 is a scalar; swap it with src2
|
||||
cmpop = cmpop == cv::CMP_LT ? cv::CMP_GT : cmpop == cv::CMP_LE ? cv::CMP_GE :
|
||||
cmpop == cv::CMP_GE ? cv::CMP_LE : cmpop == cv::CMP_GT ? cv::CMP_LT : cmpop;
|
||||
}
|
||||
|
||||
const int depth = src.depth();
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_Assert( depth <= CV_64F && cn <= 4 );
|
||||
|
||||
funcs[depth][cmpop][cn - 1](src, val, dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,159 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ShiftMap
|
||||
{
|
||||
typedef int2 value_type;
|
||||
typedef int index_type;
|
||||
|
||||
int top;
|
||||
int left;
|
||||
|
||||
__device__ __forceinline__ int2 operator ()(int y, int x) const
|
||||
{
|
||||
return make_int2(x - left, y - top);
|
||||
}
|
||||
};
|
||||
|
||||
struct ShiftMapSz : ShiftMap
|
||||
{
|
||||
int rows, cols;
|
||||
};
|
||||
}
|
||||
|
||||
namespace cv { namespace cudev {
|
||||
|
||||
template <> struct PtrTraits<ShiftMapSz> : PtrTraitsBase<ShiftMapSz, ShiftMap>
|
||||
{
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, int cn>
|
||||
void copyMakeBorderImpl(const GpuMat& src, GpuMat& dst, int top, int left, int borderMode, cv::Scalar borderValue, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<T, cn>::type src_type;
|
||||
|
||||
cv::Scalar_<T> borderValue_ = borderValue;
|
||||
const src_type brdVal = VecTraits<src_type>::make(borderValue_.val);
|
||||
|
||||
ShiftMapSz map;
|
||||
map.top = top;
|
||||
map.left = left;
|
||||
map.rows = dst.rows;
|
||||
map.cols = dst.cols;
|
||||
|
||||
switch (borderMode)
|
||||
{
|
||||
case cv::BORDER_CONSTANT:
|
||||
gridCopy(remapPtr(brdConstant(globPtr<src_type>(src), brdVal), map), globPtr<src_type>(dst), stream);
|
||||
break;
|
||||
case cv::BORDER_REPLICATE:
|
||||
gridCopy(remapPtr(brdReplicate(globPtr<src_type>(src)), map), globPtr<src_type>(dst), stream);
|
||||
break;
|
||||
case cv::BORDER_REFLECT:
|
||||
gridCopy(remapPtr(brdReflect(globPtr<src_type>(src)), map), globPtr<src_type>(dst), stream);
|
||||
break;
|
||||
case cv::BORDER_WRAP:
|
||||
gridCopy(remapPtr(brdWrap(globPtr<src_type>(src)), map), globPtr<src_type>(dst), stream);
|
||||
break;
|
||||
case cv::BORDER_REFLECT_101:
|
||||
gridCopy(remapPtr(brdReflect101(globPtr<src_type>(src)), map), globPtr<src_type>(dst), stream);
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::copyMakeBorder(InputArray _src, OutputArray _dst, int top, int bottom, int left, int right, int borderType, Scalar value, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int top, int left, int borderMode, cv::Scalar borderValue, Stream& stream);
|
||||
static const func_t funcs[6][4] =
|
||||
{
|
||||
{ copyMakeBorderImpl<uchar , 1> , copyMakeBorderImpl<uchar , 2> , copyMakeBorderImpl<uchar , 3> , copyMakeBorderImpl<uchar , 4> },
|
||||
{0 /*copyMakeBorderImpl<schar , 1>*/, 0 /*copyMakeBorderImpl<schar , 2>*/, 0 /*copyMakeBorderImpl<schar , 3>*/, 0 /*copyMakeBorderImpl<schar , 4>*/},
|
||||
{ copyMakeBorderImpl<ushort, 1> , 0 /*copyMakeBorderImpl<ushort, 2>*/, copyMakeBorderImpl<ushort, 3> , copyMakeBorderImpl<ushort, 4> },
|
||||
{ copyMakeBorderImpl<short , 1> , 0 /*copyMakeBorderImpl<short , 2>*/, copyMakeBorderImpl<short , 3> , copyMakeBorderImpl<short , 4> },
|
||||
{0 /*copyMakeBorderImpl<int , 1>*/, 0 /*copyMakeBorderImpl<int , 2>*/, 0 /*copyMakeBorderImpl<int , 3>*/, 0 /*copyMakeBorderImpl<int , 4>*/},
|
||||
{ copyMakeBorderImpl<float , 1> , 0 /*copyMakeBorderImpl<float , 2>*/, copyMakeBorderImpl<float , 3> , copyMakeBorderImpl<float ,4> }
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
const int depth = src.depth();
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_Assert( depth <= CV_32F && cn <= 4 );
|
||||
CV_Assert( borderType == BORDER_REFLECT_101 || borderType == BORDER_REPLICATE || borderType == BORDER_CONSTANT || borderType == BORDER_REFLECT || borderType == BORDER_WRAP );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.rows + top + bottom, src.cols + left + right, src.type(), stream);
|
||||
|
||||
const func_t func = funcs[depth][cn - 1];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src, dst, top, left, borderType, value, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,113 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename D>
|
||||
void countNonZeroImpl(const GpuMat& _src, GpuMat& _dst, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&) _src;
|
||||
GpuMat_<D>& dst = (GpuMat_<D>&) _dst;
|
||||
|
||||
gridCountNonZero(src, dst, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::countNonZero(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
countNonZeroImpl<uchar, int>,
|
||||
countNonZeroImpl<schar, int>,
|
||||
countNonZeroImpl<ushort, int>,
|
||||
countNonZeroImpl<short, int>,
|
||||
countNonZeroImpl<int, int>,
|
||||
countNonZeroImpl<float, int>,
|
||||
countNonZeroImpl<double, int>,
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() <= CV_64F );
|
||||
CV_Assert( src.channels() == 1 );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, 1, 1, CV_32SC1, stream);
|
||||
|
||||
const func_t func = funcs[src.depth()];
|
||||
func(src, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
int cv::cuda::countNonZero(InputArray _src)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
BufferPool pool(stream);
|
||||
GpuMat buf = pool.getBuffer(1, 1, CV_32SC1);
|
||||
|
||||
countNonZero(_src, buf, stream);
|
||||
|
||||
int data;
|
||||
buf.download(Mat(1, 1, CV_32SC1, &data));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,240 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void divMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int);
|
||||
void divMat_8uc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
void divMat_16sc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename D> struct DivOp : binary_function<T, T, D>
|
||||
{
|
||||
__device__ __forceinline__ D operator ()(T a, T b) const
|
||||
{
|
||||
return b != 0 ? saturate_cast<D>(a / b) : 0;
|
||||
}
|
||||
};
|
||||
template <typename T> struct DivOp<T, float> : binary_function<T, T, float>
|
||||
{
|
||||
__device__ __forceinline__ float operator ()(T a, T b) const
|
||||
{
|
||||
return b != 0 ? static_cast<float>(a) / b : 0.0f;
|
||||
}
|
||||
};
|
||||
template <typename T> struct DivOp<T, double> : binary_function<T, T, double>
|
||||
{
|
||||
__device__ __forceinline__ double operator ()(T a, T b) const
|
||||
{
|
||||
return b != 0 ? static_cast<double>(a) / b : 0.0;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename S, typename D> struct DivScaleOp : binary_function<T, T, D>
|
||||
{
|
||||
S scale;
|
||||
|
||||
__device__ __forceinline__ D operator ()(T a, T b) const
|
||||
{
|
||||
return b != 0 ? saturate_cast<D>(scale * a / b) : 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T, typename S, typename D>
|
||||
void divMatImpl(const GpuMat& src1, const GpuMat& src2, const GpuMat& dst, double scale, Stream& stream)
|
||||
{
|
||||
if (scale == 1)
|
||||
{
|
||||
DivOp<T, D> op;
|
||||
gridTransformBinary_< TransformPolicy<S> >(globPtr<T>(src1), globPtr<T>(src2), globPtr<D>(dst), op, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
DivScaleOp<T, S, D> op;
|
||||
op.scale = static_cast<S>(scale);
|
||||
gridTransformBinary_< TransformPolicy<S> >(globPtr<T>(src1), globPtr<T>(src2), globPtr<D>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void divMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, const GpuMat& dst, double scale, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] =
|
||||
{
|
||||
{
|
||||
divMatImpl<uchar, float, uchar>,
|
||||
divMatImpl<uchar, float, schar>,
|
||||
divMatImpl<uchar, float, ushort>,
|
||||
divMatImpl<uchar, float, short>,
|
||||
divMatImpl<uchar, float, int>,
|
||||
divMatImpl<uchar, float, float>,
|
||||
divMatImpl<uchar, double, double>
|
||||
},
|
||||
{
|
||||
divMatImpl<schar, float, uchar>,
|
||||
divMatImpl<schar, float, schar>,
|
||||
divMatImpl<schar, float, ushort>,
|
||||
divMatImpl<schar, float, short>,
|
||||
divMatImpl<schar, float, int>,
|
||||
divMatImpl<schar, float, float>,
|
||||
divMatImpl<schar, double, double>
|
||||
},
|
||||
{
|
||||
0 /*divMatImpl<ushort, float, uchar>*/,
|
||||
0 /*divMatImpl<ushort, float, schar>*/,
|
||||
divMatImpl<ushort, float, ushort>,
|
||||
divMatImpl<ushort, float, short>,
|
||||
divMatImpl<ushort, float, int>,
|
||||
divMatImpl<ushort, float, float>,
|
||||
divMatImpl<ushort, double, double>
|
||||
},
|
||||
{
|
||||
0 /*divMatImpl<short, float, uchar>*/,
|
||||
0 /*divMatImpl<short, float, schar>*/,
|
||||
divMatImpl<short, float, ushort>,
|
||||
divMatImpl<short, float, short>,
|
||||
divMatImpl<short, float, int>,
|
||||
divMatImpl<short, float, float>,
|
||||
divMatImpl<short, double, double>
|
||||
},
|
||||
{
|
||||
0 /*divMatImpl<int, float, uchar>*/,
|
||||
0 /*divMatImpl<int, float, schar>*/,
|
||||
0 /*divMatImpl<int, float, ushort>*/,
|
||||
0 /*divMatImpl<int, float, short>*/,
|
||||
divMatImpl<int, float, int>,
|
||||
divMatImpl<int, float, float>,
|
||||
divMatImpl<int, double, double>
|
||||
},
|
||||
{
|
||||
0 /*divMatImpl<float, float, uchar>*/,
|
||||
0 /*divMatImpl<float, float, schar>*/,
|
||||
0 /*divMatImpl<float, float, ushort>*/,
|
||||
0 /*divMatImpl<float, float, short>*/,
|
||||
0 /*divMatImpl<float, float, int>*/,
|
||||
divMatImpl<float, float, float>,
|
||||
divMatImpl<float, double, double>
|
||||
},
|
||||
{
|
||||
0 /*divMatImpl<double, double, uchar>*/,
|
||||
0 /*divMatImpl<double, double, schar>*/,
|
||||
0 /*divMatImpl<double, double, ushort>*/,
|
||||
0 /*divMatImpl<double, double, short>*/,
|
||||
0 /*divMatImpl<double, double, int>*/,
|
||||
0 /*divMatImpl<double, double, float>*/,
|
||||
divMatImpl<double, double, double>
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src1.depth();
|
||||
const int ddepth = dst.depth();
|
||||
|
||||
GpuMat src1_ = src1.reshape(1);
|
||||
GpuMat src2_ = src2.reshape(1);
|
||||
GpuMat dst_ = dst.reshape(1);
|
||||
|
||||
const func_t func = funcs[sdepth][ddepth];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src1_, src2_, dst_, scale, stream);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
struct DivOpSpecial : binary_function<T, float, T>
|
||||
{
|
||||
__device__ __forceinline__ T operator ()(const T& a, float b) const
|
||||
{
|
||||
typedef typename VecTraits<T>::elem_type elem_type;
|
||||
|
||||
T res = VecTraits<T>::all(0);
|
||||
|
||||
if (b != 0)
|
||||
{
|
||||
b = 1.0f / b;
|
||||
res.x = saturate_cast<elem_type>(a.x * b);
|
||||
res.y = saturate_cast<elem_type>(a.y * b);
|
||||
res.z = saturate_cast<elem_type>(a.z * b);
|
||||
res.w = saturate_cast<elem_type>(a.w * b);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void divMat_8uc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformBinary(globPtr<uchar4>(src1), globPtr<float>(src2), globPtr<uchar4>(dst), DivOpSpecial<uchar4>(), stream);
|
||||
}
|
||||
|
||||
void divMat_16sc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformBinary(globPtr<short4>(src1), globPtr<float>(src2), globPtr<short4>(dst), DivOpSpecial<short4>(), stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,262 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/cuda/cuda_compat.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void divScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream, int);
|
||||
|
||||
namespace
|
||||
{
|
||||
using cv::cuda::device::compat::double4Compat;
|
||||
template <typename T, int cn> struct SafeDiv;
|
||||
template <typename T> struct SafeDiv<T, 1>
|
||||
{
|
||||
__device__ __forceinline__ static T op(T a, T b)
|
||||
{
|
||||
return b != 0 ? a / b : 0;
|
||||
}
|
||||
};
|
||||
template <typename T> struct SafeDiv<T, 2>
|
||||
{
|
||||
__device__ __forceinline__ static T op(const T& a, const T& b)
|
||||
{
|
||||
T res;
|
||||
|
||||
res.x = b.x != 0 ? a.x / b.x : 0;
|
||||
res.y = b.y != 0 ? a.y / b.y : 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
template <typename T> struct SafeDiv<T, 3>
|
||||
{
|
||||
__device__ __forceinline__ static T op(const T& a, const T& b)
|
||||
{
|
||||
T res;
|
||||
|
||||
res.x = b.x != 0 ? a.x / b.x : 0;
|
||||
res.y = b.y != 0 ? a.y / b.y : 0;
|
||||
res.z = b.z != 0 ? a.z / b.z : 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
template <typename T> struct SafeDiv<T, 4>
|
||||
{
|
||||
__device__ __forceinline__ static T op(const T& a, const T& b)
|
||||
{
|
||||
T res;
|
||||
|
||||
res.x = b.x != 0 ? a.x / b.x : 0;
|
||||
res.y = b.y != 0 ? a.y / b.y : 0;
|
||||
res.z = b.z != 0 ? a.z / b.z : 0;
|
||||
res.w = b.w != 0 ? a.w / b.w : 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename SrcType, typename ScalarType, typename DstType> struct DivScalarOp : unary_function<SrcType, DstType>
|
||||
{
|
||||
ScalarType val;
|
||||
|
||||
__device__ __forceinline__ DstType operator ()(SrcType a) const
|
||||
{
|
||||
return saturate_cast<DstType>(SafeDiv<ScalarType, VecTraits<ScalarType>::cn>::op(saturate_cast<ScalarType>(a), val));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename SrcType, typename ScalarType, typename DstType> struct DivScalarOpInv : unary_function<SrcType, DstType>
|
||||
{
|
||||
ScalarType val;
|
||||
|
||||
__device__ __forceinline__ DstType operator ()(SrcType a) const
|
||||
{
|
||||
return saturate_cast<DstType>(SafeDiv<ScalarType, VecTraits<ScalarType>::cn>::op(val, saturate_cast<ScalarType>(a)));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename SrcType, typename ScalarDepth, typename DstType>
|
||||
void divScalarImpl(const GpuMat& src, cv::Scalar value, bool inv, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<ScalarDepth, VecTraits<SrcType>::cn>::type ScalarType;
|
||||
|
||||
cv::Scalar_<ScalarDepth> value_ = value;
|
||||
|
||||
if (inv)
|
||||
{
|
||||
DivScalarOpInv<SrcType, ScalarType, DstType> op;
|
||||
op.val = VecTraits<ScalarType>::make(value_.val);
|
||||
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
DivScalarOp<SrcType, ScalarType, DstType> op;
|
||||
op.val = VecTraits<ScalarType>::make(value_.val);
|
||||
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void divScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[7][7][4] =
|
||||
{
|
||||
{
|
||||
{divScalarImpl<uchar, float, uchar>, divScalarImpl<uchar2, float, uchar2>, divScalarImpl<uchar3, float, uchar3>, divScalarImpl<uchar4, float, uchar4>},
|
||||
{divScalarImpl<uchar, float, schar>, divScalarImpl<uchar2, float, char2>, divScalarImpl<uchar3, float, char3>, divScalarImpl<uchar4, float, char4>},
|
||||
{divScalarImpl<uchar, float, ushort>, divScalarImpl<uchar2, float, ushort2>, divScalarImpl<uchar3, float, ushort3>, divScalarImpl<uchar4, float, ushort4>},
|
||||
{divScalarImpl<uchar, float, short>, divScalarImpl<uchar2, float, short2>, divScalarImpl<uchar3, float, short3>, divScalarImpl<uchar4, float, short4>},
|
||||
{divScalarImpl<uchar, float, int>, divScalarImpl<uchar2, float, int2>, divScalarImpl<uchar3, float, int3>, divScalarImpl<uchar4, float, int4>},
|
||||
{divScalarImpl<uchar, float, float>, divScalarImpl<uchar2, float, float2>, divScalarImpl<uchar3, float, float3>, divScalarImpl<uchar4, float, float4>},
|
||||
{divScalarImpl<uchar, double, double>, divScalarImpl<uchar2, double, double2>, divScalarImpl<uchar3, double, double3>, divScalarImpl<uchar4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{divScalarImpl<schar, float, uchar>, divScalarImpl<char2, float, uchar2>, divScalarImpl<char3, float, uchar3>, divScalarImpl<char4, float, uchar4>},
|
||||
{divScalarImpl<schar, float, schar>, divScalarImpl<char2, float, char2>, divScalarImpl<char3, float, char3>, divScalarImpl<char4, float, char4>},
|
||||
{divScalarImpl<schar, float, ushort>, divScalarImpl<char2, float, ushort2>, divScalarImpl<char3, float, ushort3>, divScalarImpl<char4, float, ushort4>},
|
||||
{divScalarImpl<schar, float, short>, divScalarImpl<char2, float, short2>, divScalarImpl<char3, float, short3>, divScalarImpl<char4, float, short4>},
|
||||
{divScalarImpl<schar, float, int>, divScalarImpl<char2, float, int2>, divScalarImpl<char3, float, int3>, divScalarImpl<char4, float, int4>},
|
||||
{divScalarImpl<schar, float, float>, divScalarImpl<char2, float, float2>, divScalarImpl<char3, float, float3>, divScalarImpl<char4, float, float4>},
|
||||
{divScalarImpl<schar, double, double>, divScalarImpl<char2, double, double2>, divScalarImpl<char3, double, double3>, divScalarImpl<char4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*divScalarImpl<ushort, float, uchar>*/, 0 /*divScalarImpl<ushort2, float, uchar2>*/, 0 /*divScalarImpl<ushort3, float, uchar3>*/, 0 /*divScalarImpl<ushort4, float, uchar4>*/},
|
||||
{0 /*divScalarImpl<ushort, float, schar>*/, 0 /*divScalarImpl<ushort2, float, char2>*/, 0 /*divScalarImpl<ushort3, float, char3>*/, 0 /*divScalarImpl<ushort4, float, char4>*/},
|
||||
{divScalarImpl<ushort, float, ushort>, divScalarImpl<ushort2, float, ushort2>, divScalarImpl<ushort3, float, ushort3>, divScalarImpl<ushort4, float, ushort4>},
|
||||
{divScalarImpl<ushort, float, short>, divScalarImpl<ushort2, float, short2>, divScalarImpl<ushort3, float, short3>, divScalarImpl<ushort4, float, short4>},
|
||||
{divScalarImpl<ushort, float, int>, divScalarImpl<ushort2, float, int2>, divScalarImpl<ushort3, float, int3>, divScalarImpl<ushort4, float, int4>},
|
||||
{divScalarImpl<ushort, float, float>, divScalarImpl<ushort2, float, float2>, divScalarImpl<ushort3, float, float3>, divScalarImpl<ushort4, float, float4>},
|
||||
{divScalarImpl<ushort, double, double>, divScalarImpl<ushort2, double, double2>, divScalarImpl<ushort3, double, double3>, divScalarImpl<ushort4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*divScalarImpl<short, float, uchar>*/, 0 /*divScalarImpl<short2, float, uchar2>*/, 0 /*divScalarImpl<short3, float, uchar3>*/, 0 /*divScalarImpl<short4, float, uchar4>*/},
|
||||
{0 /*divScalarImpl<short, float, schar>*/, 0 /*divScalarImpl<short2, float, char2>*/, 0 /*divScalarImpl<short3, float, char3>*/, 0 /*divScalarImpl<short4, float, char4>*/},
|
||||
{divScalarImpl<short, float, ushort>, divScalarImpl<short2, float, ushort2>, divScalarImpl<short3, float, ushort3>, divScalarImpl<short4, float, ushort4>},
|
||||
{divScalarImpl<short, float, short>, divScalarImpl<short2, float, short2>, divScalarImpl<short3, float, short3>, divScalarImpl<short4, float, short4>},
|
||||
{divScalarImpl<short, float, int>, divScalarImpl<short2, float, int2>, divScalarImpl<short3, float, int3>, divScalarImpl<short4, float, int4>},
|
||||
{divScalarImpl<short, float, float>, divScalarImpl<short2, float, float2>, divScalarImpl<short3, float, float3>, divScalarImpl<short4, float, float4>},
|
||||
{divScalarImpl<short, double, double>, divScalarImpl<short2, double, double2>, divScalarImpl<short3, double, double3>, divScalarImpl<short4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*divScalarImpl<int, float, uchar>*/, 0 /*divScalarImpl<int2, float, uchar2>*/, 0 /*divScalarImpl<int3, float, uchar3>*/, 0 /*divScalarImpl<int4, float, uchar4>*/},
|
||||
{0 /*divScalarImpl<int, float, schar>*/, 0 /*divScalarImpl<int2, float, char2>*/, 0 /*divScalarImpl<int3, float, char3>*/, 0 /*divScalarImpl<int4, float, char4>*/},
|
||||
{0 /*divScalarImpl<int, float, ushort>*/, 0 /*divScalarImpl<int2, float, ushort2>*/, 0 /*divScalarImpl<int3, float, ushort3>*/, 0 /*divScalarImpl<int4, float, ushort4>*/},
|
||||
{0 /*divScalarImpl<int, float, short>*/, 0 /*divScalarImpl<int2, float, short2>*/, 0 /*divScalarImpl<int3, float, short3>*/, 0 /*divScalarImpl<int4, float, short4>*/},
|
||||
{divScalarImpl<int, float, int>, divScalarImpl<int2, float, int2>, divScalarImpl<int3, float, int3>, divScalarImpl<int4, float, int4>},
|
||||
{divScalarImpl<int, float, float>, divScalarImpl<int2, float, float2>, divScalarImpl<int3, float, float3>, divScalarImpl<int4, float, float4>},
|
||||
{divScalarImpl<int, double, double>, divScalarImpl<int2, double, double2>, divScalarImpl<int3, double, double3>, divScalarImpl<int4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*divScalarImpl<float, float, uchar>*/, 0 /*divScalarImpl<float2, float, uchar2>*/, 0 /*divScalarImpl<float3, float, uchar3>*/, 0 /*divScalarImpl<float4, float, uchar4>*/},
|
||||
{0 /*divScalarImpl<float, float, schar>*/, 0 /*divScalarImpl<float2, float, char2>*/, 0 /*divScalarImpl<float3, float, char3>*/, 0 /*divScalarImpl<float4, float, char4>*/},
|
||||
{0 /*divScalarImpl<float, float, ushort>*/, 0 /*divScalarImpl<float2, float, ushort2>*/, 0 /*divScalarImpl<float3, float, ushort3>*/, 0 /*divScalarImpl<float4, float, ushort4>*/},
|
||||
{0 /*divScalarImpl<float, float, short>*/, 0 /*divScalarImpl<float2, float, short2>*/, 0 /*divScalarImpl<float3, float, short3>*/, 0 /*divScalarImpl<float4, float, short4>*/},
|
||||
{0 /*divScalarImpl<float, float, int>*/, 0 /*divScalarImpl<float2, float, int2>*/, 0 /*divScalarImpl<float3, float, int3>*/, 0 /*divScalarImpl<float4, float, int4>*/},
|
||||
{divScalarImpl<float, float, float>, divScalarImpl<float2, float, float2>, divScalarImpl<float3, float, float3>, divScalarImpl<float4, float, float4>},
|
||||
{divScalarImpl<float, double, double>, divScalarImpl<float2, double, double2>, divScalarImpl<float3, double, double3>, divScalarImpl<float4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*divScalarImpl<double, double, uchar>*/, 0 /*divScalarImpl<double2, double, uchar2>*/, 0 /*divScalarImpl<double3, double, uchar3>*/, 0 /*divScalarImpl<double4, double, uchar4>*/},
|
||||
{0 /*divScalarImpl<double, double, schar>*/, 0 /*divScalarImpl<double2, double, char2>*/, 0 /*divScalarImpl<double3, double, char3>*/, 0 /*divScalarImpl<double4, double, char4>*/},
|
||||
{0 /*divScalarImpl<double, double, ushort>*/, 0 /*divScalarImpl<double2, double, ushort2>*/, 0 /*divScalarImpl<double3, double, ushort3>*/, 0 /*divScalarImpl<double4, double, ushort4>*/},
|
||||
{0 /*divScalarImpl<double, double, short>*/, 0 /*divScalarImpl<double2, double, short2>*/, 0 /*divScalarImpl<double3, double, short3>*/, 0 /*divScalarImpl<double4, double, short4>*/},
|
||||
{0 /*divScalarImpl<double, double, int>*/, 0 /*divScalarImpl<double2, double, int2>*/, 0 /*divScalarImpl<double3, double, int3>*/, 0 /*divScalarImpl<double4, double, int4>*/},
|
||||
{0 /*divScalarImpl<double, double, float>*/, 0 /*divScalarImpl<double2, double, float2>*/, 0 /*divScalarImpl<double3, double, float3>*/, 0 /*divScalarImpl<double4, double, float4>*/},
|
||||
{divScalarImpl<double, double, double>, divScalarImpl<double2, double, double2>, divScalarImpl<double3, double, double3>, divScalarImpl<double4Compat, double, double4Compat>}
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src.depth();
|
||||
const int ddepth = dst.depth();
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F && cn <= 4 );
|
||||
|
||||
if (inv)
|
||||
{
|
||||
val[0] *= scale;
|
||||
val[1] *= scale;
|
||||
val[2] *= scale;
|
||||
val[3] *= scale;
|
||||
}
|
||||
else
|
||||
{
|
||||
val[0] /= scale;
|
||||
val[1] /= scale;
|
||||
val[2] /= scale;
|
||||
val[3] /= scale;
|
||||
}
|
||||
|
||||
const func_t func = funcs[sdepth][ddepth][cn - 1];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src, val, inv, dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,99 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T, int cn>
|
||||
void inRangeImpl(const GpuMat& src,
|
||||
const Scalar& lowerb,
|
||||
const Scalar& upperb,
|
||||
GpuMat& dst,
|
||||
Stream& stream) {
|
||||
gridTransformUnary(globPtr<typename MakeVec<T, cn>::type>(src),
|
||||
globPtr<uchar>(dst),
|
||||
InRangeFunc<T, cn>(lowerb, upperb),
|
||||
stream);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void cv::cuda::inRange(InputArray _src,
|
||||
const Scalar& _lowerb,
|
||||
const Scalar& _upperb,
|
||||
OutputArray _dst,
|
||||
Stream& stream) {
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
typedef void (*func_t)(const GpuMat& src,
|
||||
const Scalar& lowerb,
|
||||
const Scalar& upperb,
|
||||
GpuMat& dst,
|
||||
Stream& stream);
|
||||
|
||||
// Note: We cannot support 16F with the current implementation because we
|
||||
// use a CUDA vector (e.g. int3) to store the bounds, and there is no CUDA
|
||||
// vector type for float16
|
||||
static constexpr const int MAX_CHANNELS = 4;
|
||||
static constexpr const int NUM_DEPTHS = CV_64F + 1;
|
||||
|
||||
static const std::array<std::array<func_t, NUM_DEPTHS>, MAX_CHANNELS>
|
||||
funcs = {std::array<func_t, NUM_DEPTHS>{inRangeImpl<uchar, 1>,
|
||||
inRangeImpl<schar, 1>,
|
||||
inRangeImpl<ushort, 1>,
|
||||
inRangeImpl<short, 1>,
|
||||
inRangeImpl<int, 1>,
|
||||
inRangeImpl<float, 1>,
|
||||
inRangeImpl<double, 1>},
|
||||
std::array<func_t, NUM_DEPTHS>{inRangeImpl<uchar, 2>,
|
||||
inRangeImpl<schar, 2>,
|
||||
inRangeImpl<ushort, 2>,
|
||||
inRangeImpl<short, 2>,
|
||||
inRangeImpl<int, 2>,
|
||||
inRangeImpl<float, 2>,
|
||||
inRangeImpl<double, 2>},
|
||||
std::array<func_t, NUM_DEPTHS>{inRangeImpl<uchar, 3>,
|
||||
inRangeImpl<schar, 3>,
|
||||
inRangeImpl<ushort, 3>,
|
||||
inRangeImpl<short, 3>,
|
||||
inRangeImpl<int, 3>,
|
||||
inRangeImpl<float, 3>,
|
||||
inRangeImpl<double, 3>},
|
||||
std::array<func_t, NUM_DEPTHS>{inRangeImpl<uchar, 4>,
|
||||
inRangeImpl<schar, 4>,
|
||||
inRangeImpl<ushort, 4>,
|
||||
inRangeImpl<short, 4>,
|
||||
inRangeImpl<int, 4>,
|
||||
inRangeImpl<float, 4>,
|
||||
inRangeImpl<double, 4>}};
|
||||
|
||||
CV_CheckLE(src.channels(), MAX_CHANNELS, "Src must have <= 4 channels");
|
||||
CV_CheckLE(src.depth(),
|
||||
CV_64F,
|
||||
"Src must have depth 8U, 8S, 16U, 16S, 32S, 32F, or 64F");
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), CV_8UC1, stream);
|
||||
|
||||
const func_t func = funcs.at(src.channels() - 1).at(src.depth());
|
||||
func(src, _lowerb, _upperb, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// integral
|
||||
|
||||
void cv::cuda::integral(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.type() == CV_8UC1 );
|
||||
|
||||
BufferPool pool(stream);
|
||||
GpuMat_<int> res(src.size(), pool.getAllocator());
|
||||
|
||||
gridIntegral(globPtr<uchar>(src), res, stream);
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.rows + 1, src.cols + 1, CV_32SC1, stream);
|
||||
|
||||
dst.setTo(Scalar::all(0), stream);
|
||||
|
||||
GpuMat inner = dst(Rect(1, 1, src.cols, src.rows));
|
||||
res.copyTo(inner, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// sqrIntegral
|
||||
|
||||
void cv::cuda::sqrIntegral(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.type() == CV_8UC1 );
|
||||
|
||||
BufferPool pool(Stream::Null());
|
||||
GpuMat_<double> res(pool.getBuffer(src.size(), CV_64FC1));
|
||||
|
||||
gridIntegral(sqr_(cvt_<int>(globPtr<uchar>(src))), res, stream);
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.rows + 1, src.cols + 1, CV_64FC1, stream);
|
||||
|
||||
dst.setTo(Scalar::all(0), stream);
|
||||
|
||||
GpuMat inner = dst(Rect(1, 1, src.cols, src.rows));
|
||||
res.copyTo(inner, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,136 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "../lut.hpp"
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
#include <opencv2/cudev/ptr2d/texture.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace cv { namespace cuda {
|
||||
|
||||
LookUpTableImpl::LookUpTableImpl(InputArray _lut)
|
||||
{
|
||||
if (_lut.kind() == _InputArray::CUDA_GPU_MAT)
|
||||
{
|
||||
d_lut = _lut.getGpuMat();
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat h_lut = _lut.getMat();
|
||||
d_lut.upload(Mat(1, 256, h_lut.type(), h_lut.data));
|
||||
}
|
||||
CV_Assert( d_lut.depth() == CV_8U );
|
||||
CV_Assert( d_lut.rows == 1 && d_lut.cols == 256 );
|
||||
szInBytes = 256 * d_lut.channels() * sizeof(uchar);
|
||||
}
|
||||
|
||||
struct LutTablePtrC1
|
||||
{
|
||||
typedef uchar value_type;
|
||||
typedef uchar index_type;
|
||||
cv::cudev::TexturePtr<uchar> tex;
|
||||
__device__ __forceinline__ uchar operator ()(uchar, uchar x) const {
|
||||
return tex(x);
|
||||
}
|
||||
};
|
||||
|
||||
struct LutTablePtrC3
|
||||
{
|
||||
typedef uchar3 value_type;
|
||||
typedef uchar3 index_type;
|
||||
cv::cudev::TexturePtr<uchar> tex;
|
||||
__device__ __forceinline__ uchar3 operator ()(const uchar3&, const uchar3& x) const {
|
||||
return make_uchar3(tex(x.x * 3), tex(x.y * 3 + 1), tex(x.z * 3 + 2));
|
||||
}
|
||||
};
|
||||
|
||||
void LookUpTableImpl::transform(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
const int cn = src.channels();
|
||||
const int lut_cn = d_lut.channels();
|
||||
|
||||
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_8UC3 );
|
||||
CV_Assert( lut_cn == 1 || lut_cn == cn );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
if (lut_cn == 1)
|
||||
{
|
||||
GpuMat_<uchar> src1(src.reshape(1));
|
||||
GpuMat_<uchar> dst1(dst.reshape(1));
|
||||
cv::cudev::Texture<uchar> tex(szInBytes, reinterpret_cast<uchar*>(d_lut.data));
|
||||
LutTablePtrC1 tbl;
|
||||
tbl.tex = TexturePtr<uchar>(tex);
|
||||
dst1.assign(lut_(src1, tbl), stream);
|
||||
}
|
||||
else if (lut_cn == 3)
|
||||
{
|
||||
GpuMat_<uchar3>& src3 = (GpuMat_<uchar3>&) src;
|
||||
GpuMat_<uchar3>& dst3 = (GpuMat_<uchar3>&) dst;
|
||||
cv::cudev::Texture<uchar> tex(szInBytes, reinterpret_cast<uchar*>(d_lut.data));
|
||||
LutTablePtrC3 tbl;
|
||||
tbl.tex = TexturePtr<uchar>(tex);
|
||||
dst3.assign(lut_(src3, tbl), stream);
|
||||
}
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,341 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// abs
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
void absMat(const GpuMat& src, const GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), abs_func<T>(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::abs(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, const GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
absMat<uchar>,
|
||||
absMat<schar>,
|
||||
absMat<ushort>,
|
||||
absMat<short>,
|
||||
absMat<int>,
|
||||
absMat<float>,
|
||||
absMat<double>
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() <= CV_64F );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
funcs[src.depth()](src.reshape(1), dst.reshape(1), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// sqr
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T> struct SqrOp : unary_function<T, T>
|
||||
{
|
||||
__device__ __forceinline__ T operator ()(T x) const
|
||||
{
|
||||
return cudev::saturate_cast<T>(x * x);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void sqrMat(const GpuMat& src, const GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), SqrOp<T>(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::sqr(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, const GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
sqrMat<uchar>,
|
||||
sqrMat<schar>,
|
||||
sqrMat<ushort>,
|
||||
sqrMat<short>,
|
||||
sqrMat<int>,
|
||||
sqrMat<float>,
|
||||
sqrMat<double>
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() <= CV_64F );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
funcs[src.depth()](src.reshape(1), dst.reshape(1), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// sqrt
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
void sqrtMat(const GpuMat& src, const GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), sqrt_func<T>(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::sqrt(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, const GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
sqrtMat<uchar>,
|
||||
sqrtMat<schar>,
|
||||
sqrtMat<ushort>,
|
||||
sqrtMat<short>,
|
||||
sqrtMat<int>,
|
||||
sqrtMat<float>,
|
||||
sqrtMat<double>
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() <= CV_64F );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
funcs[src.depth()](src.reshape(1), dst.reshape(1), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// exp
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T> struct ExpOp : unary_function<T, T>
|
||||
{
|
||||
__device__ __forceinline__ T operator ()(T x) const
|
||||
{
|
||||
exp_func<T> f;
|
||||
return cudev::saturate_cast<T>(f(x));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void expMat(const GpuMat& src, const GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), ExpOp<T>(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::exp(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, const GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
expMat<uchar>,
|
||||
expMat<schar>,
|
||||
expMat<ushort>,
|
||||
expMat<short>,
|
||||
expMat<int>,
|
||||
expMat<float>,
|
||||
expMat<double>
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() <= CV_64F );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
funcs[src.depth()](src.reshape(1), dst.reshape(1), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// log
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
void logMat(const GpuMat& src, const GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), log_func<T>(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::log(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, const GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
logMat<uchar>,
|
||||
logMat<schar>,
|
||||
logMat<ushort>,
|
||||
logMat<short>,
|
||||
logMat<int>,
|
||||
logMat<float>,
|
||||
logMat<double>
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() <= CV_64F );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
funcs[src.depth()](src.reshape(1), dst.reshape(1), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// pow
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T, bool Signed = numeric_limits<T>::is_signed> struct PowOp : unary_function<T, T>
|
||||
{
|
||||
typedef typename LargerType<T, float>::type LargerType;
|
||||
LargerType power;
|
||||
|
||||
__device__ __forceinline__ T operator()(T e) const
|
||||
{
|
||||
T res = cudev::saturate_cast<T>(__powf(e < 0 ? -e : e, power));
|
||||
|
||||
if ((e < 0) && (1 & static_cast<int>(power)))
|
||||
res *= -1;
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> struct PowOp<T, false> : unary_function<T, T>
|
||||
{
|
||||
typedef typename LargerType<T, float>::type LargerType;
|
||||
LargerType power;
|
||||
|
||||
__device__ __forceinline__ T operator()(T e) const
|
||||
{
|
||||
return cudev::saturate_cast<T>(__powf(e, power));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void powMat(const GpuMat& src, double power, const GpuMat& dst, Stream& stream)
|
||||
{
|
||||
PowOp<T> op;
|
||||
op.power = static_cast<typename LargerType<T, float>::type>(power);
|
||||
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::pow(InputArray _src, double power, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, double power, const GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
powMat<uchar>,
|
||||
powMat<schar>,
|
||||
powMat<ushort>,
|
||||
powMat<short>,
|
||||
powMat<int>,
|
||||
powMat<float>,
|
||||
powMat<double>
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() <= CV_64F );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
funcs[src.depth()](src.reshape(1), power, dst.reshape(1), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,193 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename R>
|
||||
void minMaxImpl(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&) _src;
|
||||
GpuMat_<R>& dst = (GpuMat_<R>&) _dst;
|
||||
|
||||
if (mask.empty())
|
||||
gridFindMinMaxVal(src, dst, stream);
|
||||
else
|
||||
gridFindMinMaxVal(src, dst, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
|
||||
template <typename T, typename R>
|
||||
void minMaxImpl(const GpuMat& src, const GpuMat& mask, double* minVal, double* maxVal)
|
||||
{
|
||||
BufferPool pool(Stream::Null());
|
||||
GpuMat buf(pool.getBuffer(1, 2, DataType<R>::type));
|
||||
|
||||
minMaxImpl<T, R>(src, mask, buf, Stream::Null());
|
||||
|
||||
R data[2];
|
||||
buf.download(Mat(1, 2, buf.type(), data));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::findMinMax(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX] =
|
||||
{
|
||||
minMaxImpl<uchar, int>,
|
||||
minMaxImpl<schar, int>,
|
||||
minMaxImpl<ushort, int>,
|
||||
minMaxImpl<short, int>,
|
||||
minMaxImpl<int, int>,
|
||||
minMaxImpl<float, float>,
|
||||
minMaxImpl<double, double>
|
||||
};
|
||||
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
const GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
CV_Assert( src.channels() == 1 );
|
||||
CV_Assert( mask.empty() || (mask.size() == src.size() && mask.type() == CV_8U) );
|
||||
|
||||
const int src_depth = src.depth();
|
||||
const int dst_depth = src_depth < CV_32F ? CV_32S : src_depth;
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, 1, 2, dst_depth, stream);
|
||||
|
||||
const func_t func = funcs[src.depth()];
|
||||
CV_Assert(func);
|
||||
|
||||
func(src, mask, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::minMax(InputArray _src, double* minVal, double* maxVal, InputArray _mask)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem dst;
|
||||
findMinMax(_src, dst, _mask, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
double vals[2];
|
||||
dst.createMatHeader().convertTo(Mat(1, 2, CV_64FC1, &vals[0]), CV_64F);
|
||||
|
||||
if (minVal)
|
||||
*minVal = vals[0];
|
||||
|
||||
if (maxVal)
|
||||
*maxVal = vals[1];
|
||||
}
|
||||
|
||||
namespace cv { namespace cuda { namespace device {
|
||||
|
||||
void findMaxAbs(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream);
|
||||
|
||||
}}}
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename R>
|
||||
void findMaxAbsImpl(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&) _src;
|
||||
GpuMat_<R>& dst = (GpuMat_<R>&) _dst;
|
||||
|
||||
if (mask.empty())
|
||||
gridFindMaxVal(abs_(src), dst, stream);
|
||||
else
|
||||
gridFindMaxVal(abs_(src), dst, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::device::findMaxAbs(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX] =
|
||||
{
|
||||
findMaxAbsImpl<uchar, int>,
|
||||
findMaxAbsImpl<schar, int>,
|
||||
findMaxAbsImpl<ushort, int>,
|
||||
findMaxAbsImpl<short, int>,
|
||||
findMaxAbsImpl<int, int>,
|
||||
findMaxAbsImpl<float, float>,
|
||||
findMaxAbsImpl<double, double>
|
||||
};
|
||||
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
const GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
CV_Assert( src.channels() == 1 );
|
||||
CV_Assert( mask.empty() || (mask.size() == src.size() && mask.type() == CV_8U) );
|
||||
|
||||
const int src_depth = src.depth();
|
||||
const int dst_depth = src_depth < CV_32F ? CV_32S : src_depth;
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, 1, 1, dst_depth, stream);
|
||||
|
||||
const func_t func = funcs[src.depth()];
|
||||
CV_Assert(func);
|
||||
|
||||
func(src, mask, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,242 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int op);
|
||||
|
||||
void minMaxScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int op);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
/// minMaxMat
|
||||
|
||||
namespace
|
||||
{
|
||||
template <template <typename> class Op, typename T>
|
||||
void minMaxMat_v1(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformBinary(globPtr<T>(src1), globPtr<T>(src2), globPtr<T>(dst), Op<T>(), stream);
|
||||
}
|
||||
|
||||
struct MinOp2 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vmin2(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
struct MaxOp2 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vmax2(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Op2>
|
||||
void minMaxMat_v2(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 1;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, Op2(), stream);
|
||||
}
|
||||
|
||||
struct MinOp4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vmin4(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
struct MaxOp4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vmax4(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Op4>
|
||||
void minMaxMat_v4(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 2;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, Op4(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int op)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs_v1[2][CV_DEPTH_MAX] =
|
||||
{
|
||||
{
|
||||
minMaxMat_v1<minimum, uchar>,
|
||||
minMaxMat_v1<minimum, schar>,
|
||||
minMaxMat_v1<minimum, ushort>,
|
||||
minMaxMat_v1<minimum, short>,
|
||||
minMaxMat_v1<minimum, int>,
|
||||
minMaxMat_v1<minimum, float>,
|
||||
minMaxMat_v1<minimum, double>
|
||||
},
|
||||
{
|
||||
minMaxMat_v1<maximum, uchar>,
|
||||
minMaxMat_v1<maximum, schar>,
|
||||
minMaxMat_v1<maximum, ushort>,
|
||||
minMaxMat_v1<maximum, short>,
|
||||
minMaxMat_v1<maximum, int>,
|
||||
minMaxMat_v1<maximum, float>,
|
||||
minMaxMat_v1<maximum, double>
|
||||
}
|
||||
};
|
||||
|
||||
static const func_t funcs_v2[2] =
|
||||
{
|
||||
minMaxMat_v2<MinOp2>, minMaxMat_v2<MaxOp2>
|
||||
};
|
||||
|
||||
static const func_t funcs_v4[2] =
|
||||
{
|
||||
minMaxMat_v4<MinOp4>, minMaxMat_v4<MaxOp4>
|
||||
};
|
||||
|
||||
const int depth = src1.depth();
|
||||
|
||||
GpuMat src1_ = src1.reshape(1);
|
||||
GpuMat src2_ = src2.reshape(1);
|
||||
GpuMat dst_ = dst.reshape(1);
|
||||
|
||||
if (depth == CV_8U || depth == CV_16U)
|
||||
{
|
||||
const intptr_t src1ptr = reinterpret_cast<intptr_t>(src1_.data);
|
||||
const intptr_t src2ptr = reinterpret_cast<intptr_t>(src2_.data);
|
||||
const intptr_t dstptr = reinterpret_cast<intptr_t>(dst_.data);
|
||||
|
||||
const bool isAllAligned = (src1ptr & 31) == 0 && (src2ptr & 31) == 0 && (dstptr & 31) == 0;
|
||||
|
||||
if (isAllAligned)
|
||||
{
|
||||
if (depth == CV_8U && (src1_.cols & 3) == 0)
|
||||
{
|
||||
funcs_v4[op](src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
else if (depth == CV_16U && (src1_.cols & 1) == 0)
|
||||
{
|
||||
funcs_v2[op](src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const func_t func = funcs_v1[op][depth];
|
||||
CV_Assert(func);
|
||||
|
||||
func(src1_, src2_, dst_, stream);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
/// minMaxScalar
|
||||
|
||||
namespace
|
||||
{
|
||||
template <template <typename> class Op, typename T>
|
||||
void minMaxScalar(const GpuMat& src, double value, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformUnary(globPtr<T>(src), globPtr<T>(dst), bind2nd(Op<T>(), cv::saturate_cast<T>(value)), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void minMaxScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int op)
|
||||
{
|
||||
CV_DbgAssert( src.channels() == 1 );
|
||||
|
||||
typedef void (*func_t)(const GpuMat& src, double value, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[2][CV_DEPTH_MAX] =
|
||||
{
|
||||
{
|
||||
minMaxScalar<minimum, uchar>,
|
||||
minMaxScalar<minimum, schar>,
|
||||
minMaxScalar<minimum, ushort>,
|
||||
minMaxScalar<minimum, short>,
|
||||
minMaxScalar<minimum, int>,
|
||||
minMaxScalar<minimum, float>,
|
||||
minMaxScalar<minimum, double>
|
||||
},
|
||||
{
|
||||
minMaxScalar<maximum, uchar>,
|
||||
minMaxScalar<maximum, schar>,
|
||||
minMaxScalar<maximum, ushort>,
|
||||
minMaxScalar<maximum, short>,
|
||||
minMaxScalar<maximum, int>,
|
||||
minMaxScalar<maximum, float>,
|
||||
minMaxScalar<maximum, double>
|
||||
}
|
||||
};
|
||||
|
||||
auto f = funcs[op][src.depth()];
|
||||
CV_Assert(f);
|
||||
|
||||
f(src, value[0], dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,160 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename R>
|
||||
void minMaxLocImpl(const GpuMat& _src, const GpuMat& mask, GpuMat& _valBuf, GpuMat& _locBuf, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&) _src;
|
||||
GpuMat_<R>& valBuf = (GpuMat_<R>&) _valBuf;
|
||||
GpuMat_<int>& locBuf = (GpuMat_<int>&) _locBuf;
|
||||
|
||||
if (mask.empty())
|
||||
gridMinMaxLoc(src, valBuf, locBuf, stream);
|
||||
else
|
||||
gridMinMaxLoc(src, valBuf, locBuf, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::findMinMaxLoc(InputArray _src, OutputArray _minMaxVals, OutputArray _loc, InputArray _mask, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _valBuf, GpuMat& _locBuf, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX] =
|
||||
{
|
||||
minMaxLocImpl<uchar, int>,
|
||||
minMaxLocImpl<schar, int>,
|
||||
minMaxLocImpl<ushort, int>,
|
||||
minMaxLocImpl<short, int>,
|
||||
minMaxLocImpl<int, int>,
|
||||
minMaxLocImpl<float, float>,
|
||||
minMaxLocImpl<double, double>
|
||||
};
|
||||
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
const GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
CV_Assert( src.channels() == 1 );
|
||||
CV_Assert( mask.empty() || (mask.size() == src.size() && mask.type() == CV_8U) );
|
||||
|
||||
const int src_depth = src.depth();
|
||||
|
||||
BufferPool pool(stream);
|
||||
GpuMat valBuf(pool.getAllocator());
|
||||
GpuMat locBuf(pool.getAllocator());
|
||||
|
||||
const func_t func = funcs[src_depth];
|
||||
CV_Assert(func);
|
||||
func(src, mask, valBuf, locBuf, stream);
|
||||
|
||||
GpuMat minMaxVals = valBuf.colRange(0, 1);
|
||||
GpuMat loc = locBuf.colRange(0, 1);
|
||||
|
||||
if (_minMaxVals.kind() == _InputArray::CUDA_GPU_MAT)
|
||||
{
|
||||
minMaxVals.copyTo(_minMaxVals, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
minMaxVals.download(_minMaxVals, stream);
|
||||
}
|
||||
|
||||
if (_loc.kind() == _InputArray::CUDA_GPU_MAT)
|
||||
{
|
||||
loc.copyTo(_loc, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
loc.download(_loc, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::minMaxLoc(InputArray _src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc, InputArray _mask)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem minMaxVals, locVals;
|
||||
findMinMaxLoc(_src, minMaxVals, locVals, _mask, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
double vals[2];
|
||||
minMaxVals.createMatHeader().convertTo(Mat(minMaxVals.size(), CV_64FC1, &vals[0]), CV_64F);
|
||||
|
||||
int locs[2];
|
||||
locVals.createMatHeader().copyTo(Mat(locVals.size(), CV_32SC1, &locs[0]));
|
||||
Size size = _src.size();
|
||||
cv::Point locs2D[] = {
|
||||
cv::Point(locs[0] % size.width, locs[0] / size.width),
|
||||
cv::Point(locs[1] % size.width, locs[1] / size.width),
|
||||
};
|
||||
|
||||
if (minVal)
|
||||
*minVal = vals[0];
|
||||
|
||||
if (maxVal)
|
||||
*maxVal = vals[1];
|
||||
|
||||
if (minLoc)
|
||||
*minLoc = locs2D[0];
|
||||
|
||||
if (maxLoc)
|
||||
*maxLoc = locs2D[1];
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,224 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void mulMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int);
|
||||
void mulMat_8uc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
void mulMat_16sc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename D> struct MulOp : binary_function<T, T, D>
|
||||
{
|
||||
__device__ __forceinline__ D operator ()(T a, T b) const
|
||||
{
|
||||
return saturate_cast<D>(a * b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename S, typename D> struct MulScaleOp : binary_function<T, T, D>
|
||||
{
|
||||
S scale;
|
||||
|
||||
__device__ __forceinline__ D operator ()(T a, T b) const
|
||||
{
|
||||
return saturate_cast<D>(scale * a * b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T, typename S, typename D>
|
||||
void mulMatImpl(const GpuMat& src1, const GpuMat& src2, const GpuMat& dst, double scale, Stream& stream)
|
||||
{
|
||||
if (scale == 1)
|
||||
{
|
||||
MulOp<T, D> op;
|
||||
gridTransformBinary_< TransformPolicy<S> >(globPtr<T>(src1), globPtr<T>(src2), globPtr<D>(dst), op, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
MulScaleOp<T, S, D> op;
|
||||
op.scale = static_cast<S>(scale);
|
||||
gridTransformBinary_< TransformPolicy<S> >(globPtr<T>(src1), globPtr<T>(src2), globPtr<D>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mulMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, const GpuMat& dst, double scale, Stream& stream);
|
||||
static const func_t funcs[7][7] =
|
||||
{
|
||||
{
|
||||
mulMatImpl<uchar, float, uchar>,
|
||||
mulMatImpl<uchar, float, schar>,
|
||||
mulMatImpl<uchar, float, ushort>,
|
||||
mulMatImpl<uchar, float, short>,
|
||||
mulMatImpl<uchar, float, int>,
|
||||
mulMatImpl<uchar, float, float>,
|
||||
mulMatImpl<uchar, double, double>
|
||||
},
|
||||
{
|
||||
mulMatImpl<schar, float, uchar>,
|
||||
mulMatImpl<schar, float, schar>,
|
||||
mulMatImpl<schar, float, ushort>,
|
||||
mulMatImpl<schar, float, short>,
|
||||
mulMatImpl<schar, float, int>,
|
||||
mulMatImpl<schar, float, float>,
|
||||
mulMatImpl<schar, double, double>
|
||||
},
|
||||
{
|
||||
0 /*mulMatImpl<ushort, float, uchar>*/,
|
||||
0 /*mulMatImpl<ushort, float, schar>*/,
|
||||
mulMatImpl<ushort, float, ushort>,
|
||||
mulMatImpl<ushort, float, short>,
|
||||
mulMatImpl<ushort, float, int>,
|
||||
mulMatImpl<ushort, float, float>,
|
||||
mulMatImpl<ushort, double, double>
|
||||
},
|
||||
{
|
||||
0 /*mulMatImpl<short, float, uchar>*/,
|
||||
0 /*mulMatImpl<short, float, schar>*/,
|
||||
mulMatImpl<short, float, ushort>,
|
||||
mulMatImpl<short, float, short>,
|
||||
mulMatImpl<short, float, int>,
|
||||
mulMatImpl<short, float, float>,
|
||||
mulMatImpl<short, double, double>
|
||||
},
|
||||
{
|
||||
0 /*mulMatImpl<int, float, uchar>*/,
|
||||
0 /*mulMatImpl<int, float, schar>*/,
|
||||
0 /*mulMatImpl<int, float, ushort>*/,
|
||||
0 /*mulMatImpl<int, float, short>*/,
|
||||
mulMatImpl<int, float, int>,
|
||||
mulMatImpl<int, float, float>,
|
||||
mulMatImpl<int, double, double>
|
||||
},
|
||||
{
|
||||
0 /*mulMatImpl<float, float, uchar>*/,
|
||||
0 /*mulMatImpl<float, float, schar>*/,
|
||||
0 /*mulMatImpl<float, float, ushort>*/,
|
||||
0 /*mulMatImpl<float, float, short>*/,
|
||||
0 /*mulMatImpl<float, float, int>*/,
|
||||
mulMatImpl<float, float, float>,
|
||||
mulMatImpl<float, double, double>
|
||||
},
|
||||
{
|
||||
0 /*mulMatImpl<double, double, uchar>*/,
|
||||
0 /*mulMatImpl<double, double, schar>*/,
|
||||
0 /*mulMatImpl<double, double, ushort>*/,
|
||||
0 /*mulMatImpl<double, double, short>*/,
|
||||
0 /*mulMatImpl<double, double, int>*/,
|
||||
0 /*mulMatImpl<double, double, float>*/,
|
||||
mulMatImpl<double, double, double>
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src1.depth();
|
||||
const int ddepth = dst.depth();
|
||||
|
||||
CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F );
|
||||
|
||||
GpuMat src1_ = src1.reshape(1);
|
||||
GpuMat src2_ = src2.reshape(1);
|
||||
GpuMat dst_ = dst.reshape(1);
|
||||
|
||||
const func_t func = funcs[sdepth][ddepth];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src1_, src2_, dst_, scale, stream);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
struct MulOpSpecial : binary_function<T, float, T>
|
||||
{
|
||||
__device__ __forceinline__ T operator ()(const T& a, float b) const
|
||||
{
|
||||
typedef typename VecTraits<T>::elem_type elem_type;
|
||||
|
||||
T res;
|
||||
|
||||
res.x = saturate_cast<elem_type>(a.x * b);
|
||||
res.y = saturate_cast<elem_type>(a.y * b);
|
||||
res.z = saturate_cast<elem_type>(a.z * b);
|
||||
res.w = saturate_cast<elem_type>(a.w * b);
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void mulMat_8uc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformBinary(globPtr<uchar4>(src1), globPtr<float>(src2), globPtr<uchar4>(dst), MulOpSpecial<uchar4>(), stream);
|
||||
}
|
||||
|
||||
void mulMat_16sc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
gridTransformBinary(globPtr<short4>(src1), globPtr<float>(src2), globPtr<short4>(dst), MulOpSpecial<short4>(), stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,184 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/cuda/cuda_compat.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void mulScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream, int);
|
||||
|
||||
namespace
|
||||
{
|
||||
using cv::cuda::device::compat::double4Compat;
|
||||
template <typename SrcType, typename ScalarType, typename DstType> struct MulScalarOp : unary_function<SrcType, DstType>
|
||||
{
|
||||
ScalarType val;
|
||||
|
||||
__device__ __forceinline__ DstType operator ()(SrcType a) const
|
||||
{
|
||||
return saturate_cast<DstType>(saturate_cast<ScalarType>(a) * val);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename SrcType, typename ScalarDepth, typename DstType>
|
||||
void mulScalarImpl(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<ScalarDepth, VecTraits<SrcType>::cn>::type ScalarType;
|
||||
|
||||
cv::Scalar_<ScalarDepth> value_ = value;
|
||||
|
||||
MulScalarOp<SrcType, ScalarType, DstType> op;
|
||||
op.val = VecTraits<ScalarType>::make(value_.val);
|
||||
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void mulScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, cv::Scalar val, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[7][7][4] =
|
||||
{
|
||||
{
|
||||
{mulScalarImpl<uchar, float, uchar>, mulScalarImpl<uchar2, float, uchar2>, mulScalarImpl<uchar3, float, uchar3>, mulScalarImpl<uchar4, float, uchar4>},
|
||||
{mulScalarImpl<uchar, float, schar>, mulScalarImpl<uchar2, float, char2>, mulScalarImpl<uchar3, float, char3>, mulScalarImpl<uchar4, float, char4>},
|
||||
{mulScalarImpl<uchar, float, ushort>, mulScalarImpl<uchar2, float, ushort2>, mulScalarImpl<uchar3, float, ushort3>, mulScalarImpl<uchar4, float, ushort4>},
|
||||
{mulScalarImpl<uchar, float, short>, mulScalarImpl<uchar2, float, short2>, mulScalarImpl<uchar3, float, short3>, mulScalarImpl<uchar4, float, short4>},
|
||||
{mulScalarImpl<uchar, float, int>, mulScalarImpl<uchar2, float, int2>, mulScalarImpl<uchar3, float, int3>, mulScalarImpl<uchar4, float, int4>},
|
||||
{mulScalarImpl<uchar, float, float>, mulScalarImpl<uchar2, float, float2>, mulScalarImpl<uchar3, float, float3>, mulScalarImpl<uchar4, float, float4>},
|
||||
{mulScalarImpl<uchar, double, double>, mulScalarImpl<uchar2, double, double2>, mulScalarImpl<uchar3, double, double3>, mulScalarImpl<uchar4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{mulScalarImpl<schar, float, uchar>, mulScalarImpl<char2, float, uchar2>, mulScalarImpl<char3, float, uchar3>, mulScalarImpl<char4, float, uchar4>},
|
||||
{mulScalarImpl<schar, float, schar>, mulScalarImpl<char2, float, char2>, mulScalarImpl<char3, float, char3>, mulScalarImpl<char4, float, char4>},
|
||||
{mulScalarImpl<schar, float, ushort>, mulScalarImpl<char2, float, ushort2>, mulScalarImpl<char3, float, ushort3>, mulScalarImpl<char4, float, ushort4>},
|
||||
{mulScalarImpl<schar, float, short>, mulScalarImpl<char2, float, short2>, mulScalarImpl<char3, float, short3>, mulScalarImpl<char4, float, short4>},
|
||||
{mulScalarImpl<schar, float, int>, mulScalarImpl<char2, float, int2>, mulScalarImpl<char3, float, int3>, mulScalarImpl<char4, float, int4>},
|
||||
{mulScalarImpl<schar, float, float>, mulScalarImpl<char2, float, float2>, mulScalarImpl<char3, float, float3>, mulScalarImpl<char4, float, float4>},
|
||||
{mulScalarImpl<schar, double, double>, mulScalarImpl<char2, double, double2>, mulScalarImpl<char3, double, double3>, mulScalarImpl<char4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*mulScalarImpl<ushort, float, uchar>*/, 0 /*mulScalarImpl<ushort2, float, uchar2>*/, 0 /*mulScalarImpl<ushort3, float, uchar3>*/, 0 /*mulScalarImpl<ushort4, float, uchar4>*/},
|
||||
{0 /*mulScalarImpl<ushort, float, schar>*/, 0 /*mulScalarImpl<ushort2, float, char2>*/, 0 /*mulScalarImpl<ushort3, float, char3>*/, 0 /*mulScalarImpl<ushort4, float, char4>*/},
|
||||
{mulScalarImpl<ushort, float, ushort>, mulScalarImpl<ushort2, float, ushort2>, mulScalarImpl<ushort3, float, ushort3>, mulScalarImpl<ushort4, float, ushort4>},
|
||||
{mulScalarImpl<ushort, float, short>, mulScalarImpl<ushort2, float, short2>, mulScalarImpl<ushort3, float, short3>, mulScalarImpl<ushort4, float, short4>},
|
||||
{mulScalarImpl<ushort, float, int>, mulScalarImpl<ushort2, float, int2>, mulScalarImpl<ushort3, float, int3>, mulScalarImpl<ushort4, float, int4>},
|
||||
{mulScalarImpl<ushort, float, float>, mulScalarImpl<ushort2, float, float2>, mulScalarImpl<ushort3, float, float3>, mulScalarImpl<ushort4, float, float4>},
|
||||
{mulScalarImpl<ushort, double, double>, mulScalarImpl<ushort2, double, double2>, mulScalarImpl<ushort3, double, double3>, mulScalarImpl<ushort4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*mulScalarImpl<short, float, uchar>*/, 0 /*mulScalarImpl<short2, float, uchar2>*/, 0 /*mulScalarImpl<short3, float, uchar3>*/, 0 /*mulScalarImpl<short4, float, uchar4>*/},
|
||||
{0 /*mulScalarImpl<short, float, schar>*/, 0 /*mulScalarImpl<short2, float, char2>*/, 0 /*mulScalarImpl<short3, float, char3>*/, 0 /*mulScalarImpl<short4, float, char4>*/},
|
||||
{mulScalarImpl<short, float, ushort>, mulScalarImpl<short2, float, ushort2>, mulScalarImpl<short3, float, ushort3>, mulScalarImpl<short4, float, ushort4>},
|
||||
{mulScalarImpl<short, float, short>, mulScalarImpl<short2, float, short2>, mulScalarImpl<short3, float, short3>, mulScalarImpl<short4, float, short4>},
|
||||
{mulScalarImpl<short, float, int>, mulScalarImpl<short2, float, int2>, mulScalarImpl<short3, float, int3>, mulScalarImpl<short4, float, int4>},
|
||||
{mulScalarImpl<short, float, float>, mulScalarImpl<short2, float, float2>, mulScalarImpl<short3, float, float3>, mulScalarImpl<short4, float, float4>},
|
||||
{mulScalarImpl<short, double, double>, mulScalarImpl<short2, double, double2>, mulScalarImpl<short3, double, double3>, mulScalarImpl<short4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*mulScalarImpl<int, float, uchar>*/, 0 /*mulScalarImpl<int2, float, uchar2>*/, 0 /*mulScalarImpl<int3, float, uchar3>*/, 0 /*mulScalarImpl<int4, float, uchar4>*/},
|
||||
{0 /*mulScalarImpl<int, float, schar>*/, 0 /*mulScalarImpl<int2, float, char2>*/, 0 /*mulScalarImpl<int3, float, char3>*/, 0 /*mulScalarImpl<int4, float, char4>*/},
|
||||
{0 /*mulScalarImpl<int, float, ushort>*/, 0 /*mulScalarImpl<int2, float, ushort2>*/, 0 /*mulScalarImpl<int3, float, ushort3>*/, 0 /*mulScalarImpl<int4, float, ushort4>*/},
|
||||
{0 /*mulScalarImpl<int, float, short>*/, 0 /*mulScalarImpl<int2, float, short2>*/, 0 /*mulScalarImpl<int3, float, short3>*/, 0 /*mulScalarImpl<int4, float, short4>*/},
|
||||
{mulScalarImpl<int, float, int>, mulScalarImpl<int2, float, int2>, mulScalarImpl<int3, float, int3>, mulScalarImpl<int4, float, int4>},
|
||||
{mulScalarImpl<int, float, float>, mulScalarImpl<int2, float, float2>, mulScalarImpl<int3, float, float3>, mulScalarImpl<int4, float, float4>},
|
||||
{mulScalarImpl<int, double, double>, mulScalarImpl<int2, double, double2>, mulScalarImpl<int3, double, double3>, mulScalarImpl<int4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*mulScalarImpl<float, float, uchar>*/, 0 /*mulScalarImpl<float2, float, uchar2>*/, 0 /*mulScalarImpl<float3, float, uchar3>*/, 0 /*mulScalarImpl<float4, float, uchar4>*/},
|
||||
{0 /*mulScalarImpl<float, float, schar>*/, 0 /*mulScalarImpl<float2, float, char2>*/, 0 /*mulScalarImpl<float3, float, char3>*/, 0 /*mulScalarImpl<float4, float, char4>*/},
|
||||
{0 /*mulScalarImpl<float, float, ushort>*/, 0 /*mulScalarImpl<float2, float, ushort2>*/, 0 /*mulScalarImpl<float3, float, ushort3>*/, 0 /*mulScalarImpl<float4, float, ushort4>*/},
|
||||
{0 /*mulScalarImpl<float, float, short>*/, 0 /*mulScalarImpl<float2, float, short2>*/, 0 /*mulScalarImpl<float3, float, short3>*/, 0 /*mulScalarImpl<float4, float, short4>*/},
|
||||
{0 /*mulScalarImpl<float, float, int>*/, 0 /*mulScalarImpl<float2, float, int2>*/, 0 /*mulScalarImpl<float3, float, int3>*/, 0 /*mulScalarImpl<float4, float, int4>*/},
|
||||
{mulScalarImpl<float, float, float>, mulScalarImpl<float2, float, float2>, mulScalarImpl<float3, float, float3>, mulScalarImpl<float4, float, float4>},
|
||||
{mulScalarImpl<float, double, double>, mulScalarImpl<float2, double, double2>, mulScalarImpl<float3, double, double3>, mulScalarImpl<float4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*mulScalarImpl<double, double, uchar>*/, 0 /*mulScalarImpl<double2, double, uchar2>*/, 0 /*mulScalarImpl<double3, double, uchar3>*/, 0 /*mulScalarImpl<double4, double, uchar4>*/},
|
||||
{0 /*mulScalarImpl<double, double, schar>*/, 0 /*mulScalarImpl<double2, double, char2>*/, 0 /*mulScalarImpl<double3, double, char3>*/, 0 /*mulScalarImpl<double4, double, char4>*/},
|
||||
{0 /*mulScalarImpl<double, double, ushort>*/, 0 /*mulScalarImpl<double2, double, ushort2>*/, 0 /*mulScalarImpl<double3, double, ushort3>*/, 0 /*mulScalarImpl<double4, double, ushort4>*/},
|
||||
{0 /*mulScalarImpl<double, double, short>*/, 0 /*mulScalarImpl<double2, double, short2>*/, 0 /*mulScalarImpl<double3, double, short3>*/, 0 /*mulScalarImpl<double4, double, short4>*/},
|
||||
{0 /*mulScalarImpl<double, double, int>*/, 0 /*mulScalarImpl<double2, double, int2>*/, 0 /*mulScalarImpl<double3, double, int3>*/, 0 /*mulScalarImpl<double4, double, int4>*/},
|
||||
{0 /*mulScalarImpl<double, double, float>*/, 0 /*mulScalarImpl<double2, double, float2>*/, 0 /*mulScalarImpl<double3, double, float3>*/, 0 /*mulScalarImpl<double4, double, float4>*/},
|
||||
{mulScalarImpl<double, double, double>, mulScalarImpl<double2, double, double2>, mulScalarImpl<double3, double, double3>, mulScalarImpl<double4Compat, double, double4Compat>}
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src.depth();
|
||||
const int ddepth = dst.depth();
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F && cn <= 4 );
|
||||
|
||||
val[0] *= scale;
|
||||
val[1] *= scale;
|
||||
val[2] *= scale;
|
||||
val[3] *= scale;
|
||||
|
||||
const func_t func = funcs[sdepth][ddepth][cn - 1];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src, val, dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,170 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// mulSpectrums
|
||||
|
||||
namespace
|
||||
{
|
||||
__device__ __forceinline__ float real(const float2& val)
|
||||
{
|
||||
return val.x;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ float imag(const float2& val)
|
||||
{
|
||||
return val.y;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ float2 cmul(const float2& a, const float2& b)
|
||||
{
|
||||
return make_float2((real(a) * real(b)) - (imag(a) * imag(b)),
|
||||
(real(a) * imag(b)) + (imag(a) * real(b)));
|
||||
}
|
||||
|
||||
__device__ __forceinline__ float2 conj(const float2& a)
|
||||
{
|
||||
return make_float2(real(a), -imag(a));
|
||||
}
|
||||
|
||||
struct comlex_mul : binary_function<float2, float2, float2>
|
||||
{
|
||||
__device__ __forceinline__ float2 operator ()(const float2& a, const float2& b) const
|
||||
{
|
||||
return cmul(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
struct comlex_mul_conj : binary_function<float2, float2, float2>
|
||||
{
|
||||
__device__ __forceinline__ float2 operator ()(const float2& a, const float2& b) const
|
||||
{
|
||||
return cmul(a, conj(b));
|
||||
}
|
||||
};
|
||||
|
||||
struct comlex_mul_scale : binary_function<float2, float2, float2>
|
||||
{
|
||||
float scale;
|
||||
|
||||
__device__ __forceinline__ float2 operator ()(const float2& a, const float2& b) const
|
||||
{
|
||||
return scale * cmul(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
struct comlex_mul_conj_scale : binary_function<float2, float2, float2>
|
||||
{
|
||||
float scale;
|
||||
|
||||
__device__ __forceinline__ float2 operator ()(const float2& a, const float2& b) const
|
||||
{
|
||||
return scale * cmul(a, conj(b));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void cv::cuda::mulSpectrums(InputArray _src1, InputArray _src2, OutputArray _dst, int flags, bool conjB, Stream& stream)
|
||||
{
|
||||
CV_UNUSED(flags);
|
||||
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
|
||||
CV_Assert( src1.type() == src2.type() && src1.type() == CV_32FC2 );
|
||||
CV_Assert( src1.size() == src2.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src1.size(), CV_32FC2, stream);
|
||||
|
||||
if (conjB)
|
||||
gridTransformBinary(globPtr<float2>(src1), globPtr<float2>(src2), globPtr<float2>(dst), comlex_mul_conj(), stream);
|
||||
else
|
||||
gridTransformBinary(globPtr<float2>(src1), globPtr<float2>(src2), globPtr<float2>(dst), comlex_mul(), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::mulAndScaleSpectrums(InputArray _src1, InputArray _src2, OutputArray _dst, int flags, float scale, bool conjB, Stream& stream)
|
||||
{
|
||||
CV_UNUSED(flags);
|
||||
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
|
||||
CV_Assert( src1.type() == src2.type() && src1.type() == CV_32FC2);
|
||||
CV_Assert( src1.size() == src2.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src1.size(), CV_32FC2, stream);
|
||||
|
||||
if (conjB)
|
||||
{
|
||||
comlex_mul_conj_scale op;
|
||||
op.scale = scale;
|
||||
gridTransformBinary(globPtr<float2>(src1), globPtr<float2>(src2), globPtr<float2>(dst), op, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
comlex_mul_scale op;
|
||||
op.scale = scale;
|
||||
gridTransformBinary(globPtr<float2>(src1), globPtr<float2>(src2), globPtr<float2>(dst), op, stream);
|
||||
}
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,190 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
void normDiffInf(const GpuMat& _src1, const GpuMat& _src2, GpuMat& _dst, Stream& stream)
|
||||
{
|
||||
const GpuMat_<uchar>& src1 = (const GpuMat_<uchar>&) _src1;
|
||||
const GpuMat_<uchar>& src2 = (const GpuMat_<uchar>&) _src2;
|
||||
GpuMat_<int>& dst = (GpuMat_<int>&) _dst;
|
||||
|
||||
gridFindMaxVal(abs_(cvt_<int>(src1) - cvt_<int>(src2)), dst, stream);
|
||||
}
|
||||
|
||||
void normDiffL1(const GpuMat& _src1, const GpuMat& _src2, GpuMat& _dst, Stream& stream)
|
||||
{
|
||||
const GpuMat_<uchar>& src1 = (const GpuMat_<uchar>&) _src1;
|
||||
const GpuMat_<uchar>& src2 = (const GpuMat_<uchar>&) _src2;
|
||||
GpuMat_<int>& dst = (GpuMat_<int>&) _dst;
|
||||
|
||||
gridCalcSum(abs_(cvt_<int>(src1) - cvt_<int>(src2)), dst, stream);
|
||||
}
|
||||
|
||||
void normDiffL2(const GpuMat& _src1, const GpuMat& _src2, GpuMat& _dst, Stream& stream)
|
||||
{
|
||||
const GpuMat_<uchar>& src1 = (const GpuMat_<uchar>&) _src1;
|
||||
const GpuMat_<uchar>& src2 = (const GpuMat_<uchar>&) _src2;
|
||||
GpuMat_<double>& dst = (GpuMat_<double>&) _dst;
|
||||
|
||||
BufferPool pool(stream);
|
||||
GpuMat_<double> buf(1, 1, pool.getAllocator());
|
||||
|
||||
gridCalcSum(sqr_(cvt_<double>(src1) - cvt_<double>(src2)), buf, stream);
|
||||
gridTransformUnary(buf, dst, sqrt_func<double>(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::calcNormDiff(InputArray _src1, InputArray _src2, OutputArray _dst, int normType, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src1, const GpuMat& _src2, GpuMat& _dst, Stream& stream);
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
0, normDiffInf, normDiffL1, 0, normDiffL2
|
||||
};
|
||||
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
|
||||
CV_Assert( src1.type() == CV_8UC1 );
|
||||
CV_Assert( src1.size() == src2.size() && src1.type() == src2.type() );
|
||||
CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, 1, 1, normType == NORM_L2 ? CV_64FC1 : CV_32SC1, stream);
|
||||
|
||||
const func_t func = funcs[normType];
|
||||
func(src1, src2, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
double cv::cuda::norm(InputArray _src1, InputArray _src2, int normType)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem dst;
|
||||
calcNormDiff(_src1, _src2, dst, normType, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
double val;
|
||||
dst.createMatHeader().convertTo(Mat(1, 1, CV_64FC1, &val), CV_64F);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
namespace cv { namespace cuda { namespace device {
|
||||
|
||||
void normL2(cv::InputArray _src, cv::OutputArray _dst, cv::InputArray _mask, Stream& stream);
|
||||
|
||||
}}}
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename R>
|
||||
void normL2Impl(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&) _src;
|
||||
GpuMat_<R>& dst = (GpuMat_<R>&) _dst;
|
||||
|
||||
BufferPool pool(stream);
|
||||
GpuMat_<double> buf(1, 1, pool.getAllocator());
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
gridCalcSum(sqr_(cvt_<double>(src)), buf, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
gridCalcSum(sqr_(cvt_<double>(src)), buf, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
|
||||
gridTransformUnary(buf, dst, sqrt_func<double>(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::device::normL2(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX] =
|
||||
{
|
||||
normL2Impl<uchar, double>,
|
||||
normL2Impl<schar, double>,
|
||||
normL2Impl<ushort, double>,
|
||||
normL2Impl<short, double>,
|
||||
normL2Impl<int, double>,
|
||||
normL2Impl<float, double>,
|
||||
normL2Impl<double, double>
|
||||
};
|
||||
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
const GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
CV_Assert( src.channels() == 1 );
|
||||
CV_Assert( mask.empty() || (mask.size() == src.size() && mask.type() == CV_8U) );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, 1, 1, CV_64FC1, stream);
|
||||
|
||||
const func_t func = funcs[src.depth()];
|
||||
CV_Assert(func);
|
||||
func(src, mask, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,296 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T, typename R, typename I>
|
||||
struct ConvertorMinMax : unary_function<T, R>
|
||||
{
|
||||
typedef typename LargerType<T, R>::type larger_type1;
|
||||
typedef typename LargerType<larger_type1, I>::type larger_type2;
|
||||
typedef typename LargerType<larger_type2, float>::type scalar_type;
|
||||
|
||||
scalar_type dmin, dmax;
|
||||
const I* minMaxVals;
|
||||
|
||||
__device__ R operator ()(typename TypeTraits<T>::parameter_type src) const
|
||||
{
|
||||
const scalar_type smin = minMaxVals[0];
|
||||
const scalar_type smax = minMaxVals[1];
|
||||
|
||||
const scalar_type scale = (dmax - dmin) * (smax - smin > numeric_limits<scalar_type>::epsilon() ? 1.0 / (smax - smin) : 0.0);
|
||||
const scalar_type shift = dmin - smin * scale;
|
||||
|
||||
return cudev::saturate_cast<R>(scale * src + shift);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename R, typename I>
|
||||
void normalizeMinMax(const GpuMat& _src, GpuMat& _dst, double a, double b, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&)_src;
|
||||
GpuMat_<R>& dst = (GpuMat_<R>&)_dst;
|
||||
|
||||
BufferPool pool(stream);
|
||||
GpuMat_<I> minMaxVals(1, 2, pool.getAllocator());
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
gridFindMinMaxVal(src, minMaxVals, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
gridFindMinMaxVal(src, minMaxVals, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
|
||||
ConvertorMinMax<T, R, I> cvt;
|
||||
cvt.dmin = std::min(a, b);
|
||||
cvt.dmax = std::max(a, b);
|
||||
cvt.minMaxVals = minMaxVals[0];
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
gridTransformUnary(src, dst, cvt, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
dst.setTo(Scalar::all(0), stream);
|
||||
gridTransformUnary(src, dst, cvt, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename R, typename I, bool normL2>
|
||||
struct ConvertorNorm : unary_function<T, R>
|
||||
{
|
||||
typedef typename LargerType<T, R>::type larger_type1;
|
||||
typedef typename LargerType<larger_type1, I>::type larger_type2;
|
||||
typedef typename LargerType<larger_type2, float>::type scalar_type;
|
||||
|
||||
scalar_type a;
|
||||
const I* normVal;
|
||||
|
||||
__device__ R operator ()(typename TypeTraits<T>::parameter_type src) const
|
||||
{
|
||||
sqrt_func<scalar_type> sqrt;
|
||||
|
||||
scalar_type scale = normL2 ? sqrt(*normVal) : *normVal;
|
||||
scale = scale > numeric_limits<scalar_type>::epsilon() ? a / scale : 0.0;
|
||||
|
||||
return cudev::saturate_cast<R>(scale * src);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename R, typename I>
|
||||
void normalizeNorm(const GpuMat& _src, GpuMat& _dst, double a, int normType, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&)_src;
|
||||
GpuMat_<R>& dst = (GpuMat_<R>&)_dst;
|
||||
|
||||
BufferPool pool(stream);
|
||||
GpuMat_<I> normVal(1, 1, pool.getAllocator());
|
||||
|
||||
if (normType == NORM_L1)
|
||||
{
|
||||
if (mask.empty())
|
||||
{
|
||||
gridCalcSum(abs_(cvt_<I>(src)), normVal, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
gridCalcSum(abs_(cvt_<I>(src)), normVal, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
else if (normType == NORM_L2)
|
||||
{
|
||||
if (mask.empty())
|
||||
{
|
||||
gridCalcSum(sqr_(cvt_<I>(src)), normVal, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
gridCalcSum(sqr_(cvt_<I>(src)), normVal, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
else // NORM_INF
|
||||
{
|
||||
if (mask.empty())
|
||||
{
|
||||
gridFindMaxVal(abs_(cvt_<I>(src)), normVal, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
gridFindMaxVal(abs_(cvt_<I>(src)), normVal, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
|
||||
if (normType == NORM_L2)
|
||||
{
|
||||
ConvertorNorm<T, R, I, true> cvt;
|
||||
cvt.a = a;
|
||||
cvt.normVal = normVal[0];
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
gridTransformUnary(src, dst, cvt, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
dst.setTo(Scalar::all(0), stream);
|
||||
gridTransformUnary(src, dst, cvt, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConvertorNorm<T, R, I, false> cvt;
|
||||
cvt.a = a;
|
||||
cvt.normVal = normVal[0];
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
gridTransformUnary(src, dst, cvt, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
dst.setTo(Scalar::all(0), stream);
|
||||
gridTransformUnary(src, dst, cvt, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void cv::cuda::normalize(InputArray _src, OutputArray _dst, double a, double b, int normType, int dtype, InputArray _mask, Stream& stream)
|
||||
{
|
||||
typedef void (*func_minmax_t)(const GpuMat& _src, GpuMat& _dst, double a, double b, const GpuMat& mask, Stream& stream);
|
||||
typedef void (*func_norm_t)(const GpuMat& _src, GpuMat& _dst, double a, int normType, const GpuMat& mask, Stream& stream);
|
||||
|
||||
static const func_minmax_t funcs_minmax[CV_DEPTH_MAX] =
|
||||
{
|
||||
normalizeMinMax<uchar, float, float>,
|
||||
normalizeMinMax<schar, float, float>,
|
||||
normalizeMinMax<ushort, float, float>,
|
||||
normalizeMinMax<short, float, float>,
|
||||
normalizeMinMax<int, float, float>,
|
||||
normalizeMinMax<float, float, float>,
|
||||
normalizeMinMax<double, double, double>
|
||||
};
|
||||
|
||||
static const func_norm_t funcs_norm[CV_DEPTH_MAX] =
|
||||
{
|
||||
normalizeNorm<uchar, float, float>,
|
||||
normalizeNorm<schar, float, float>,
|
||||
normalizeNorm<ushort, float, float>,
|
||||
normalizeNorm<short, float, float>,
|
||||
normalizeNorm<int, float, float>,
|
||||
normalizeNorm<float, float, float>,
|
||||
normalizeNorm<double, double, double>
|
||||
};
|
||||
|
||||
CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_MINMAX );
|
||||
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
const GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
CV_Assert( src.channels() == 1 );
|
||||
CV_Assert( mask.empty() || (mask.size() == src.size() && mask.type() == CV_8U) );
|
||||
|
||||
if (dtype < 0)
|
||||
{
|
||||
dtype = _dst.fixedType() ? _dst.type() : src.type();
|
||||
}
|
||||
dtype = CV_MAT_DEPTH(dtype);
|
||||
|
||||
const int src_depth = src.depth();
|
||||
const int tmp_depth = src_depth <= CV_32F ? CV_32F : src_depth;
|
||||
|
||||
GpuMat dst;
|
||||
if (dtype == tmp_depth)
|
||||
{
|
||||
_dst.create(src.size(), tmp_depth);
|
||||
dst = getOutputMat(_dst, src.size(), tmp_depth, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferPool pool(stream);
|
||||
dst = pool.getBuffer(src.size(), tmp_depth);
|
||||
}
|
||||
|
||||
if (normType == NORM_MINMAX)
|
||||
{
|
||||
const func_minmax_t func = funcs_minmax[src_depth];
|
||||
CV_Assert(func);
|
||||
func(src, dst, a, b, mask, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
const func_norm_t func = funcs_norm[src_depth];
|
||||
CV_Assert(func);
|
||||
func(src, dst, a, normType, mask, stream);
|
||||
}
|
||||
|
||||
if (dtype == tmp_depth)
|
||||
{
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
dst.convertTo(_dst, dtype, stream);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,396 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
//do not use implicit cv::cuda to avoid clash of tuples from ::cuda::std
|
||||
/*using namespace cv;
|
||||
using namespace cv::cuda;*/
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void cv::cuda::magnitude(InputArray _x, InputArray _y, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat x = getInputMat(_x, stream);
|
||||
GpuMat y = getInputMat(_y, stream);
|
||||
|
||||
CV_Assert( x.depth() == CV_32F );
|
||||
CV_Assert( y.type() == x.type() && y.size() == x.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, x.size(), CV_32FC1, stream);
|
||||
|
||||
gridTransformBinary(globPtr<float>(x), globPtr<float>(y), globPtr<float>(dst), magnitude_func<float>(), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::magnitudeSqr(InputArray _x, InputArray _y, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat x = getInputMat(_x, stream);
|
||||
GpuMat y = getInputMat(_y, stream);
|
||||
|
||||
CV_Assert( x.depth() == CV_32F );
|
||||
CV_Assert( y.type() == x.type() && y.size() == x.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, x.size(), CV_32FC1, stream);
|
||||
|
||||
gridTransformBinary(globPtr<float>(x), globPtr<float>(y), globPtr<float>(dst), magnitude_sqr_func<float>(), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::phase(InputArray _x, InputArray _y, OutputArray _dst, bool angleInDegrees, Stream& stream)
|
||||
{
|
||||
GpuMat x = getInputMat(_x, stream);
|
||||
GpuMat y = getInputMat(_y, stream);
|
||||
|
||||
CV_Assert( x.depth() == CV_32F );
|
||||
CV_Assert( y.type() == x.type() && y.size() == x.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, x.size(), CV_32FC1, stream);
|
||||
|
||||
if (angleInDegrees)
|
||||
gridTransformBinary(globPtr<float>(x), globPtr<float>(y), globPtr<float>(dst), direction_func<float, true>(), stream);
|
||||
else
|
||||
gridTransformBinary(globPtr<float>(x), globPtr<float>(y), globPtr<float>(dst), direction_func<float, false>(), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::phase(InputArray _xy, OutputArray _dst, bool angleInDegrees, Stream& stream)
|
||||
{
|
||||
GpuMat xy = getInputMat(_xy, stream);
|
||||
|
||||
CV_Assert( xy.type() == CV_32FC2 );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, xy.size(), CV_32FC1, stream);
|
||||
|
||||
if (angleInDegrees)
|
||||
gridTransformUnary(globPtr<float2>(xy), globPtr<float>(dst), direction_interleaved_func<float2, true>(), stream);
|
||||
else
|
||||
gridTransformUnary(globPtr<float2>(xy), globPtr<float>(dst), direction_interleaved_func<float2, false>(), stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::cartToPolar(InputArray _x, InputArray _y, OutputArray _mag, OutputArray _angle, bool angleInDegrees, Stream& stream)
|
||||
{
|
||||
GpuMat x = getInputMat(_x, stream);
|
||||
GpuMat y = getInputMat(_y, stream);
|
||||
|
||||
CV_Assert( x.depth() == CV_32F );
|
||||
CV_Assert( y.type() == x.type() && y.size() == x.size() );
|
||||
|
||||
GpuMat mag = getOutputMat(_mag, x.size(), CV_32FC1, stream);
|
||||
GpuMat angle = getOutputMat(_angle, x.size(), CV_32FC1, stream);
|
||||
|
||||
GpuMat_<float> xc(x);
|
||||
GpuMat_<float> yc(y);
|
||||
GpuMat_<float> magc(mag);
|
||||
GpuMat_<float> anglec(angle);
|
||||
|
||||
if (angleInDegrees)
|
||||
gridTransformBinary(xc, yc, magc, anglec, magnitude_func<float>(), direction_func<float, true>(), stream);
|
||||
else
|
||||
gridTransformBinary(xc, yc, magc, anglec, magnitude_func<float>(), direction_func<float, false>(), stream);
|
||||
|
||||
syncOutput(mag, _mag, stream);
|
||||
syncOutput(angle, _angle, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::cartToPolar(InputArray _xy, OutputArray _mag, OutputArray _angle, bool angleInDegrees, Stream& stream)
|
||||
{
|
||||
GpuMat xy = getInputMat(_xy, stream);
|
||||
|
||||
CV_Assert( xy.type() == CV_32FC2 );
|
||||
|
||||
GpuMat mag = getOutputMat(_mag, xy.size(), CV_32FC1, stream);
|
||||
GpuMat angle = getOutputMat(_angle, xy.size(), CV_32FC1, stream);
|
||||
|
||||
GpuMat_<float> magc(mag);
|
||||
GpuMat_<float> anglec(angle);
|
||||
|
||||
gridTransformUnary(globPtr<float2>(xy), globPtr<float>(magc), magnitude_interleaved_func<float2>(), stream);
|
||||
|
||||
if (angleInDegrees)
|
||||
{
|
||||
gridTransformUnary(globPtr<float2>(xy), globPtr<float>(anglec), direction_interleaved_func<float2, true>(), stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
gridTransformUnary(globPtr<float2>(xy), globPtr<float>(anglec), direction_interleaved_func<float2, false>(), stream);
|
||||
}
|
||||
|
||||
syncOutput(mag, _mag, stream);
|
||||
syncOutput(angle, _angle, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::cartToPolar(InputArray _xy, OutputArray _magAngle, bool angleInDegrees, Stream& stream)
|
||||
{
|
||||
GpuMat xy = getInputMat(_xy, stream);
|
||||
|
||||
CV_Assert( xy.type() == CV_32FC2 );
|
||||
|
||||
GpuMat magAngle = getOutputMat(_magAngle, xy.size(), CV_32FC2, stream);
|
||||
|
||||
if (angleInDegrees)
|
||||
{
|
||||
gridTransformUnary(globPtr<float2>(xy),
|
||||
globPtr<float2>(magAngle),
|
||||
magnitude_direction_interleaved_func<float2, true>(),
|
||||
stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
gridTransformUnary(globPtr<float2>(xy),
|
||||
globPtr<float2>(magAngle),
|
||||
magnitude_direction_interleaved_func<float2, false>(),
|
||||
stream);
|
||||
}
|
||||
|
||||
syncOutput(magAngle, _magAngle, stream);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T> struct sincos_op
|
||||
{
|
||||
__device__ __forceinline__ void operator()(T a, T *sptr, T *cptr) const
|
||||
{
|
||||
::sincos(a, sptr, cptr);
|
||||
}
|
||||
};
|
||||
template <> struct sincos_op<float>
|
||||
{
|
||||
__device__ __forceinline__ void operator()(float a, float *sptr, float *cptr) const
|
||||
{
|
||||
::sincosf(a, sptr, cptr);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, bool useMag>
|
||||
__global__ void polarToCartImpl_(const PtrStep<T> mag, const PtrStepSz<T> angle, PtrStep<T> xmat, PtrStep<T> ymat, const T scale)
|
||||
{
|
||||
const int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
const int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
if (x >= angle.cols || y >= angle.rows)
|
||||
return;
|
||||
|
||||
const T mag_val = useMag ? mag(y, x) : static_cast<T>(1.0);
|
||||
const T angle_val = angle(y, x);
|
||||
|
||||
T sin_a, cos_a;
|
||||
sincos_op<T> op;
|
||||
op(scale * angle_val, &sin_a, &cos_a);
|
||||
|
||||
xmat(y, x) = mag_val * cos_a;
|
||||
ymat(y, x) = mag_val * sin_a;
|
||||
}
|
||||
|
||||
template <typename T, bool useMag>
|
||||
__global__ void polarToCartDstInterleavedImpl_(const PtrStep<T> mag, const PtrStepSz<T> angle, PtrStep<typename MakeVec<T, 2>::type > xymat, const T scale)
|
||||
{
|
||||
typedef typename MakeVec<T, 2>::type T2;
|
||||
const int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
const int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
if (x >= angle.cols || y >= angle.rows)
|
||||
return;
|
||||
|
||||
const T mag_val = useMag ? mag(y, x) : static_cast<T>(1.0);
|
||||
const T angle_val = angle(y, x);
|
||||
|
||||
T sin_a, cos_a;
|
||||
sincos_op<T> op;
|
||||
op(scale * angle_val, &sin_a, &cos_a);
|
||||
|
||||
const T2 xy = {mag_val * cos_a, mag_val * sin_a};
|
||||
xymat(y, x) = xy;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__global__ void polarToCartInterleavedImpl_(const PtrStepSz<typename MakeVec<T, 2>::type > magAngle, PtrStep<typename MakeVec<T, 2>::type > xymat, const T scale)
|
||||
{
|
||||
typedef typename MakeVec<T, 2>::type T2;
|
||||
const int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
const int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
if (x >= magAngle.cols || y >= magAngle.rows)
|
||||
return;
|
||||
|
||||
const T2 magAngle_val = magAngle(y, x);
|
||||
const T mag_val = magAngle_val.x;
|
||||
const T angle_val = magAngle_val.y;
|
||||
|
||||
T sin_a, cos_a;
|
||||
sincos_op<T> op;
|
||||
op(scale * angle_val, &sin_a, &cos_a);
|
||||
|
||||
const T2 xy = {mag_val * cos_a, mag_val * sin_a};
|
||||
xymat(y, x) = xy;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void polarToCartImpl(const GpuMat& mag, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, cudaStream_t& stream)
|
||||
{
|
||||
const dim3 block(32, 8);
|
||||
const dim3 grid(divUp(angle.cols, block.x), divUp(angle.rows, block.y));
|
||||
|
||||
const T scale = angleInDegrees ? static_cast<T>(CV_PI / 180.0) : static_cast<T>(1.0);
|
||||
|
||||
if (mag.empty())
|
||||
polarToCartImpl_<T, false> <<<grid, block, 0, stream >>>(mag, angle, x, y, scale);
|
||||
else
|
||||
polarToCartImpl_<T, true> <<<grid, block, 0, stream >>>(mag, angle, x, y, scale);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void polarToCartDstInterleavedImpl(const GpuMat& mag, const GpuMat& angle, GpuMat& xy, bool angleInDegrees, cudaStream_t& stream)
|
||||
{
|
||||
typedef typename MakeVec<T, 2>::type T2;
|
||||
|
||||
const dim3 block(32, 8);
|
||||
const dim3 grid(divUp(angle.cols, block.x), divUp(angle.rows, block.y));
|
||||
|
||||
const T scale = angleInDegrees ? static_cast<T>(CV_PI / 180.0) : static_cast<T>(1.0);
|
||||
|
||||
if (mag.empty())
|
||||
polarToCartDstInterleavedImpl_<T, false> <<<grid, block, 0, stream >>>(mag, angle, xy, scale);
|
||||
else
|
||||
polarToCartDstInterleavedImpl_<T, true> <<<grid, block, 0, stream >>>(mag, angle, xy, scale);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void polarToCartInterleavedImpl(const GpuMat& magAngle, GpuMat& xy, bool angleInDegrees, cudaStream_t& stream)
|
||||
{
|
||||
typedef typename MakeVec<T, 2>::type T2;
|
||||
|
||||
const dim3 block(32, 8);
|
||||
const dim3 grid(divUp(magAngle.cols, block.x), divUp(magAngle.rows, block.y));
|
||||
|
||||
const T scale = angleInDegrees ? static_cast<T>(CV_PI / 180.0) : static_cast<T>(1.0);
|
||||
|
||||
polarToCartInterleavedImpl_<T> <<<grid, block, 0, stream >>>(magAngle, xy, scale);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::polarToCart(InputArray _mag, InputArray _angle, OutputArray _x, OutputArray _y, bool angleInDegrees, Stream& _stream)
|
||||
{
|
||||
typedef void(*func_t)(const GpuMat& mag, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, cudaStream_t& stream);
|
||||
static const func_t funcs[7] = { 0, 0, 0, 0, 0, polarToCartImpl<float>, polarToCartImpl<double> };
|
||||
|
||||
GpuMat mag = getInputMat(_mag, _stream);
|
||||
GpuMat angle = getInputMat(_angle, _stream);
|
||||
|
||||
CV_Assert(angle.depth() == CV_32F || angle.depth() == CV_64F);
|
||||
CV_Assert( mag.empty() || (mag.type() == angle.type() && mag.size() == angle.size()) );
|
||||
|
||||
GpuMat x = getOutputMat(_x, angle.size(), CV_MAKETYPE(angle.depth(), 1), _stream);
|
||||
GpuMat y = getOutputMat(_y, angle.size(), CV_MAKETYPE(angle.depth(), 1), _stream);
|
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
funcs[angle.depth()](mag, angle, x, y, angleInDegrees, stream);
|
||||
CV_CUDEV_SAFE_CALL( cudaGetLastError() );
|
||||
|
||||
syncOutput(x, _x, _stream);
|
||||
syncOutput(y, _y, _stream);
|
||||
|
||||
if (stream == 0)
|
||||
CV_CUDEV_SAFE_CALL( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
void cv::cuda::polarToCart(InputArray _mag, InputArray _angle, OutputArray _xy, bool angleInDegrees, Stream& _stream)
|
||||
{
|
||||
typedef void(*func_t)(const GpuMat& mag, const GpuMat& angle, GpuMat& xy, bool angleInDegrees, cudaStream_t& stream);
|
||||
static const func_t funcs[7] = { 0, 0, 0, 0, 0, polarToCartDstInterleavedImpl<float>, polarToCartDstInterleavedImpl<double> };
|
||||
|
||||
GpuMat mag = getInputMat(_mag, _stream);
|
||||
GpuMat angle = getInputMat(_angle, _stream);
|
||||
|
||||
CV_Assert(angle.depth() == CV_32F || angle.depth() == CV_64F);
|
||||
CV_Assert( mag.empty() || (mag.type() == angle.type() && mag.size() == angle.size()) );
|
||||
|
||||
GpuMat xy = getOutputMat(_xy, angle.size(), CV_MAKETYPE(angle.depth(), 2), _stream);
|
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
funcs[angle.depth()](mag, angle, xy, angleInDegrees, stream);
|
||||
CV_CUDEV_SAFE_CALL( cudaGetLastError() );
|
||||
|
||||
syncOutput(xy, _xy, _stream);
|
||||
|
||||
if (stream == 0)
|
||||
CV_CUDEV_SAFE_CALL( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
void cv::cuda::polarToCart(InputArray _magAngle, OutputArray _xy, bool angleInDegrees, Stream& _stream)
|
||||
{
|
||||
typedef void(*func_t)(const GpuMat& magAngle, GpuMat& xy, bool angleInDegrees, cudaStream_t& stream);
|
||||
static const func_t funcs[7] = { 0, 0, 0, 0, 0, polarToCartInterleavedImpl<float>, polarToCartInterleavedImpl<double> };
|
||||
|
||||
GpuMat magAngle = getInputMat(_magAngle, _stream);
|
||||
|
||||
CV_Assert(magAngle.type() == CV_32FC2 || magAngle.type() == CV_64FC2);
|
||||
|
||||
GpuMat xy = getOutputMat(_xy, magAngle.size(), magAngle.type(), _stream);
|
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
funcs[magAngle.depth()](magAngle, xy, angleInDegrees, stream);
|
||||
CV_CUDEV_SAFE_CALL( cudaGetLastError() );
|
||||
|
||||
syncOutput(xy, _xy, _stream);
|
||||
|
||||
if (stream == 0)
|
||||
CV_CUDEV_SAFE_CALL( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,301 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename S, typename D>
|
||||
void reduceToRowImpl(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&) _src;
|
||||
GpuMat_<D>& dst = (GpuMat_<D>&) _dst;
|
||||
|
||||
switch (reduceOp)
|
||||
{
|
||||
case cv::REDUCE_SUM:
|
||||
gridReduceToRow< Sum<S> >(src, dst, stream);
|
||||
break;
|
||||
|
||||
case cv::REDUCE_AVG:
|
||||
gridReduceToRow< Avg<S> >(src, dst, stream);
|
||||
break;
|
||||
|
||||
case cv::REDUCE_MIN:
|
||||
gridReduceToRow< Min<S> >(src, dst, stream);
|
||||
break;
|
||||
|
||||
case cv::REDUCE_MAX:
|
||||
gridReduceToRow< Max<S> >(src, dst, stream);
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T, typename S, typename D>
|
||||
void reduceToColumnImpl_(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream)
|
||||
{
|
||||
const GpuMat_<T>& src = (const GpuMat_<T>&) _src;
|
||||
GpuMat_<D>& dst = (GpuMat_<D>&) _dst;
|
||||
|
||||
switch (reduceOp)
|
||||
{
|
||||
case cv::REDUCE_SUM:
|
||||
gridReduceToColumn< Sum<S> >(src, dst, stream);
|
||||
break;
|
||||
|
||||
case cv::REDUCE_AVG:
|
||||
gridReduceToColumn< Avg<S> >(src, dst, stream);
|
||||
break;
|
||||
|
||||
case cv::REDUCE_MIN:
|
||||
gridReduceToColumn< Min<S> >(src, dst, stream);
|
||||
break;
|
||||
|
||||
case cv::REDUCE_MAX:
|
||||
gridReduceToColumn< Max<S> >(src, dst, stream);
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T, typename S, typename D>
|
||||
void reduceToColumnImpl(const GpuMat& src, GpuMat& dst, int reduceOp, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int reduceOp, Stream& stream);
|
||||
static const func_t funcs[4] =
|
||||
{
|
||||
reduceToColumnImpl_<T, S, D>,
|
||||
reduceToColumnImpl_<typename MakeVec<T, 2>::type, typename MakeVec<S, 2>::type, typename MakeVec<D, 2>::type>,
|
||||
reduceToColumnImpl_<typename MakeVec<T, 3>::type, typename MakeVec<S, 3>::type, typename MakeVec<D, 3>::type>,
|
||||
reduceToColumnImpl_<typename MakeVec<T, 4>::type, typename MakeVec<S, 4>::type, typename MakeVec<D, 4>::type>
|
||||
};
|
||||
|
||||
funcs[src.channels() - 1](src, dst, reduceOp, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::reduce(InputArray _src, OutputArray _dst, int dim, int reduceOp, int dtype, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.channels() <= 4 );
|
||||
CV_Assert( dim == 0 || dim == 1 );
|
||||
CV_Assert( reduceOp == REDUCE_SUM || reduceOp == REDUCE_AVG || reduceOp == REDUCE_MAX || reduceOp == REDUCE_MIN );
|
||||
|
||||
if (dtype < 0)
|
||||
dtype = src.depth();
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, dim == 0 ? 1 : src.rows, dim == 0 ? src.cols : 1, CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src.channels()), stream);
|
||||
|
||||
if (dim == 0)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] =
|
||||
{
|
||||
{
|
||||
reduceToRowImpl<uchar, int, uchar>,
|
||||
0 /*reduceToRowImpl<uchar, int, schar>*/,
|
||||
0 /*reduceToRowImpl<uchar, int, ushort>*/,
|
||||
0 /*reduceToRowImpl<uchar, int, short>*/,
|
||||
reduceToRowImpl<uchar, int, int>,
|
||||
reduceToRowImpl<uchar, float, float>,
|
||||
reduceToRowImpl<uchar, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToRowImpl<schar, int, uchar>*/,
|
||||
0 /*reduceToRowImpl<schar, int, schar>*/,
|
||||
0 /*reduceToRowImpl<schar, int, ushort>*/,
|
||||
0 /*reduceToRowImpl<schar, int, short>*/,
|
||||
0 /*reduceToRowImpl<schar, int, int>*/,
|
||||
0 /*reduceToRowImpl<schar, float, float>*/,
|
||||
0 /*reduceToRowImpl<schar, double, double>*/
|
||||
},
|
||||
{
|
||||
0 /*reduceToRowImpl<ushort, int, uchar>*/,
|
||||
0 /*reduceToRowImpl<ushort, int, schar>*/,
|
||||
reduceToRowImpl<ushort, int, ushort>,
|
||||
0 /*reduceToRowImpl<ushort, int, short>*/,
|
||||
reduceToRowImpl<ushort, int, int>,
|
||||
reduceToRowImpl<ushort, float, float>,
|
||||
reduceToRowImpl<ushort, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToRowImpl<short, int, uchar>*/,
|
||||
0 /*reduceToRowImpl<short, int, schar>*/,
|
||||
0 /*reduceToRowImpl<short, int, ushort>*/,
|
||||
reduceToRowImpl<short, int, short>,
|
||||
reduceToRowImpl<short, int, int>,
|
||||
reduceToRowImpl<short, float, float>,
|
||||
reduceToRowImpl<short, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToRowImpl<int, int, uchar>*/,
|
||||
0 /*reduceToRowImpl<int, int, schar>*/,
|
||||
0 /*reduceToRowImpl<int, int, ushort>*/,
|
||||
0 /*reduceToRowImpl<int, int, short>*/,
|
||||
reduceToRowImpl<int, int, int>,
|
||||
reduceToRowImpl<int, float, float>,
|
||||
reduceToRowImpl<int, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToRowImpl<float, float, uchar>*/,
|
||||
0 /*reduceToRowImpl<float, float, schar>*/,
|
||||
0 /*reduceToRowImpl<float, float, ushort>*/,
|
||||
0 /*reduceToRowImpl<float, float, short>*/,
|
||||
0 /*reduceToRowImpl<float, float, int>*/,
|
||||
reduceToRowImpl<float, float, float>,
|
||||
reduceToRowImpl<float, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToRowImpl<double, double, uchar>*/,
|
||||
0 /*reduceToRowImpl<double, double, schar>*/,
|
||||
0 /*reduceToRowImpl<double, double, ushort>*/,
|
||||
0 /*reduceToRowImpl<double, double, short>*/,
|
||||
0 /*reduceToRowImpl<double, double, int>*/,
|
||||
0 /*reduceToRowImpl<double, double, float>*/,
|
||||
reduceToRowImpl<double, double, double>
|
||||
}
|
||||
};
|
||||
|
||||
const func_t func = funcs[src.depth()][dst.depth()];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of input and output array formats");
|
||||
|
||||
GpuMat dst_cont = dst.reshape(1);
|
||||
func(src.reshape(1), dst_cont, reduceOp, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] =
|
||||
{
|
||||
{
|
||||
reduceToColumnImpl<uchar, int, uchar>,
|
||||
0 /*reduceToColumnImpl<uchar, int, schar>*/,
|
||||
0 /*reduceToColumnImpl<uchar, int, ushort>*/,
|
||||
0 /*reduceToColumnImpl<uchar, int, short>*/,
|
||||
reduceToColumnImpl<uchar, int, int>,
|
||||
reduceToColumnImpl<uchar, float, float>,
|
||||
reduceToColumnImpl<uchar, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToColumnImpl<schar, int, uchar>*/,
|
||||
0 /*reduceToColumnImpl<schar, int, schar>*/,
|
||||
0 /*reduceToColumnImpl<schar, int, ushort>*/,
|
||||
0 /*reduceToColumnImpl<schar, int, short>*/,
|
||||
0 /*reduceToColumnImpl<schar, int, int>*/,
|
||||
0 /*reduceToColumnImpl<schar, float, float>*/,
|
||||
0 /*reduceToColumnImpl<schar, double, double>*/
|
||||
},
|
||||
{
|
||||
0 /*reduceToColumnImpl<ushort, int, uchar>*/,
|
||||
0 /*reduceToColumnImpl<ushort, int, schar>*/,
|
||||
reduceToColumnImpl<ushort, int, ushort>,
|
||||
0 /*reduceToColumnImpl<ushort, int, short>*/,
|
||||
reduceToColumnImpl<ushort, int, int>,
|
||||
reduceToColumnImpl<ushort, float, float>,
|
||||
reduceToColumnImpl<ushort, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToColumnImpl<short, int, uchar>*/,
|
||||
0 /*reduceToColumnImpl<short, int, schar>*/,
|
||||
0 /*reduceToColumnImpl<short, int, ushort>*/,
|
||||
reduceToColumnImpl<short, int, short>,
|
||||
reduceToColumnImpl<short, int, int>,
|
||||
reduceToColumnImpl<short, float, float>,
|
||||
reduceToColumnImpl<short, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToColumnImpl<int, int, uchar>*/,
|
||||
0 /*reduceToColumnImpl<int, int, schar>*/,
|
||||
0 /*reduceToColumnImpl<int, int, ushort>*/,
|
||||
0 /*reduceToColumnImpl<int, int, short>*/,
|
||||
reduceToColumnImpl<int, int, int>,
|
||||
reduceToColumnImpl<int, float, float>,
|
||||
reduceToColumnImpl<int, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToColumnImpl<float, float, uchar>*/,
|
||||
0 /*reduceToColumnImpl<float, float, schar>*/,
|
||||
0 /*reduceToColumnImpl<float, float, ushort>*/,
|
||||
0 /*reduceToColumnImpl<float, float, short>*/,
|
||||
0 /*reduceToColumnImpl<float, float, int>*/,
|
||||
reduceToColumnImpl<float, float, float>,
|
||||
reduceToColumnImpl<float, double, double>
|
||||
},
|
||||
{
|
||||
0 /*reduceToColumnImpl<double, double, uchar>*/,
|
||||
0 /*reduceToColumnImpl<double, double, schar>*/,
|
||||
0 /*reduceToColumnImpl<double, double, ushort>*/,
|
||||
0 /*reduceToColumnImpl<double, double, short>*/,
|
||||
0 /*reduceToColumnImpl<double, double, int>*/,
|
||||
0 /*reduceToColumnImpl<double, double, float>*/,
|
||||
reduceToColumnImpl<double, double, double>
|
||||
}
|
||||
};
|
||||
|
||||
const func_t func = funcs[src.depth()][dst.depth()];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of input and output array formats");
|
||||
|
||||
func(src, dst, reduceOp, stream);
|
||||
}
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,253 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// merge
|
||||
|
||||
namespace
|
||||
{
|
||||
template <int cn, typename T> struct MergeFunc;
|
||||
|
||||
template <typename T> struct MergeFunc<2, T>
|
||||
{
|
||||
static void call(const GpuMat* src, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const std::array<GlobPtrSz<T>, 2> d_src = {globPtr<T>(src[0]), globPtr<T>(src[1])};
|
||||
gridMerge(d_src,
|
||||
globPtr<typename MakeVec<T, 2>::type>(dst),
|
||||
stream);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct MergeFunc<3, T>
|
||||
{
|
||||
static void call(const GpuMat* src, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const std::array<GlobPtrSz<T>, 3> d_src = {globPtr<T>(src[0]), globPtr<T>(src[1]), globPtr<T>(src[2])};
|
||||
gridMerge(d_src,
|
||||
globPtr<typename MakeVec<T, 3>::type>(dst),
|
||||
stream);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct MergeFunc<4, T>
|
||||
{
|
||||
static void call(const GpuMat* src, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const std::array<GlobPtrSz<T>, 4 > d_src = {globPtr<T>(src[0]), globPtr<T>(src[1]), globPtr<T>(src[2]), globPtr<T>(src[3])};
|
||||
gridMerge(d_src,
|
||||
globPtr<typename MakeVec<T, 4>::type>(dst),
|
||||
stream);
|
||||
}
|
||||
};
|
||||
|
||||
void mergeImpl(const GpuMat* src, size_t n, cv::OutputArray _dst, Stream& stream)
|
||||
{
|
||||
CV_Assert( src != 0 );
|
||||
CV_Assert( n > 0 && n <= 4 );
|
||||
|
||||
const int depth = src[0].depth();
|
||||
const cv::Size size = src[0].size();
|
||||
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
CV_Assert( src[i].size() == size );
|
||||
CV_Assert( src[i].depth() == depth );
|
||||
CV_Assert( src[i].channels() == 1 );
|
||||
}
|
||||
|
||||
if (n == 1)
|
||||
{
|
||||
src[0].copyTo(_dst, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat* src, GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[3][5] =
|
||||
{
|
||||
{MergeFunc<2, uchar>::call, MergeFunc<2, ushort>::call, MergeFunc<2, int>::call, 0, MergeFunc<2, double>::call},
|
||||
{MergeFunc<3, uchar>::call, MergeFunc<3, ushort>::call, MergeFunc<3, int>::call, 0, MergeFunc<3, double>::call},
|
||||
{MergeFunc<4, uchar>::call, MergeFunc<4, ushort>::call, MergeFunc<4, int>::call, 0, MergeFunc<4, double>::call}
|
||||
};
|
||||
|
||||
const int channels = static_cast<int>(n);
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, size, CV_MAKE_TYPE(depth, channels), stream);
|
||||
|
||||
const func_t func = funcs[channels - 2][CV_ELEM_SIZE(depth) / 2];
|
||||
|
||||
if (func == 0)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported channel count or data type");
|
||||
|
||||
func(src, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::merge(const GpuMat* src, size_t n, OutputArray dst, Stream& stream)
|
||||
{
|
||||
mergeImpl(src, n, dst, stream);
|
||||
}
|
||||
|
||||
|
||||
void cv::cuda::merge(const std::vector<GpuMat>& src, OutputArray dst, Stream& stream)
|
||||
{
|
||||
mergeImpl(&src[0], src.size(), dst, stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// split
|
||||
|
||||
namespace
|
||||
{
|
||||
template <int cn, typename T> struct SplitFunc;
|
||||
|
||||
template <typename T> struct SplitFunc<2, T>
|
||||
{
|
||||
static void call(const GpuMat& src, GpuMat* dst, Stream& stream)
|
||||
{
|
||||
GlobPtrSz<T> dstarr[2] =
|
||||
{
|
||||
globPtr<T>(dst[0]), globPtr<T>(dst[1])
|
||||
};
|
||||
|
||||
gridSplit(globPtr<typename MakeVec<T, 2>::type>(src), dstarr, stream);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct SplitFunc<3, T>
|
||||
{
|
||||
static void call(const GpuMat& src, GpuMat* dst, Stream& stream)
|
||||
{
|
||||
GlobPtrSz<T> dstarr[3] =
|
||||
{
|
||||
globPtr<T>(dst[0]), globPtr<T>(dst[1]), globPtr<T>(dst[2])
|
||||
};
|
||||
|
||||
gridSplit(globPtr<typename MakeVec<T, 3>::type>(src), dstarr, stream);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct SplitFunc<4, T>
|
||||
{
|
||||
static void call(const GpuMat& src, GpuMat* dst, Stream& stream)
|
||||
{
|
||||
GlobPtrSz<T> dstarr[4] =
|
||||
{
|
||||
globPtr<T>(dst[0]), globPtr<T>(dst[1]), globPtr<T>(dst[2]), globPtr<T>(dst[3])
|
||||
};
|
||||
|
||||
gridSplit(globPtr<typename MakeVec<T, 4>::type>(src), dstarr, stream);
|
||||
}
|
||||
};
|
||||
|
||||
void splitImpl(const GpuMat& src, GpuMat* dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, GpuMat* dst, Stream& stream);
|
||||
static const func_t funcs[3][5] =
|
||||
{
|
||||
{SplitFunc<2, uchar>::call, SplitFunc<2, ushort>::call, SplitFunc<2, int>::call, 0, SplitFunc<2, double>::call},
|
||||
{SplitFunc<3, uchar>::call, SplitFunc<3, ushort>::call, SplitFunc<3, int>::call, 0, SplitFunc<3, double>::call},
|
||||
{SplitFunc<4, uchar>::call, SplitFunc<4, ushort>::call, SplitFunc<4, int>::call, 0, SplitFunc<4, double>::call}
|
||||
};
|
||||
|
||||
CV_Assert( dst != 0 );
|
||||
|
||||
const int depth = src.depth();
|
||||
const int channels = src.channels();
|
||||
|
||||
CV_Assert( channels <= 4 );
|
||||
|
||||
if (channels == 0)
|
||||
return;
|
||||
|
||||
if (channels == 1)
|
||||
{
|
||||
src.copyTo(dst[0], stream);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < channels; ++i)
|
||||
dst[i].create(src.size(), depth);
|
||||
|
||||
const func_t func = funcs[channels - 2][CV_ELEM_SIZE(depth) / 2];
|
||||
|
||||
if (func == 0)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported channel count or data type");
|
||||
|
||||
func(src, dst, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::split(InputArray _src, GpuMat* dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
splitImpl(src, dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::split(InputArray _src, std::vector<GpuMat>& dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
dst.resize(src.channels());
|
||||
if (src.channels() > 0)
|
||||
splitImpl(src, &dst[0], stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,225 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void subMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& _stream, int);
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename D> struct SubOp1 : binary_function<T, T, D>
|
||||
{
|
||||
__device__ __forceinline__ D operator ()(T a, T b) const
|
||||
{
|
||||
return saturate_cast<D>(a - b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename D>
|
||||
void subMat_v1(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
if (mask.data)
|
||||
gridTransformBinary(globPtr<T>(src1), globPtr<T>(src2), globPtr<D>(dst), SubOp1<T, D>(), globPtr<uchar>(mask), stream);
|
||||
else
|
||||
gridTransformBinary(globPtr<T>(src1), globPtr<T>(src2), globPtr<D>(dst), SubOp1<T, D>(), stream);
|
||||
}
|
||||
|
||||
struct SubOp2 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vsub2(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
void subMat_v2(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 1;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, SubOp2(), stream);
|
||||
}
|
||||
|
||||
struct SubOp4 : binary_function<uint, uint, uint>
|
||||
{
|
||||
__device__ __forceinline__ uint operator ()(uint a, uint b) const
|
||||
{
|
||||
return vsub4(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
void subMat_v4(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
const int vcols = src1.cols >> 2;
|
||||
|
||||
GlobPtrSz<uint> src1_ = globPtr((uint*) src1.data, src1.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> src2_ = globPtr((uint*) src2.data, src2.step, src1.rows, vcols);
|
||||
GlobPtrSz<uint> dst_ = globPtr((uint*) dst.data, dst.step, src1.rows, vcols);
|
||||
|
||||
gridTransformBinary(src1_, src2_, dst_, SubOp4(), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void subMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, Stream& stream);
|
||||
static const func_t funcs[7][7] =
|
||||
{
|
||||
{
|
||||
subMat_v1<uchar, uchar>,
|
||||
subMat_v1<uchar, schar>,
|
||||
subMat_v1<uchar, ushort>,
|
||||
subMat_v1<uchar, short>,
|
||||
subMat_v1<uchar, int>,
|
||||
subMat_v1<uchar, float>,
|
||||
subMat_v1<uchar, double>
|
||||
},
|
||||
{
|
||||
subMat_v1<schar, uchar>,
|
||||
subMat_v1<schar, schar>,
|
||||
subMat_v1<schar, ushort>,
|
||||
subMat_v1<schar, short>,
|
||||
subMat_v1<schar, int>,
|
||||
subMat_v1<schar, float>,
|
||||
subMat_v1<schar, double>
|
||||
},
|
||||
{
|
||||
0 /*subMat_v1<ushort, uchar>*/,
|
||||
0 /*subMat_v1<ushort, schar>*/,
|
||||
subMat_v1<ushort, ushort>,
|
||||
subMat_v1<ushort, short>,
|
||||
subMat_v1<ushort, int>,
|
||||
subMat_v1<ushort, float>,
|
||||
subMat_v1<ushort, double>
|
||||
},
|
||||
{
|
||||
0 /*subMat_v1<short, uchar>*/,
|
||||
0 /*subMat_v1<short, schar>*/,
|
||||
subMat_v1<short, ushort>,
|
||||
subMat_v1<short, short>,
|
||||
subMat_v1<short, int>,
|
||||
subMat_v1<short, float>,
|
||||
subMat_v1<short, double>
|
||||
},
|
||||
{
|
||||
0 /*subMat_v1<int, uchar>*/,
|
||||
0 /*subMat_v1<int, schar>*/,
|
||||
0 /*subMat_v1<int, ushort>*/,
|
||||
0 /*subMat_v1<int, short>*/,
|
||||
subMat_v1<int, int>,
|
||||
subMat_v1<int, float>,
|
||||
subMat_v1<int, double>
|
||||
},
|
||||
{
|
||||
0 /*subMat_v1<float, uchar>*/,
|
||||
0 /*subMat_v1<float, schar>*/,
|
||||
0 /*subMat_v1<float, ushort>*/,
|
||||
0 /*subMat_v1<float, short>*/,
|
||||
0 /*subMat_v1<float, int>*/,
|
||||
subMat_v1<float, float>,
|
||||
subMat_v1<float, double>
|
||||
},
|
||||
{
|
||||
0 /*subMat_v1<double, uchar>*/,
|
||||
0 /*subMat_v1<double, schar>*/,
|
||||
0 /*subMat_v1<double, ushort>*/,
|
||||
0 /*subMat_v1<double, short>*/,
|
||||
0 /*subMat_v1<double, int>*/,
|
||||
0 /*subMat_v1<double, float>*/,
|
||||
subMat_v1<double, double>
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src1.depth();
|
||||
const int ddepth = dst.depth();
|
||||
|
||||
CV_Assert( sdepth <= CV_64F && ddepth <= CV_64F );
|
||||
|
||||
GpuMat src1_ = src1.reshape(1);
|
||||
GpuMat src2_ = src2.reshape(1);
|
||||
GpuMat dst_ = dst.reshape(1);
|
||||
|
||||
if (mask.empty() && (sdepth == CV_8U || sdepth == CV_16U) && ddepth == sdepth)
|
||||
{
|
||||
const intptr_t src1ptr = reinterpret_cast<intptr_t>(src1_.data);
|
||||
const intptr_t src2ptr = reinterpret_cast<intptr_t>(src2_.data);
|
||||
const intptr_t dstptr = reinterpret_cast<intptr_t>(dst_.data);
|
||||
|
||||
const bool isAllAligned = (src1ptr & 31) == 0 && (src2ptr & 31) == 0 && (dstptr & 31) == 0;
|
||||
|
||||
if (isAllAligned)
|
||||
{
|
||||
if (sdepth == CV_8U && (src1_.cols & 3) == 0)
|
||||
{
|
||||
subMat_v4(src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
else if (sdepth == CV_16U && (src1_.cols & 1) == 0)
|
||||
{
|
||||
subMat_v2(src1_, src2_, dst_, stream);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const func_t func = funcs[sdepth][ddepth];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src1_, src2_, dst_, mask, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,206 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/cuda/cuda_compat.hpp"
|
||||
|
||||
using namespace cv::cudev;
|
||||
|
||||
void subScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int);
|
||||
|
||||
namespace
|
||||
{
|
||||
using cv::cuda::device::compat::double4Compat;
|
||||
|
||||
template <typename SrcType, typename ScalarType, typename DstType> struct SubScalarOp : unary_function<SrcType, DstType>
|
||||
{
|
||||
ScalarType val;
|
||||
|
||||
__device__ __forceinline__ DstType operator ()(SrcType a) const
|
||||
{
|
||||
return saturate_cast<DstType>(saturate_cast<ScalarType>(a) - val);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename SrcType, typename ScalarType, typename DstType> struct SubScalarOpInv : unary_function<SrcType, DstType>
|
||||
{
|
||||
ScalarType val;
|
||||
|
||||
__device__ __forceinline__ DstType operator ()(SrcType a) const
|
||||
{
|
||||
return saturate_cast<DstType>(val - saturate_cast<ScalarType>(a));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename SrcType, typename ScalarDepth, typename DstType>
|
||||
void subScalarImpl(const GpuMat& src, cv::Scalar value, bool inv, GpuMat& dst, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<ScalarDepth, VecTraits<SrcType>::cn>::type ScalarType;
|
||||
|
||||
cv::Scalar_<ScalarDepth> value_ = value;
|
||||
|
||||
if (inv)
|
||||
{
|
||||
SubScalarOpInv<SrcType, ScalarType, DstType> op;
|
||||
op.val = VecTraits<ScalarType>::make(value_.val);
|
||||
|
||||
if (mask.data)
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, globPtr<uchar>(mask), stream);
|
||||
else
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
SubScalarOp<SrcType, ScalarType, DstType> op;
|
||||
op.val = VecTraits<ScalarType>::make(value_.val);
|
||||
|
||||
if (mask.data)
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, globPtr<uchar>(mask), stream);
|
||||
else
|
||||
gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<DstType>(dst), op, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, Stream& stream);
|
||||
static const func_t funcs[7][7][4] =
|
||||
{
|
||||
{
|
||||
{subScalarImpl<uchar, float, uchar>, subScalarImpl<uchar2, float, uchar2>, subScalarImpl<uchar3, float, uchar3>, subScalarImpl<uchar4, float, uchar4>},
|
||||
{subScalarImpl<uchar, float, schar>, subScalarImpl<uchar2, float, char2>, subScalarImpl<uchar3, float, char3>, subScalarImpl<uchar4, float, char4>},
|
||||
{subScalarImpl<uchar, float, ushort>, subScalarImpl<uchar2, float, ushort2>, subScalarImpl<uchar3, float, ushort3>, subScalarImpl<uchar4, float, ushort4>},
|
||||
{subScalarImpl<uchar, float, short>, subScalarImpl<uchar2, float, short2>, subScalarImpl<uchar3, float, short3>, subScalarImpl<uchar4, float, short4>},
|
||||
{subScalarImpl<uchar, float, int>, subScalarImpl<uchar2, float, int2>, subScalarImpl<uchar3, float, int3>, subScalarImpl<uchar4, float, int4>},
|
||||
{subScalarImpl<uchar, float, float>, subScalarImpl<uchar2, float, float2>, subScalarImpl<uchar3, float, float3>, subScalarImpl<uchar4, float, float4>},
|
||||
{subScalarImpl<uchar, double, double>, subScalarImpl<uchar2, double, double2>, subScalarImpl<uchar3, double, double3>, subScalarImpl<uchar4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{subScalarImpl<schar, float, uchar>, subScalarImpl<char2, float, uchar2>, subScalarImpl<char3, float, uchar3>, subScalarImpl<char4, float, uchar4>},
|
||||
{subScalarImpl<schar, float, schar>, subScalarImpl<char2, float, char2>, subScalarImpl<char3, float, char3>, subScalarImpl<char4, float, char4>},
|
||||
{subScalarImpl<schar, float, ushort>, subScalarImpl<char2, float, ushort2>, subScalarImpl<char3, float, ushort3>, subScalarImpl<char4, float, ushort4>},
|
||||
{subScalarImpl<schar, float, short>, subScalarImpl<char2, float, short2>, subScalarImpl<char3, float, short3>, subScalarImpl<char4, float, short4>},
|
||||
{subScalarImpl<schar, float, int>, subScalarImpl<char2, float, int2>, subScalarImpl<char3, float, int3>, subScalarImpl<char4, float, int4>},
|
||||
{subScalarImpl<schar, float, float>, subScalarImpl<char2, float, float2>, subScalarImpl<char3, float, float3>, subScalarImpl<char4, float, float4>},
|
||||
{subScalarImpl<schar, double, double>, subScalarImpl<char2, double, double2>, subScalarImpl<char3, double, double3>, subScalarImpl<char4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*subScalarImpl<ushort, float, uchar>*/, 0 /*subScalarImpl<ushort2, float, uchar2>*/, 0 /*subScalarImpl<ushort3, float, uchar3>*/, 0 /*subScalarImpl<ushort4, float, uchar4>*/},
|
||||
{0 /*subScalarImpl<ushort, float, schar>*/, 0 /*subScalarImpl<ushort2, float, char2>*/, 0 /*subScalarImpl<ushort3, float, char3>*/, 0 /*subScalarImpl<ushort4, float, char4>*/},
|
||||
{subScalarImpl<ushort, float, ushort>, subScalarImpl<ushort2, float, ushort2>, subScalarImpl<ushort3, float, ushort3>, subScalarImpl<ushort4, float, ushort4>},
|
||||
{subScalarImpl<ushort, float, short>, subScalarImpl<ushort2, float, short2>, subScalarImpl<ushort3, float, short3>, subScalarImpl<ushort4, float, short4>},
|
||||
{subScalarImpl<ushort, float, int>, subScalarImpl<ushort2, float, int2>, subScalarImpl<ushort3, float, int3>, subScalarImpl<ushort4, float, int4>},
|
||||
{subScalarImpl<ushort, float, float>, subScalarImpl<ushort2, float, float2>, subScalarImpl<ushort3, float, float3>, subScalarImpl<ushort4, float, float4>},
|
||||
{subScalarImpl<ushort, double, double>, subScalarImpl<ushort2, double, double2>, subScalarImpl<ushort3, double, double3>, subScalarImpl<ushort4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*subScalarImpl<short, float, uchar>*/, 0 /*subScalarImpl<short2, float, uchar2>*/, 0 /*subScalarImpl<short3, float, uchar3>*/, 0 /*subScalarImpl<short4, float, uchar4>*/},
|
||||
{0 /*subScalarImpl<short, float, schar>*/, 0 /*subScalarImpl<short2, float, char2>*/, 0 /*subScalarImpl<short3, float, char3>*/, 0 /*subScalarImpl<short4, float, char4>*/},
|
||||
{subScalarImpl<short, float, ushort>, subScalarImpl<short2, float, ushort2>, subScalarImpl<short3, float, ushort3>, subScalarImpl<short4, float, ushort4>},
|
||||
{subScalarImpl<short, float, short>, subScalarImpl<short2, float, short2>, subScalarImpl<short3, float, short3>, subScalarImpl<short4, float, short4>},
|
||||
{subScalarImpl<short, float, int>, subScalarImpl<short2, float, int2>, subScalarImpl<short3, float, int3>, subScalarImpl<short4, float, int4>},
|
||||
{subScalarImpl<short, float, float>, subScalarImpl<short2, float, float2>, subScalarImpl<short3, float, float3>, subScalarImpl<short4, float, float4>},
|
||||
{subScalarImpl<short, double, double>, subScalarImpl<short2, double, double2>, subScalarImpl<short3, double, double3>, subScalarImpl<short4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*subScalarImpl<int, float, uchar>*/, 0 /*subScalarImpl<int2, float, uchar2>*/, 0 /*subScalarImpl<int3, float, uchar3>*/, 0 /*subScalarImpl<int4, float, uchar4>*/},
|
||||
{0 /*subScalarImpl<int, float, schar>*/, 0 /*subScalarImpl<int2, float, char2>*/, 0 /*subScalarImpl<int3, float, char3>*/, 0 /*subScalarImpl<int4, float, char4>*/},
|
||||
{0 /*subScalarImpl<int, float, ushort>*/, 0 /*subScalarImpl<int2, float, ushort2>*/, 0 /*subScalarImpl<int3, float, ushort3>*/, 0 /*subScalarImpl<int4, float, ushort4>*/},
|
||||
{0 /*subScalarImpl<int, float, short>*/, 0 /*subScalarImpl<int2, float, short2>*/, 0 /*subScalarImpl<int3, float, short3>*/, 0 /*subScalarImpl<int4, float, short4>*/},
|
||||
{subScalarImpl<int, float, int>, subScalarImpl<int2, float, int2>, subScalarImpl<int3, float, int3>, subScalarImpl<int4, float, int4>},
|
||||
{subScalarImpl<int, float, float>, subScalarImpl<int2, float, float2>, subScalarImpl<int3, float, float3>, subScalarImpl<int4, float, float4>},
|
||||
{subScalarImpl<int, double, double>, subScalarImpl<int2, double, double2>, subScalarImpl<int3, double, double3>, subScalarImpl<int4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*subScalarImpl<float, float, uchar>*/, 0 /*subScalarImpl<float2, float, uchar2>*/, 0 /*subScalarImpl<float3, float, uchar3>*/, 0 /*subScalarImpl<float4, float, uchar4>*/},
|
||||
{0 /*subScalarImpl<float, float, schar>*/, 0 /*subScalarImpl<float2, float, char2>*/, 0 /*subScalarImpl<float3, float, char3>*/, 0 /*subScalarImpl<float4, float, char4>*/},
|
||||
{0 /*subScalarImpl<float, float, ushort>*/, 0 /*subScalarImpl<float2, float, ushort2>*/, 0 /*subScalarImpl<float3, float, ushort3>*/, 0 /*subScalarImpl<float4, float, ushort4>*/},
|
||||
{0 /*subScalarImpl<float, float, short>*/, 0 /*subScalarImpl<float2, float, short2>*/, 0 /*subScalarImpl<float3, float, short3>*/, 0 /*subScalarImpl<float4, float, short4>*/},
|
||||
{0 /*subScalarImpl<float, float, int>*/, 0 /*subScalarImpl<float2, float, int2>*/, 0 /*subScalarImpl<float3, float, int3>*/, 0 /*subScalarImpl<float4, float, int4>*/},
|
||||
{subScalarImpl<float, float, float>, subScalarImpl<float2, float, float2>, subScalarImpl<float3, float, float3>, subScalarImpl<float4, float, float4>},
|
||||
{subScalarImpl<float, double, double>, subScalarImpl<float2, double, double2>, subScalarImpl<float3, double, double3>, subScalarImpl<float4, double, double4Compat>}
|
||||
},
|
||||
{
|
||||
{0 /*subScalarImpl<double, double, uchar>*/, 0 /*subScalarImpl<double2, double, uchar2>*/, 0 /*subScalarImpl<double3, double, uchar3>*/, 0 /*subScalarImpl<double4, double, uchar4>*/},
|
||||
{0 /*subScalarImpl<double, double, schar>*/, 0 /*subScalarImpl<double2, double, char2>*/, 0 /*subScalarImpl<double3, double, char3>*/, 0 /*subScalarImpl<double4, double, char4>*/},
|
||||
{0 /*subScalarImpl<double, double, ushort>*/, 0 /*subScalarImpl<double2, double, ushort2>*/, 0 /*subScalarImpl<double3, double, ushort3>*/, 0 /*subScalarImpl<double4, double, ushort4>*/},
|
||||
{0 /*subScalarImpl<double, double, short>*/, 0 /*subScalarImpl<double2, double, short2>*/, 0 /*subScalarImpl<double3, double, short3>*/, 0 /*subScalarImpl<double4, double, short4>*/},
|
||||
{0 /*subScalarImpl<double, double, int>*/, 0 /*subScalarImpl<double2, double, int2>*/, 0 /*subScalarImpl<double3, double, int3>*/, 0 /*subScalarImpl<double4, double, int4>*/},
|
||||
{0 /*subScalarImpl<double, double, float>*/, 0 /*subScalarImpl<double2, double, float2>*/, 0 /*subScalarImpl<double3, double, float3>*/, 0 /*subScalarImpl<double4, double, float4>*/},
|
||||
{subScalarImpl<double, double, double>, subScalarImpl<double2, double, double2>, subScalarImpl<double3, double, double3>, subScalarImpl<double4Compat, double, double4Compat>}
|
||||
}
|
||||
};
|
||||
|
||||
const int sdepth = src.depth();
|
||||
const int ddepth = dst.depth();
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F && cn <= 4 );
|
||||
|
||||
const func_t func = funcs[sdepth][ddepth][cn - 1];
|
||||
|
||||
if (!func)
|
||||
CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
|
||||
|
||||
func(src, val, inv, dst, mask, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,242 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T, typename R, int cn>
|
||||
void sumImpl(const GpuMat& _src, GpuMat& _dst, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<T, cn>::type src_type;
|
||||
typedef typename MakeVec<R, cn>::type res_type;
|
||||
|
||||
const GpuMat_<src_type>& src = (const GpuMat_<src_type>&) _src;
|
||||
GpuMat_<res_type>& dst = (GpuMat_<res_type>&) _dst;
|
||||
|
||||
if (mask.empty())
|
||||
gridCalcSum(src, dst, stream);
|
||||
else
|
||||
gridCalcSum(src, dst, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
|
||||
template <typename T, typename R, int cn>
|
||||
void sumAbsImpl(const GpuMat& _src, GpuMat& _dst, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<T, cn>::type src_type;
|
||||
typedef typename MakeVec<R, cn>::type res_type;
|
||||
|
||||
const GpuMat_<src_type>& src = (const GpuMat_<src_type>&) _src;
|
||||
GpuMat_<res_type>& dst = (GpuMat_<res_type>&) _dst;
|
||||
|
||||
if (mask.empty())
|
||||
gridCalcSum(abs_(cvt_<res_type>(src)), dst, stream);
|
||||
else
|
||||
gridCalcSum(abs_(cvt_<res_type>(src)), dst, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
|
||||
template <typename T, typename R, int cn>
|
||||
void sumSqrImpl(const GpuMat& _src, GpuMat& _dst, const GpuMat& mask, Stream& stream)
|
||||
{
|
||||
typedef typename MakeVec<T, cn>::type src_type;
|
||||
typedef typename MakeVec<R, cn>::type res_type;
|
||||
|
||||
const GpuMat_<src_type>& src = (const GpuMat_<src_type>&) _src;
|
||||
GpuMat_<res_type>& dst = (GpuMat_<res_type>&) _dst;
|
||||
|
||||
if (mask.empty())
|
||||
gridCalcSum(sqr_(cvt_<res_type>(src)), dst, stream);
|
||||
else
|
||||
gridCalcSum(sqr_(cvt_<res_type>(src)), dst, globPtr<uchar>(mask), stream);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::calcSum(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, const GpuMat& mask, Stream& stream);
|
||||
static const func_t funcs[7][4] =
|
||||
{
|
||||
{sumImpl<uchar , double, 1>, sumImpl<uchar , double, 2>, sumImpl<uchar , double, 3>, sumImpl<uchar , double, 4>},
|
||||
{sumImpl<schar , double, 1>, sumImpl<schar , double, 2>, sumImpl<schar , double, 3>, sumImpl<schar , double, 4>},
|
||||
{sumImpl<ushort, double, 1>, sumImpl<ushort, double, 2>, sumImpl<ushort, double, 3>, sumImpl<ushort, double, 4>},
|
||||
{sumImpl<short , double, 1>, sumImpl<short , double, 2>, sumImpl<short , double, 3>, sumImpl<short , double, 4>},
|
||||
{sumImpl<int , double, 1>, sumImpl<int , double, 2>, sumImpl<int , double, 3>, sumImpl<int , double, 4>},
|
||||
{sumImpl<float , double, 1>, sumImpl<float , double, 2>, sumImpl<float , double, 3>, sumImpl<float , double, 4>},
|
||||
{sumImpl<double, double, 1>, sumImpl<double, double, 2>, sumImpl<double, double, 3>, sumImpl<double, double, 4>}
|
||||
};
|
||||
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
const GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
CV_Assert( mask.empty() || (mask.type() == CV_8UC1 && mask.size() == src.size()) );
|
||||
|
||||
const int src_depth = src.depth();
|
||||
const int channels = src.channels();
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, 1, 1, CV_64FC(channels), stream);
|
||||
|
||||
const func_t func = funcs[src_depth][channels - 1];
|
||||
func(src, dst, mask, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
cv::Scalar cv::cuda::sum(InputArray _src, InputArray _mask)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem dst;
|
||||
calcSum(_src, dst, _mask, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
cv::Scalar val;
|
||||
dst.createMatHeader().convertTo(cv::Mat(dst.size(), CV_64FC(dst.channels()), val.val), CV_64F);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void cv::cuda::calcAbsSum(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, const GpuMat& mask, Stream& stream);
|
||||
static const func_t funcs[7][4] =
|
||||
{
|
||||
{sumAbsImpl<uchar , double, 1>, sumAbsImpl<uchar , double, 2>, sumAbsImpl<uchar , double, 3>, sumAbsImpl<uchar , double, 4>},
|
||||
{sumAbsImpl<schar , double, 1>, sumAbsImpl<schar , double, 2>, sumAbsImpl<schar , double, 3>, sumAbsImpl<schar , double, 4>},
|
||||
{sumAbsImpl<ushort, double, 1>, sumAbsImpl<ushort, double, 2>, sumAbsImpl<ushort, double, 3>, sumAbsImpl<ushort, double, 4>},
|
||||
{sumAbsImpl<short , double, 1>, sumAbsImpl<short , double, 2>, sumAbsImpl<short , double, 3>, sumAbsImpl<short , double, 4>},
|
||||
{sumAbsImpl<int , double, 1>, sumAbsImpl<int , double, 2>, sumAbsImpl<int , double, 3>, sumAbsImpl<int , double, 4>},
|
||||
{sumAbsImpl<float , double, 1>, sumAbsImpl<float , double, 2>, sumAbsImpl<float , double, 3>, sumAbsImpl<float , double, 4>},
|
||||
{sumAbsImpl<double, double, 1>, sumAbsImpl<double, double, 2>, sumAbsImpl<double, double, 3>, sumAbsImpl<double, double, 4>}
|
||||
};
|
||||
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
const GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
CV_Assert( mask.empty() || (mask.type() == CV_8UC1 && mask.size() == src.size()) );
|
||||
|
||||
const int src_depth = src.depth();
|
||||
const int channels = src.channels();
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, 1, 1, CV_64FC(channels), stream);
|
||||
|
||||
const func_t func = funcs[src_depth][channels - 1];
|
||||
func(src, dst, mask, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
cv::Scalar cv::cuda::absSum(InputArray _src, InputArray _mask)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem dst;
|
||||
calcAbsSum(_src, dst, _mask, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
cv::Scalar val;
|
||||
dst.createMatHeader().convertTo(cv::Mat(dst.size(), CV_64FC(dst.channels()), val.val), CV_64F);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void cv::cuda::calcSqrSum(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, const GpuMat& mask, Stream& stream);
|
||||
static const func_t funcs[7][4] =
|
||||
{
|
||||
{sumSqrImpl<uchar , double, 1>, sumSqrImpl<uchar , double, 2>, sumSqrImpl<uchar , double, 3>, sumSqrImpl<uchar , double, 4>},
|
||||
{sumSqrImpl<schar , double, 1>, sumSqrImpl<schar , double, 2>, sumSqrImpl<schar , double, 3>, sumSqrImpl<schar , double, 4>},
|
||||
{sumSqrImpl<ushort, double, 1>, sumSqrImpl<ushort, double, 2>, sumSqrImpl<ushort, double, 3>, sumSqrImpl<ushort, double, 4>},
|
||||
{sumSqrImpl<short , double, 1>, sumSqrImpl<short , double, 2>, sumSqrImpl<short , double, 3>, sumSqrImpl<short , double, 4>},
|
||||
{sumSqrImpl<int , double, 1>, sumSqrImpl<int , double, 2>, sumSqrImpl<int , double, 3>, sumSqrImpl<int , double, 4>},
|
||||
{sumSqrImpl<float , double, 1>, sumSqrImpl<float , double, 2>, sumSqrImpl<float , double, 3>, sumSqrImpl<float , double, 4>},
|
||||
{sumSqrImpl<double, double, 1>, sumSqrImpl<double, double, 2>, sumSqrImpl<double, double, 3>, sumSqrImpl<double, double, 4>}
|
||||
};
|
||||
|
||||
const GpuMat src = getInputMat(_src, stream);
|
||||
const GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
CV_Assert( mask.empty() || (mask.type() == CV_8UC1 && mask.size() == src.size()) );
|
||||
|
||||
const int src_depth = src.depth();
|
||||
const int channels = src.channels();
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, 1, 1, CV_64FC(channels), stream);
|
||||
|
||||
const func_t func = funcs[src_depth][channels - 1];
|
||||
func(src, dst, mask, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
cv::Scalar cv::cuda::sqrSum(InputArray _src, InputArray _mask)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem dst;
|
||||
calcSqrSum(_src, dst, _mask, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
cv::Scalar val;
|
||||
dst.createMatHeader().convertTo(cv::Mat(dst.size(), CV_64FC(dst.channels()), val.val), CV_64F);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,409 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename ScalarDepth> struct TransformPolicy : DefaultTransformPolicy
|
||||
{
|
||||
};
|
||||
template <> struct TransformPolicy<double> : DefaultTransformPolicy
|
||||
{
|
||||
enum {
|
||||
shift = 1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void thresholdImpl(const GpuMat& src, GpuMat& dst, double thresh, double maxVal, int type, Stream& stream)
|
||||
{
|
||||
const T thresh_ = static_cast<T>(thresh);
|
||||
const T maxVal_ = static_cast<T>(maxVal);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), thresh_binary_func(thresh_, maxVal_), stream);
|
||||
break;
|
||||
case 1:
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), thresh_binary_inv_func(thresh_, maxVal_), stream);
|
||||
break;
|
||||
case 2:
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), thresh_trunc_func(thresh_), stream);
|
||||
break;
|
||||
case 3:
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), thresh_to_zero_func(thresh_), stream);
|
||||
break;
|
||||
case 4:
|
||||
gridTransformUnary_< TransformPolicy<T> >(globPtr<T>(src), globPtr<T>(dst), thresh_to_zero_inv_func(thresh_), stream);
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__global__ void otsu_sums(uint *histogram, uint *threshold_sums, unsigned long long *sums)
|
||||
{
|
||||
const uint n_bins = 256;
|
||||
|
||||
__shared__ uint shared_memory_ts[n_bins];
|
||||
__shared__ unsigned long long shared_memory_s[n_bins];
|
||||
|
||||
int bin_idx = threadIdx.x;
|
||||
int threshold = blockIdx.x;
|
||||
|
||||
uint threshold_sum_above = 0;
|
||||
unsigned long long sum_above = 0;
|
||||
|
||||
if (bin_idx > threshold)
|
||||
{
|
||||
uint value = histogram[bin_idx];
|
||||
threshold_sum_above = value;
|
||||
sum_above = value * bin_idx;
|
||||
}
|
||||
|
||||
blockReduce<n_bins>(shared_memory_ts, threshold_sum_above, bin_idx, plus<uint>());
|
||||
blockReduce<n_bins>(shared_memory_s, sum_above, bin_idx, plus<unsigned long long>());
|
||||
|
||||
if (bin_idx == 0)
|
||||
{
|
||||
threshold_sums[threshold] = threshold_sum_above;
|
||||
sums[threshold] = sum_above;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void
|
||||
otsu_variance(float2 *variance, uint *histogram, uint *threshold_sums, unsigned long long *sums, uint n_samples)
|
||||
{
|
||||
const uint n_bins = 256;
|
||||
|
||||
__shared__ signed long long shared_memory_a[n_bins];
|
||||
__shared__ signed long long shared_memory_b[n_bins];
|
||||
|
||||
int bin_idx = threadIdx.x;
|
||||
int threshold = blockIdx.x;
|
||||
|
||||
uint n_samples_above = threshold_sums[threshold];
|
||||
uint n_samples_below = n_samples - n_samples_above;
|
||||
|
||||
unsigned long long total_sum = sums[0];
|
||||
unsigned long long sum_above = sums[threshold];
|
||||
unsigned long long sum_below = total_sum - sum_above;
|
||||
|
||||
float threshold_variance_above_f32 = 0;
|
||||
float threshold_variance_below_f32 = 0;
|
||||
if (bin_idx > threshold)
|
||||
{
|
||||
if (n_samples_above > 0)
|
||||
{
|
||||
float mean = (float) sum_above / n_samples_above;
|
||||
float sigma = bin_idx - mean;
|
||||
threshold_variance_above_f32 = sigma * sigma;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n_samples_below > 0)
|
||||
{
|
||||
float mean = (float) sum_below / n_samples_below;
|
||||
float sigma = bin_idx - mean;
|
||||
threshold_variance_below_f32 = sigma * sigma;
|
||||
}
|
||||
}
|
||||
|
||||
uint bin_count = histogram[bin_idx];
|
||||
signed long long threshold_variance_above_i64 = (signed long long)(threshold_variance_above_f32 * bin_count);
|
||||
signed long long threshold_variance_below_i64 = (signed long long)(threshold_variance_below_f32 * bin_count);
|
||||
blockReduce<n_bins>(shared_memory_a, threshold_variance_above_i64, bin_idx, plus<signed long long>());
|
||||
blockReduce<n_bins>(shared_memory_b, threshold_variance_below_i64, bin_idx, plus<signed long long>());
|
||||
|
||||
if (bin_idx == 0)
|
||||
{
|
||||
variance[threshold] = make_float2(threshold_variance_above_i64, threshold_variance_below_i64);
|
||||
}
|
||||
}
|
||||
|
||||
template <uint n_thresholds>
|
||||
__device__ bool has_lowest_score(
|
||||
uint threshold, float original_score, float score, uint *shared_memory
|
||||
) {
|
||||
// It may happen that multiple threads have the same minimum score. In that case, we want to find the thread with
|
||||
// the lowest threshold. This is done by calling '__syncthreads_count' to count how many threads have a score
|
||||
// that matches to the minimum score found. Since this is rare, we will optimize towards the common case where only
|
||||
// one thread has the minimum score. If multiple threads have the same minimum score, we will find the minimum
|
||||
// threshold that satifies the condition
|
||||
bool has_match = original_score == score;
|
||||
uint matches = __syncthreads_count(has_match);
|
||||
|
||||
if(matches > 1) {
|
||||
// If this thread has a match, we use it; otherwise we give it a value that is larger than the maximum
|
||||
// threshold, so it will never get picked
|
||||
uint min_threshold = has_match ? threshold : n_thresholds;
|
||||
|
||||
blockReduce<n_thresholds>(shared_memory, min_threshold, threshold, minimum<uint>());
|
||||
|
||||
return min_threshold == threshold;
|
||||
} else {
|
||||
return has_match;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void
|
||||
otsu_score(uint *otsu_threshold, uint *threshold_sums, float2 *variance, uint n_samples)
|
||||
{
|
||||
const uint n_thresholds = 256;
|
||||
|
||||
__shared__ float shared_memory[n_thresholds];
|
||||
|
||||
int threshold = threadIdx.x;
|
||||
|
||||
uint n_samples_above = threshold_sums[threshold];
|
||||
uint n_samples_below = n_samples - n_samples_above;
|
||||
|
||||
float threshold_mean_above = (float)n_samples_above / n_samples;
|
||||
float threshold_mean_below = (float)n_samples_below / n_samples;
|
||||
|
||||
float2 variances = variance[threshold];
|
||||
float variance_above = n_samples_above > 0 ? variances.x / n_samples_above : 0.0f;
|
||||
float variance_below = n_samples_below > 0 ? variances.y / n_samples_below : 0.0f;
|
||||
|
||||
float above = threshold_mean_above * variance_above;
|
||||
float below = threshold_mean_below * variance_below;
|
||||
float score = above + below;
|
||||
|
||||
float original_score = score;
|
||||
|
||||
blockReduce<n_thresholds>(shared_memory, score, threshold, minimum<float>());
|
||||
|
||||
if (threshold == 0)
|
||||
{
|
||||
shared_memory[0] = score;
|
||||
}
|
||||
__syncthreads();
|
||||
|
||||
score = shared_memory[0];
|
||||
|
||||
// We found the minimum score, but in some cases multiple threads can have the same score, so we need to find the
|
||||
// lowest threshold
|
||||
if (has_lowest_score<n_thresholds>(threshold, original_score, score, (uint *) shared_memory))
|
||||
{
|
||||
*otsu_threshold = threshold;
|
||||
}
|
||||
}
|
||||
|
||||
void compute_otsu(uint *histogram, uint *otsu_threshold, uint n_samples, Stream &stream)
|
||||
{
|
||||
const uint n_bins = 256;
|
||||
const uint n_thresholds = 256;
|
||||
|
||||
cudaStream_t cuda_stream = StreamAccessor::getStream(stream);
|
||||
|
||||
dim3 block_all(n_bins);
|
||||
dim3 grid_all(n_thresholds);
|
||||
dim3 block_score(n_thresholds);
|
||||
dim3 grid_score(1);
|
||||
|
||||
BufferPool pool(stream);
|
||||
GpuMat gpu_threshold_sums(1, n_bins, CV_32SC1, pool.getAllocator());
|
||||
GpuMat gpu_sums(1, n_bins, CV_64FC1, pool.getAllocator());
|
||||
GpuMat gpu_variances(1, n_bins, CV_32FC2, pool.getAllocator());
|
||||
|
||||
otsu_sums<<<grid_all, block_all, 0, cuda_stream>>>(
|
||||
histogram, gpu_threshold_sums.ptr<uint>(), gpu_sums.ptr<unsigned long long>());
|
||||
otsu_variance<<<grid_all, block_all, 0, cuda_stream>>>(
|
||||
gpu_variances.ptr<float2>(), histogram, gpu_threshold_sums.ptr<uint>(), gpu_sums.ptr<unsigned long long>(), n_samples);
|
||||
otsu_score<<<grid_score, block_score, 0, cuda_stream>>>(
|
||||
otsu_threshold, gpu_threshold_sums.ptr<uint>(), gpu_variances.ptr<float2>(), n_samples);
|
||||
}
|
||||
|
||||
// TODO: Replace this with cv::cuda::calcHist
|
||||
template <uint n_bins>
|
||||
__global__ void histogram_kernel(
|
||||
uint *histogram, const uint8_t *image, uint width,
|
||||
uint height, uint pitch)
|
||||
{
|
||||
__shared__ uint local_histogram[n_bins];
|
||||
|
||||
uint x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
uint y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
uint tid = threadIdx.y * blockDim.x + threadIdx.x;
|
||||
|
||||
if (tid < n_bins)
|
||||
{
|
||||
local_histogram[tid] = 0;
|
||||
}
|
||||
|
||||
__syncthreads();
|
||||
|
||||
if (x < width && y < height)
|
||||
{
|
||||
uint8_t value = image[y * pitch + x];
|
||||
atomicInc(&local_histogram[value], 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
__syncthreads();
|
||||
|
||||
if (tid < n_bins)
|
||||
{
|
||||
cv::cudev::atomicAdd(&histogram[tid], local_histogram[tid]);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Replace this with cv::cuda::calcHist
|
||||
void calcHist(
|
||||
const GpuMat src, GpuMat histogram, Stream stream)
|
||||
{
|
||||
const uint n_bins = 256;
|
||||
|
||||
cudaStream_t cuda_stream = StreamAccessor::getStream(stream);
|
||||
|
||||
dim3 block(128, 4, 1);
|
||||
dim3 grid = dim3(divUp(src.cols, block.x), divUp(src.rows, block.y), 1);
|
||||
CV_CUDEV_SAFE_CALL(cudaMemsetAsync(histogram.ptr<uint>(), 0, n_bins * sizeof(uint), cuda_stream));
|
||||
histogram_kernel<n_bins>
|
||||
<<<grid, block, 0, cuda_stream>>>(
|
||||
histogram.ptr<uint>(), src.ptr<uint8_t>(), (uint) src.cols, (uint) src.rows, (uint) src.step);
|
||||
}
|
||||
|
||||
double cv::cuda::threshold(InputArray _src, OutputArray _dst, double thresh, double maxVal, int type, Stream &stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
const int depth = src.depth();
|
||||
|
||||
const int THRESH_OTSU = 8;
|
||||
if ((type & THRESH_OTSU) == THRESH_OTSU)
|
||||
{
|
||||
CV_Assert(depth == CV_8U);
|
||||
CV_Assert(src.channels() == 1);
|
||||
|
||||
BufferPool pool(stream);
|
||||
|
||||
// Find the threshold using Otsu and then run the normal thresholding algorithm
|
||||
GpuMat gpu_histogram(256, 1, CV_32SC1, pool.getAllocator());
|
||||
calcHist(src, gpu_histogram, stream);
|
||||
|
||||
GpuMat gpu_otsu_threshold(1, 1, CV_32SC1, pool.getAllocator());
|
||||
compute_otsu(gpu_histogram.ptr<uint>(), gpu_otsu_threshold.ptr<uint>(), src.rows * src.cols, stream);
|
||||
|
||||
cv::Mat mat_otsu_threshold;
|
||||
gpu_otsu_threshold.download(mat_otsu_threshold, stream);
|
||||
stream.waitForCompletion();
|
||||
|
||||
// Overwrite the threshold value with the Otsu value and remove the Otsu flag from the type
|
||||
type = type & ~THRESH_OTSU;
|
||||
thresh = (double) mat_otsu_threshold.at<int>(0);
|
||||
}
|
||||
|
||||
CV_Assert( depth <= CV_64F );
|
||||
CV_Assert( type <= 4 /*THRESH_TOZERO_INV*/ );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
src = src.reshape(1);
|
||||
dst = dst.reshape(1);
|
||||
|
||||
if (depth == CV_32F && type == 2 /*THRESH_TRUNC*/)
|
||||
{
|
||||
NppStreamHandler h(StreamAccessor::getStream(stream));
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = src.cols;
|
||||
sz.height = src.rows;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall(nppiThreshold_32f_C1R_Ctx(src.ptr<Npp32f>(), static_cast<int>(src.step),
|
||||
dst.ptr<Npp32f>(), static_cast<int>(dst.step), sz, static_cast<Npp32f>(thresh), NPP_CMP_GREATER, h));
|
||||
#else
|
||||
nppSafeCall( nppiThreshold_32f_C1R(src.ptr<Npp32f>(), static_cast<int>(src.step),
|
||||
dst.ptr<Npp32f>(), static_cast<int>(dst.step), sz, static_cast<Npp32f>(thresh), NPP_CMP_GREATER) );
|
||||
#endif
|
||||
|
||||
if (!stream)
|
||||
CV_CUDEV_SAFE_CALL( cudaDeviceSynchronize() );
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, GpuMat& dst, double thresh, double maxVal, int type, Stream& stream);
|
||||
static const func_t funcs[CV_DEPTH_MAX] =
|
||||
{
|
||||
thresholdImpl<uchar>,
|
||||
thresholdImpl<schar>,
|
||||
thresholdImpl<ushort>,
|
||||
thresholdImpl<short>,
|
||||
thresholdImpl<int>,
|
||||
thresholdImpl<float>,
|
||||
thresholdImpl<double>
|
||||
};
|
||||
|
||||
if (depth != CV_32F && depth != CV_64F)
|
||||
{
|
||||
thresh = cvFloor(thresh);
|
||||
maxVal = cvRound(maxVal);
|
||||
}
|
||||
|
||||
auto f = funcs[depth];
|
||||
CV_Assert(f);
|
||||
|
||||
f(src, dst, thresh, maxVal, type, stream);
|
||||
}
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
|
||||
return thresh;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifndef HAVE_OPENCV_CUDEV
|
||||
|
||||
#error "opencv_cudev is required"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/cudev.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
using namespace cv::cudev;
|
||||
|
||||
void cv::cuda::transpose(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
const size_t elemSize = src.elemSize();
|
||||
|
||||
CV_Assert( elemSize == 1 || elemSize == 4 || elemSize == 8 );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.cols, src.rows, src.type(), stream);
|
||||
|
||||
if (elemSize == 1)
|
||||
{
|
||||
NppStreamHandler h(StreamAccessor::getStream(stream));
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = src.cols;
|
||||
sz.height = src.rows;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall(nppiTranspose_8u_C1R_Ctx(src.ptr<Npp8u>(), static_cast<int>(src.step),
|
||||
dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz, h));
|
||||
#else
|
||||
nppSafeCall( nppiTranspose_8u_C1R(src.ptr<Npp8u>(), static_cast<int>(src.step),
|
||||
dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz) );
|
||||
#endif
|
||||
|
||||
if (!stream)
|
||||
CV_CUDEV_SAFE_CALL( cudaDeviceSynchronize() );
|
||||
}
|
||||
else if (elemSize == 4)
|
||||
{
|
||||
gridTranspose(globPtr<int>(src), globPtr<int>(dst), stream);
|
||||
}
|
||||
else // if (elemSize == 8)
|
||||
{
|
||||
gridTranspose(globPtr<double>(src), globPtr<double>(dst), stream);
|
||||
}
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,561 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::cuda::add(InputArray, InputArray, OutputArray, InputArray, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::subtract(InputArray, InputArray, OutputArray, InputArray, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::multiply(InputArray, InputArray, OutputArray, double, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::divide(InputArray, InputArray, OutputArray, double, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::absdiff(InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::abs(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::sqr(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::sqrt(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::exp(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::log(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::pow(InputArray, double, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::compare(InputArray, InputArray, OutputArray, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::bitwise_not(InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::bitwise_or(InputArray, InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::bitwise_and(InputArray, InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::bitwise_xor(InputArray, InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::rshift(InputArray, Scalar_<int>, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::lshift(InputArray, Scalar_<int>, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::min(InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::max(InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::addWeighted(InputArray, double, InputArray, double, double, OutputArray, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
double cv::cuda::threshold(InputArray, OutputArray, double, double, int, Stream&) {throw_no_cuda(); return 0.0;}
|
||||
|
||||
void cv::cuda::inRange(InputArray, const Scalar&, const Scalar&, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::magnitude(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::magnitude(InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::magnitudeSqr(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::magnitudeSqr(InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::phase(InputArray, InputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::phase(InputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::cartToPolar(InputArray, InputArray, OutputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::cartToPolar(InputArray, OutputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::cartToPolar(InputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::polarToCart(InputArray, InputArray, OutputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::polarToCart(InputArray, InputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::polarToCart(InputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
|
||||
|
||||
#else
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// arithm_op
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef void (*mat_mat_func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream, int op);
|
||||
typedef void (*mat_scalar_func_t)(const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream, int op);
|
||||
|
||||
void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, InputArray _mask, double scale, int dtype, Stream& stream,
|
||||
mat_mat_func_t mat_mat_func, mat_scalar_func_t mat_scalar_func, int op = 0)
|
||||
{
|
||||
const int kind1 = _src1.kind();
|
||||
const int kind2 = _src2.kind();
|
||||
|
||||
const bool isScalar1 = (kind1 == _InputArray::MATX);
|
||||
const bool isScalar2 = (kind2 == _InputArray::MATX);
|
||||
CV_Assert( !isScalar1 || !isScalar2 );
|
||||
|
||||
GpuMat src1;
|
||||
if (!isScalar1)
|
||||
src1 = getInputMat(_src1, stream);
|
||||
|
||||
GpuMat src2;
|
||||
if (!isScalar2)
|
||||
src2 = getInputMat(_src2, stream);
|
||||
|
||||
Mat scalar;
|
||||
if (isScalar1)
|
||||
scalar = _src1.getMat();
|
||||
else if (isScalar2)
|
||||
scalar = _src2.getMat();
|
||||
|
||||
Scalar val;
|
||||
if (!scalar.empty())
|
||||
{
|
||||
CV_Assert( scalar.total() <= 4 );
|
||||
scalar.convertTo(Mat_<double>(scalar.rows, scalar.cols, &val[0]), CV_64F);
|
||||
}
|
||||
|
||||
GpuMat mask = getInputMat(_mask, stream);
|
||||
|
||||
const int sdepth = src1.empty() ? src2.depth() : src1.depth();
|
||||
const int cn = src1.empty() ? src2.channels() : src1.channels();
|
||||
const Size size = src1.empty() ? src2.size() : src1.size();
|
||||
|
||||
if (dtype < 0)
|
||||
dtype = sdepth;
|
||||
|
||||
const int ddepth = CV_MAT_DEPTH(dtype);
|
||||
|
||||
CV_Assert( sdepth <= CV_64F && ddepth <= CV_64F );
|
||||
CV_Assert( !scalar.empty() || (src2.type() == src1.type() && src2.size() == src1.size()) );
|
||||
CV_Assert( mask.empty() || (cn == 1 && mask.size() == size && mask.type() == CV_8UC1) );
|
||||
|
||||
if (sdepth == CV_64F || ddepth == CV_64F)
|
||||
{
|
||||
if (!deviceSupports(NATIVE_DOUBLE))
|
||||
CV_Error(Error::StsUnsupportedFormat, "The device doesn't support double");
|
||||
}
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, size, CV_MAKE_TYPE(ddepth, cn), stream);
|
||||
|
||||
if (isScalar1)
|
||||
mat_scalar_func(src2, val, true, dst, mask, scale, stream, op);
|
||||
else if (isScalar2)
|
||||
mat_scalar_func(src1, val, false, dst, mask, scale, stream, op);
|
||||
else
|
||||
mat_mat_func(src1, src2, dst, mask, scale, stream, op);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// add
|
||||
|
||||
void addMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& _stream, int);
|
||||
|
||||
void addScalar(const GpuMat& src, Scalar val, bool, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int);
|
||||
|
||||
void cv::cuda::add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask, int dtype, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, mask, 1.0, dtype, stream, addMat, addScalar);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// subtract
|
||||
|
||||
void subMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& _stream, int);
|
||||
|
||||
void subScalar(const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int);
|
||||
|
||||
void cv::cuda::subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask, int dtype, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, mask, 1.0, dtype, stream, subMat, subScalar);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// multiply
|
||||
|
||||
void mulMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int);
|
||||
void mulMat_8uc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
void mulMat_16sc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
|
||||
void mulScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream, int);
|
||||
|
||||
void cv::cuda::multiply(InputArray _src1, InputArray _src2, OutputArray _dst, double scale, int dtype, Stream& stream)
|
||||
{
|
||||
if (_src1.type() == CV_8UC4 && _src2.type() == CV_32FC1)
|
||||
{
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
|
||||
CV_Assert( src1.size() == src2.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src1.size(), src1.type(), stream);
|
||||
|
||||
mulMat_8uc4_32f(src1, src2, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
else if (_src1.type() == CV_16SC4 && _src2.type() == CV_32FC1)
|
||||
{
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
|
||||
CV_Assert( src1.size() == src2.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src1.size(), src1.type(), stream);
|
||||
|
||||
mulMat_16sc4_32f(src1, src2, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
arithm_op(_src1, _src2, _dst, GpuMat(), scale, dtype, stream, mulMat, mulScalar);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// divide
|
||||
|
||||
void divMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int);
|
||||
void divMat_8uc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
void divMat_16sc4_32f(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream);
|
||||
|
||||
void divScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream, int);
|
||||
|
||||
void cv::cuda::divide(InputArray _src1, InputArray _src2, OutputArray _dst, double scale, int dtype, Stream& stream)
|
||||
{
|
||||
if (_src1.type() == CV_8UC4 && _src2.type() == CV_32FC1)
|
||||
{
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
|
||||
CV_Assert( src1.size() == src2.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src1.size(), src1.type(), stream);
|
||||
|
||||
divMat_8uc4_32f(src1, src2, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
else if (_src1.type() == CV_16SC4 && _src2.type() == CV_32FC1)
|
||||
{
|
||||
GpuMat src1 = getInputMat(_src1, stream);
|
||||
GpuMat src2 = getInputMat(_src2, stream);
|
||||
|
||||
CV_Assert( src1.size() == src2.size() );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src1.size(), src1.type(), stream);
|
||||
|
||||
divMat_16sc4_32f(src1, src2, dst, stream);
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
arithm_op(_src1, _src2, _dst, GpuMat(), scale, dtype, stream, divMat, divScalar);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// absdiff
|
||||
|
||||
void absDiffMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int);
|
||||
|
||||
void absDiffScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int);
|
||||
|
||||
void cv::cuda::absdiff(InputArray src1, InputArray src2, OutputArray dst, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, noArray(), 1.0, -1, stream, absDiffMat, absDiffScalar);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// compare
|
||||
|
||||
void cmpMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int cmpop);
|
||||
|
||||
void cmpScalar(const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat&, double, Stream& stream, int cmpop);
|
||||
|
||||
void cv::cuda::compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, noArray(), 1.0, CV_8U, stream, cmpMat, cmpScalar, cmpop);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Binary bitwise logical operations
|
||||
|
||||
namespace
|
||||
{
|
||||
enum
|
||||
{
|
||||
BIT_OP_AND,
|
||||
BIT_OP_OR,
|
||||
BIT_OP_XOR
|
||||
};
|
||||
}
|
||||
|
||||
void bitMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int op);
|
||||
|
||||
void bitScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const GpuMat& mask, double, Stream& stream, int op);
|
||||
|
||||
void cv::cuda::bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, mask, 1.0, -1, stream, bitMat, bitScalar, BIT_OP_OR);
|
||||
}
|
||||
|
||||
void cv::cuda::bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, mask, 1.0, -1, stream, bitMat, bitScalar, BIT_OP_AND);
|
||||
}
|
||||
|
||||
void cv::cuda::bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, mask, 1.0, -1, stream, bitMat, bitScalar, BIT_OP_XOR);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// shift
|
||||
|
||||
namespace
|
||||
{
|
||||
template <int DEPTH, int cn> struct NppShiftFunc
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_type;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
typedef NppStatus(*func_t)(const npp_type* pSrc1, int nSrc1Step, const Npp32u* pConstants, npp_type* pDst, int nDstStep, NppiSize oSizeROI, NppStreamContext ctx);
|
||||
#else
|
||||
typedef NppStatus (*func_t)(const npp_type* pSrc1, int nSrc1Step, const Npp32u* pConstants, npp_type* pDst, int nDstStep, NppiSize oSizeROI);
|
||||
#endif
|
||||
};
|
||||
template <int DEPTH> struct NppShiftFunc<DEPTH, 1>
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_type;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
typedef NppStatus(*func_t)(const npp_type* pSrc1, int nSrc1Step, const Npp32u pConstants, npp_type* pDst, int nDstStep, NppiSize oSizeROI, NppStreamContext ctx);
|
||||
#else
|
||||
typedef NppStatus (*func_t)(const npp_type* pSrc1, int nSrc1Step, const Npp32u pConstants, npp_type* pDst, int nDstStep, NppiSize oSizeROI);
|
||||
#endif
|
||||
};
|
||||
|
||||
template <int DEPTH, int cn, typename NppShiftFunc<DEPTH, cn>::func_t func> struct NppShift
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_type;
|
||||
|
||||
static void call(const GpuMat& src, Scalar_<Npp32u> sc, GpuMat& dst, cudaStream_t stream)
|
||||
{
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize oSizeROI;
|
||||
oSizeROI.width = src.cols;
|
||||
oSizeROI.height = src.rows;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall(func(src.ptr<npp_type>(), static_cast<int>(src.step), sc.val, dst.ptr<npp_type>(), static_cast<int>(dst.step), oSizeROI, h));
|
||||
#else
|
||||
nppSafeCall( func(src.ptr<npp_type>(), static_cast<int>(src.step), sc.val, dst.ptr<npp_type>(), static_cast<int>(dst.step), oSizeROI) );
|
||||
#endif
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
};
|
||||
template <int DEPTH, typename NppShiftFunc<DEPTH, 1>::func_t func> struct NppShift<DEPTH, 1, func>
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_type;
|
||||
|
||||
static void call(const GpuMat& src, Scalar_<Npp32u> sc, GpuMat& dst, cudaStream_t stream)
|
||||
{
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize oSizeROI;
|
||||
oSizeROI.width = src.cols;
|
||||
oSizeROI.height = src.rows;
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall(func(src.ptr<npp_type>(), static_cast<int>(src.step), sc.val[0], dst.ptr<npp_type>(), static_cast<int>(dst.step), oSizeROI, h));
|
||||
#else
|
||||
nppSafeCall( func(src.ptr<npp_type>(), static_cast<int>(src.step), sc.val[0], dst.ptr<npp_type>(), static_cast<int>(dst.step), oSizeROI) );
|
||||
#endif
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void cv::cuda::rshift(InputArray _src, Scalar_<int> val, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, Scalar_<Npp32u> sc, GpuMat& dst, cudaStream_t stream);
|
||||
static const func_t funcs[5][4] =
|
||||
{
|
||||
#if USE_NPP_STREAM_CTX
|
||||
|
||||
{NppShift<CV_8U , 1, nppiRShiftC_8u_C1R_Ctx>::call, 0, NppShift<CV_8U , 3, nppiRShiftC_8u_C3R_Ctx>::call, NppShift<CV_8U , 4, nppiRShiftC_8u_C4R_Ctx>::call },
|
||||
{NppShift<CV_8S , 1, nppiRShiftC_8s_C1R_Ctx>::call, 0, NppShift<CV_8S , 3, nppiRShiftC_8s_C3R_Ctx>::call, NppShift<CV_8S , 4, nppiRShiftC_8s_C4R_Ctx>::call },
|
||||
{NppShift<CV_16U, 1, nppiRShiftC_16u_C1R_Ctx>::call, 0, NppShift<CV_16U, 3, nppiRShiftC_16u_C3R_Ctx>::call, NppShift<CV_16U, 4, nppiRShiftC_16u_C4R_Ctx>::call},
|
||||
{NppShift<CV_16S, 1, nppiRShiftC_16s_C1R_Ctx>::call, 0, NppShift<CV_16S, 3, nppiRShiftC_16s_C3R_Ctx>::call, NppShift<CV_16S, 4, nppiRShiftC_16s_C4R_Ctx>::call},
|
||||
{NppShift<CV_32S, 1, nppiRShiftC_32s_C1R_Ctx>::call, 0, NppShift<CV_32S, 3, nppiRShiftC_32s_C3R_Ctx>::call, NppShift<CV_32S, 4, nppiRShiftC_32s_C4R_Ctx>::call},
|
||||
#else
|
||||
{NppShift<CV_8U , 1, nppiRShiftC_8u_C1R >::call, 0, NppShift<CV_8U , 3, nppiRShiftC_8u_C3R >::call, NppShift<CV_8U , 4, nppiRShiftC_8u_C4R>::call },
|
||||
{NppShift<CV_8S , 1, nppiRShiftC_8s_C1R >::call, 0, NppShift<CV_8S , 3, nppiRShiftC_8s_C3R >::call, NppShift<CV_8S , 4, nppiRShiftC_8s_C4R>::call },
|
||||
{NppShift<CV_16U, 1, nppiRShiftC_16u_C1R>::call, 0, NppShift<CV_16U, 3, nppiRShiftC_16u_C3R>::call, NppShift<CV_16U, 4, nppiRShiftC_16u_C4R>::call},
|
||||
{NppShift<CV_16S, 1, nppiRShiftC_16s_C1R>::call, 0, NppShift<CV_16S, 3, nppiRShiftC_16s_C3R>::call, NppShift<CV_16S, 4, nppiRShiftC_16s_C4R>::call},
|
||||
{NppShift<CV_32S, 1, nppiRShiftC_32s_C1R>::call, 0, NppShift<CV_32S, 3, nppiRShiftC_32s_C3R>::call, NppShift<CV_32S, 4, nppiRShiftC_32s_C4R>::call},
|
||||
#endif
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() < CV_32F );
|
||||
CV_Assert( src.channels() == 1 || src.channels() == 3 || src.channels() == 4 );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
funcs[src.depth()][src.channels() - 1](src, val, dst, StreamAccessor::getStream(stream));
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::lshift(InputArray _src, Scalar_<int> val, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, Scalar_<Npp32u> sc, GpuMat& dst, cudaStream_t stream);
|
||||
static const func_t funcs[5][4] =
|
||||
{
|
||||
#if USE_NPP_STREAM_CTX
|
||||
{NppShift<CV_8U , 1, nppiLShiftC_8u_C1R_Ctx>::call , 0, NppShift<CV_8U , 3, nppiLShiftC_8u_C3R_Ctx>::call , NppShift<CV_8U , 4, nppiLShiftC_8u_C4R_Ctx>::call },
|
||||
{0 , 0, 0 , 0 },
|
||||
{NppShift<CV_16U, 1, nppiLShiftC_16u_C1R_Ctx>::call, 0, NppShift<CV_16U, 3, nppiLShiftC_16u_C3R_Ctx>::call, NppShift<CV_16U, 4, nppiLShiftC_16u_C4R_Ctx>::call},
|
||||
{0 , 0, 0 , 0 },
|
||||
{NppShift<CV_32S, 1, nppiLShiftC_32s_C1R_Ctx>::call, 0, NppShift<CV_32S, 3, nppiLShiftC_32s_C3R_Ctx>::call, NppShift<CV_32S, 4, nppiLShiftC_32s_C4R_Ctx>::call},
|
||||
#else
|
||||
{NppShift<CV_8U , 1, nppiLShiftC_8u_C1R>::call , 0, NppShift<CV_8U , 3, nppiLShiftC_8u_C3R>::call , NppShift<CV_8U , 4, nppiLShiftC_8u_C4R>::call },
|
||||
{0 , 0, 0 , 0 },
|
||||
{NppShift<CV_16U, 1, nppiLShiftC_16u_C1R>::call, 0, NppShift<CV_16U, 3, nppiLShiftC_16u_C3R>::call, NppShift<CV_16U, 4, nppiLShiftC_16u_C4R>::call},
|
||||
{0 , 0, 0 , 0 },
|
||||
{NppShift<CV_32S, 1, nppiLShiftC_32s_C1R>::call, 0, NppShift<CV_32S, 3, nppiLShiftC_32s_C3R>::call, NppShift<CV_32S, 4, nppiLShiftC_32s_C4R>::call},
|
||||
#endif
|
||||
};
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
CV_Assert( src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32S );
|
||||
CV_Assert( src.channels() == 1 || src.channels() == 3 || src.channels() == 4 );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
|
||||
|
||||
funcs[src.depth()][src.channels() - 1](src, val, dst, StreamAccessor::getStream(stream));
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Minimum and maximum operations
|
||||
|
||||
namespace
|
||||
{
|
||||
enum
|
||||
{
|
||||
MIN_OP,
|
||||
MAX_OP
|
||||
};
|
||||
}
|
||||
|
||||
void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int op);
|
||||
|
||||
void minMaxScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int op);
|
||||
|
||||
void cv::cuda::min(InputArray src1, InputArray src2, OutputArray dst, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, noArray(), 1.0, -1, stream, minMaxMat, minMaxScalar, MIN_OP);
|
||||
}
|
||||
|
||||
void cv::cuda::max(InputArray src1, InputArray src2, OutputArray dst, Stream& stream)
|
||||
{
|
||||
arithm_op(src1, src2, dst, noArray(), 1.0, -1, stream, minMaxMat, minMaxScalar, MAX_OP);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// NPP magnitide
|
||||
|
||||
namespace
|
||||
{
|
||||
#if USE_NPP_STREAM_CTX
|
||||
typedef NppStatus(*nppMagnitude_t)(const Npp32fc* pSrc, int nSrcStep, Npp32f* pDst, int nDstStep, NppiSize oSizeROI, NppStreamContext ctx);
|
||||
#else
|
||||
typedef NppStatus (*nppMagnitude_t)(const Npp32fc* pSrc, int nSrcStep, Npp32f* pDst, int nDstStep, NppiSize oSizeROI);
|
||||
#endif
|
||||
|
||||
void npp_magnitude(const GpuMat& src, GpuMat& dst, nppMagnitude_t func, cudaStream_t stream)
|
||||
{
|
||||
CV_Assert(src.type() == CV_32FC2);
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = src.cols;
|
||||
sz.height = src.rows;
|
||||
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall(func(src.ptr<Npp32fc>(), static_cast<int>(src.step), dst.ptr<Npp32f>(), static_cast<int>(dst.step), sz, h));
|
||||
#else
|
||||
nppSafeCall( func(src.ptr<Npp32fc>(), static_cast<int>(src.step), dst.ptr<Npp32f>(), static_cast<int>(dst.step), sz) );
|
||||
#endif
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
}
|
||||
|
||||
void cv::cuda::magnitude(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), CV_32FC1, stream);
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
npp_magnitude(src, dst, nppiMagnitude_32fc32f_C1R_Ctx, StreamAccessor::getStream(stream));
|
||||
#else
|
||||
npp_magnitude(src, dst, nppiMagnitude_32fc32f_C1R, StreamAccessor::getStream(stream));
|
||||
#endif
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::magnitudeSqr(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), CV_32FC1, stream);
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
npp_magnitude(src, dst, nppiMagnitudeSqr_32fc32f_C1R_Ctx, StreamAccessor::getStream(stream));
|
||||
#else
|
||||
npp_magnitude(src, dst, nppiMagnitudeSqr_32fc32f_C1R, StreamAccessor::getStream(stream));
|
||||
#endif
|
||||
|
||||
syncOutput(dst, _dst, stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
Ptr<LookUpTable> cv::cuda::createLookUpTable(InputArray) { throw_no_cuda(); return Ptr<LookUpTable>(); }
|
||||
|
||||
#else /* !defined (HAVE_CUDA) || defined (CUDA_DISABLER) */
|
||||
|
||||
// lut.hpp includes cuda_runtime.h and can only be included when we have CUDA
|
||||
#include "lut.hpp"
|
||||
|
||||
Ptr<LookUpTable> cv::cuda::createLookUpTable(InputArray lut)
|
||||
{
|
||||
return makePtr<LookUpTableImpl>(lut);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef __CUDAARITHM_LUT_HPP__
|
||||
#define __CUDAARITHM_LUT_HPP__
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
namespace cv { namespace cuda {
|
||||
|
||||
class LookUpTableImpl : public LookUpTable
|
||||
{
|
||||
public:
|
||||
LookUpTableImpl(InputArray lut);
|
||||
void transform(InputArray src, OutputArray dst, Stream& stream = Stream::Null()) CV_OVERRIDE;
|
||||
private:
|
||||
GpuMat d_lut;
|
||||
size_t szInBytes = 0;
|
||||
};
|
||||
|
||||
} }
|
||||
|
||||
#endif // __CUDAARITHM_LUT_HPP__
|
||||
@@ -0,0 +1,63 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "cvconfig.h"
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
|
||||
#ifdef HAVE_CUBLAS
|
||||
# include <cublas.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CUFFT
|
||||
# include <cufft.h>
|
||||
#endif
|
||||
|
||||
#endif /* __OPENCV_PRECOMP_H__ */
|
||||
@@ -0,0 +1,337 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::cuda;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
double cv::cuda::norm(InputArray, int, InputArray) { throw_no_cuda(); return 0.0; }
|
||||
void cv::cuda::calcNorm(InputArray, OutputArray, int, InputArray, Stream&) { throw_no_cuda(); }
|
||||
double cv::cuda::norm(InputArray, InputArray, int) { throw_no_cuda(); return 0.0; }
|
||||
void cv::cuda::calcNormDiff(InputArray, InputArray, OutputArray, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
Scalar cv::cuda::sum(InputArray, InputArray) { throw_no_cuda(); return Scalar(); }
|
||||
void cv::cuda::calcSum(InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
Scalar cv::cuda::absSum(InputArray, InputArray) { throw_no_cuda(); return Scalar(); }
|
||||
void cv::cuda::calcAbsSum(InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
Scalar cv::cuda::sqrSum(InputArray, InputArray) { throw_no_cuda(); return Scalar(); }
|
||||
void cv::cuda::calcSqrSum(InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::minMax(InputArray, double*, double*, InputArray) { throw_no_cuda(); }
|
||||
void cv::cuda::findMinMax(InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::minMaxLoc(InputArray, double*, double*, Point*, Point*, InputArray) { throw_no_cuda(); }
|
||||
void cv::cuda::findMinMaxLoc(InputArray, OutputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
int cv::cuda::countNonZero(InputArray) { throw_no_cuda(); return 0; }
|
||||
void cv::cuda::countNonZero(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::reduce(InputArray, OutputArray, int, int, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::meanStdDev(InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::meanStdDev(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::meanStdDev(InputArray, Scalar&, Scalar&, InputArray) { throw_no_cuda(); }
|
||||
void cv::cuda::meanStdDev(InputArray, Scalar&, Scalar&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::rectStdDev(InputArray, InputArray, OutputArray, Rect, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::normalize(InputArray, OutputArray, double, double, int, int, InputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::cuda::integral(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::cuda::sqrIntegral(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
#else
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// norm
|
||||
|
||||
namespace cv { namespace cuda { namespace device {
|
||||
|
||||
void normL2(cv::InputArray _src, cv::OutputArray _dst, cv::InputArray _mask, Stream& stream);
|
||||
|
||||
void findMaxAbs(cv::InputArray _src, cv::OutputArray _dst, cv::InputArray _mask, Stream& stream);
|
||||
|
||||
}}}
|
||||
|
||||
void cv::cuda::calcNorm(InputArray _src, OutputArray dst, int normType, InputArray mask, Stream& stream)
|
||||
{
|
||||
CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 );
|
||||
|
||||
GpuMat src = getInputMat(_src, stream);
|
||||
|
||||
GpuMat src_single_channel = src.reshape(1);
|
||||
|
||||
if (normType == NORM_L1)
|
||||
{
|
||||
calcAbsSum(src_single_channel, dst, mask, stream);
|
||||
}
|
||||
else if (normType == NORM_L2)
|
||||
{
|
||||
cv::cuda::device::normL2(src_single_channel, dst, mask, stream);
|
||||
}
|
||||
else // NORM_INF
|
||||
{
|
||||
cv::cuda::device::findMaxAbs(src_single_channel, dst, mask, stream);
|
||||
}
|
||||
}
|
||||
|
||||
double cv::cuda::norm(InputArray _src, int normType, InputArray _mask)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem dst;
|
||||
calcNorm(_src, dst, normType, _mask, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
double val;
|
||||
dst.createMatHeader().convertTo(Mat(1, 1, CV_64FC1, &val), CV_64F);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// meanStdDev
|
||||
|
||||
void cv::cuda::meanStdDev(InputArray src, OutputArray dst, Stream& stream)
|
||||
{
|
||||
if (!deviceSupports(FEATURE_SET_COMPUTE_13))
|
||||
CV_Error(cv::Error::StsNotImplemented, "Not sufficient compute capebility");
|
||||
|
||||
const GpuMat gsrc = getInputMat(src, stream);
|
||||
|
||||
#if (CUDA_VERSION <= 4020)
|
||||
CV_Assert( gsrc.type() == CV_8UC1 );
|
||||
#else
|
||||
CV_Assert( (gsrc.type() == CV_8UC1) || (gsrc.type() == CV_32FC1) );
|
||||
#endif
|
||||
|
||||
GpuMat gdst = getOutputMat(dst, 1, 2, CV_64FC1, stream);
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = gsrc.cols;
|
||||
sz.height = gsrc.rows;
|
||||
|
||||
#if (NPP_VERSION >= 12205)
|
||||
size_t bufSize;
|
||||
#else
|
||||
int bufSize;
|
||||
#endif
|
||||
|
||||
NppStreamHandler h(StreamAccessor::getStream(stream));
|
||||
|
||||
#if (CUDA_VERSION <= 4020)
|
||||
nppSafeCall( nppiMeanStdDev8uC1RGetBufferHostSize(sz, &bufSize) );
|
||||
#else
|
||||
#if USE_NPP_STREAM_CTX
|
||||
if (gsrc.type() == CV_8UC1)
|
||||
nppSafeCall(nppiMeanStdDevGetBufferHostSize_8u_C1R_Ctx(sz, &bufSize, h));
|
||||
else
|
||||
nppSafeCall(nppiMeanStdDevGetBufferHostSize_32f_C1R_Ctx(sz, &bufSize, h));
|
||||
#else
|
||||
if (gsrc.type() == CV_8UC1)
|
||||
nppSafeCall( nppiMeanStdDevGetBufferHostSize_8u_C1R(sz, &bufSize) );
|
||||
else
|
||||
nppSafeCall( nppiMeanStdDevGetBufferHostSize_32f_C1R(sz, &bufSize) );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
BufferPool pool(stream);
|
||||
CV_Assert(bufSize <= std::numeric_limits<int>::max());
|
||||
GpuMat buf = pool.getBuffer(1, static_cast<int>(bufSize), gsrc.type());
|
||||
#if USE_NPP_STREAM_CTX
|
||||
if (gsrc.type() == CV_8UC1)
|
||||
nppSafeCall(nppiMean_StdDev_8u_C1R_Ctx(gsrc.ptr<Npp8u>(), static_cast<int>(gsrc.step), sz, buf.ptr<Npp8u>(), gdst.ptr<Npp64f>(), gdst.ptr<Npp64f>() + 1, h));
|
||||
else
|
||||
nppSafeCall(nppiMean_StdDev_32f_C1R_Ctx(gsrc.ptr<Npp32f>(), static_cast<int>(gsrc.step), sz, buf.ptr<Npp8u>(), gdst.ptr<Npp64f>(), gdst.ptr<Npp64f>() + 1, h));
|
||||
#else
|
||||
if(gsrc.type() == CV_8UC1)
|
||||
nppSafeCall( nppiMean_StdDev_8u_C1R(gsrc.ptr<Npp8u>(), static_cast<int>(gsrc.step), sz, buf.ptr<Npp8u>(), gdst.ptr<Npp64f>(), gdst.ptr<Npp64f>() + 1) );
|
||||
else
|
||||
nppSafeCall( nppiMean_StdDev_32f_C1R(gsrc.ptr<Npp32f>(), static_cast<int>(gsrc.step), sz, buf.ptr<Npp8u>(), gdst.ptr<Npp64f>(), gdst.ptr<Npp64f>() + 1) );
|
||||
#endif
|
||||
|
||||
syncOutput(gdst, dst, stream);
|
||||
}
|
||||
|
||||
void cv::cuda::meanStdDev(InputArray src, Scalar& mean, Scalar& stddev)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem dst;
|
||||
meanStdDev(src, dst, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
double vals[2];
|
||||
dst.createMatHeader().copyTo(Mat(1, 2, CV_64FC1, &vals[0]));
|
||||
|
||||
mean = Scalar(vals[0]);
|
||||
stddev = Scalar(vals[1]);
|
||||
}
|
||||
|
||||
void cv::cuda::meanStdDev(InputArray _src, Scalar& mean, Scalar& stddev, InputArray _mask)
|
||||
{
|
||||
Stream& stream = Stream::Null();
|
||||
|
||||
HostMem dst;
|
||||
meanStdDev(_src, dst, _mask, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
double vals[2];
|
||||
dst.createMatHeader().copyTo(Mat(1, 2, CV_64FC1, &vals[0]));
|
||||
|
||||
mean = Scalar(vals[0]);
|
||||
stddev = Scalar(vals[1]);
|
||||
}
|
||||
|
||||
void cv::cuda::meanStdDev(InputArray src, OutputArray dst, InputArray mask, Stream& stream)
|
||||
{
|
||||
if (!deviceSupports(FEATURE_SET_COMPUTE_13))
|
||||
CV_Error(cv::Error::StsNotImplemented, "Not sufficient compute capebility");
|
||||
|
||||
const GpuMat gsrc = getInputMat(src, stream);
|
||||
const GpuMat gmask = getInputMat(mask, stream);
|
||||
|
||||
#if (CUDA_VERSION <= 4020)
|
||||
CV_Assert( gsrc.type() == CV_8UC1 );
|
||||
#else
|
||||
CV_Assert( (gsrc.type() == CV_8UC1) || (gsrc.type() == CV_32FC1) );
|
||||
#endif
|
||||
|
||||
GpuMat gdst = getOutputMat(dst, 1, 2, CV_64FC1, stream);
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = gsrc.cols;
|
||||
sz.height = gsrc.rows;
|
||||
|
||||
#if (NPP_VERSION >= 12205)
|
||||
size_t bufSize;
|
||||
#else
|
||||
int bufSize;
|
||||
#endif
|
||||
|
||||
NppStreamHandler h(StreamAccessor::getStream(stream));
|
||||
|
||||
#if (CUDA_VERSION <= 4020)
|
||||
nppSafeCall( nppiMeanStdDev8uC1MRGetBufferHostSize(sz, &bufSize) );
|
||||
#else
|
||||
#if USE_NPP_STREAM_CTX
|
||||
if (gsrc.type() == CV_8UC1)
|
||||
nppSafeCall(nppiMeanStdDevGetBufferHostSize_8u_C1MR_Ctx(sz, &bufSize, h));
|
||||
else
|
||||
nppSafeCall(nppiMeanStdDevGetBufferHostSize_32f_C1MR_Ctx(sz, &bufSize, h));
|
||||
#else
|
||||
if (gsrc.type() == CV_8UC1)
|
||||
nppSafeCall( nppiMeanStdDevGetBufferHostSize_8u_C1MR(sz, &bufSize) );
|
||||
else
|
||||
nppSafeCall( nppiMeanStdDevGetBufferHostSize_32f_C1MR(sz, &bufSize) );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
BufferPool pool(stream);
|
||||
CV_Assert(bufSize <= std::numeric_limits<int>::max());
|
||||
GpuMat buf = pool.getBuffer(1, static_cast<int>(bufSize), gsrc.type());
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
if (gsrc.type() == CV_8UC1)
|
||||
nppSafeCall(nppiMean_StdDev_8u_C1MR_Ctx(gsrc.ptr<Npp8u>(), static_cast<int>(gsrc.step), gmask.ptr<Npp8u>(), static_cast<int>(gmask.step),
|
||||
sz, buf.ptr<Npp8u>(), gdst.ptr<Npp64f>(), gdst.ptr<Npp64f>() + 1, h));
|
||||
else
|
||||
nppSafeCall(nppiMean_StdDev_32f_C1MR_Ctx(gsrc.ptr<Npp32f>(), static_cast<int>(gsrc.step), gmask.ptr<Npp8u>(), static_cast<int>(gmask.step),
|
||||
sz, buf.ptr<Npp8u>(), gdst.ptr<Npp64f>(), gdst.ptr<Npp64f>() + 1, h));
|
||||
#else
|
||||
if(gsrc.type() == CV_8UC1)
|
||||
nppSafeCall( nppiMean_StdDev_8u_C1MR(gsrc.ptr<Npp8u>(), static_cast<int>(gsrc.step), gmask.ptr<Npp8u>(), static_cast<int>(gmask.step),
|
||||
sz, buf.ptr<Npp8u>(), gdst.ptr<Npp64f>(), gdst.ptr<Npp64f>() + 1) );
|
||||
else
|
||||
nppSafeCall( nppiMean_StdDev_32f_C1MR(gsrc.ptr<Npp32f>(), static_cast<int>(gsrc.step), gmask.ptr<Npp8u>(), static_cast<int>(gmask.step),
|
||||
sz, buf.ptr<Npp8u>(), gdst.ptr<Npp64f>(), gdst.ptr<Npp64f>() + 1) );
|
||||
#endif
|
||||
|
||||
syncOutput(gdst, dst, stream);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// rectStdDev
|
||||
|
||||
void cv::cuda::rectStdDev(InputArray _src, InputArray _sqr, OutputArray _dst, Rect rect, Stream& _stream)
|
||||
{
|
||||
GpuMat src = getInputMat(_src, _stream);
|
||||
GpuMat sqr = getInputMat(_sqr, _stream);
|
||||
|
||||
CV_Assert( src.type() == CV_32SC1 && sqr.type() == CV_64FC1 );
|
||||
|
||||
GpuMat dst = getOutputMat(_dst, src.size(), CV_32FC1, _stream);
|
||||
|
||||
NppiSize sz;
|
||||
sz.width = src.cols;
|
||||
sz.height = src.rows;
|
||||
|
||||
NppiRect nppRect;
|
||||
nppRect.height = rect.height;
|
||||
nppRect.width = rect.width;
|
||||
nppRect.x = rect.x;
|
||||
nppRect.y = rect.y;
|
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
#if USE_NPP_STREAM_CTX
|
||||
nppSafeCall(nppiRectStdDev_32s32f_C1R_Ctx(src.ptr<Npp32s>(), static_cast<int>(src.step), sqr.ptr<Npp64f>(), static_cast<int>(sqr.step),
|
||||
dst.ptr<Npp32f>(), static_cast<int>(dst.step), sz, nppRect, h));
|
||||
#else
|
||||
nppSafeCall( nppiRectStdDev_32s32f_C1R(src.ptr<Npp32s>(), static_cast<int>(src.step), sqr.ptr<Npp64f>(), static_cast<int>(sqr.step),
|
||||
dst.ptr<Npp32f>(), static_cast<int>(dst.step), sz, nppRect) );
|
||||
#endif
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
|
||||
syncOutput(dst, _dst, _stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,433 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// GEMM
|
||||
|
||||
#ifdef HAVE_CUBLAS
|
||||
|
||||
CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T);
|
||||
#define ALL_GEMM_FLAGS testing::Values(GemmFlags(0), GemmFlags(cv::GEMM_1_T), GemmFlags(cv::GEMM_2_T), GemmFlags(cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T | cv::GEMM_3_T))
|
||||
|
||||
PARAM_TEST_CASE(GEMM, cv::cuda::DeviceInfo, cv::Size, MatType, GemmFlags, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int flags;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
flags = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GEMM, Accuracy)
|
||||
{
|
||||
cv::Mat src1 = randomMat(size, type, -10.0, 10.0);
|
||||
cv::Mat src2 = randomMat(size, type, -10.0, 10.0);
|
||||
cv::Mat src3 = randomMat(size, type, -10.0, 10.0);
|
||||
double alpha = randomDouble(-10.0, 10.0);
|
||||
double beta = randomDouble(-10.0, 10.0);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::gemm(loadMat(src1), loadMat(src2), alpha, loadMat(src3), beta, dst, flags);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else if (type == CV_64FC2 && flags != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::gemm(loadMat(src1), loadMat(src2), alpha, loadMat(src3), beta, dst, flags);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsNotImplemented, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::cuda::gemm(loadMat(src1, useRoi), loadMat(src2, useRoi), alpha, loadMat(src3, useRoi), beta, dst, flags);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::gemm(src1, src2, alpha, src3, beta, dst_gold, flags);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, CV_MAT_DEPTH(type) == CV_32F ? 1e-1 : 1e-10);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, GEMM, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_32FC1), MatType(CV_32FC2), MatType(CV_64FC1), MatType(CV_64FC2)),
|
||||
ALL_GEMM_FLAGS,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// MulSpectrums
|
||||
|
||||
CV_FLAGS(DftFlags, 0, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT)
|
||||
|
||||
PARAM_TEST_CASE(MulSpectrums, cv::cuda::DeviceInfo, cv::Size, DftFlags)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int flag;
|
||||
|
||||
cv::Mat a, b;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
flag = GET_PARAM(2);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
a = randomMat(size, CV_32FC2);
|
||||
b = randomMat(size, CV_32FC2);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(MulSpectrums, Simple)
|
||||
{
|
||||
cv::cuda::GpuMat c;
|
||||
cv::cuda::mulSpectrums(loadMat(a), loadMat(b), c, flag, false);
|
||||
|
||||
cv::Mat c_gold;
|
||||
cv::mulSpectrums(a, b, c_gold, flag, false);
|
||||
|
||||
EXPECT_MAT_NEAR(c_gold, c, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(MulSpectrums, Scaled)
|
||||
{
|
||||
float scale = 1.f / size.area();
|
||||
|
||||
cv::cuda::GpuMat c;
|
||||
cv::cuda::mulAndScaleSpectrums(loadMat(a), loadMat(b), c, flag, scale, false);
|
||||
|
||||
cv::Mat c_gold;
|
||||
cv::mulSpectrums(a, b, c_gold, flag, false);
|
||||
c_gold.convertTo(c_gold, c_gold.type(), scale);
|
||||
|
||||
EXPECT_MAT_NEAR(c_gold, c, 1e-2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, MulSpectrums, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(DftFlags(0), DftFlags(cv::DFT_ROWS))));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Dft
|
||||
|
||||
struct Dft : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GetParam();
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
void testC2C(const std::string& hint, int cols, int rows, int flags, bool inplace)
|
||||
{
|
||||
SCOPED_TRACE(hint);
|
||||
|
||||
cv::Mat a = randomMat(cv::Size(cols, rows), CV_32FC2, 0.0, 10.0);
|
||||
|
||||
cv::Mat b_gold;
|
||||
cv::dft(a, b_gold, flags);
|
||||
|
||||
cv::cuda::GpuMat d_b;
|
||||
cv::cuda::GpuMat d_b_data;
|
||||
if (inplace)
|
||||
{
|
||||
d_b_data.create(1, a.size().area(), CV_32FC2);
|
||||
d_b = cv::cuda::GpuMat(a.rows, a.cols, CV_32FC2, d_b_data.ptr(), a.cols * d_b_data.elemSize());
|
||||
}
|
||||
cv::cuda::dft(loadMat(a), d_b, cv::Size(cols, rows), flags);
|
||||
|
||||
EXPECT_TRUE(!inplace || d_b.ptr() == d_b_data.ptr());
|
||||
ASSERT_EQ(CV_32F, d_b.depth());
|
||||
ASSERT_EQ(2, d_b.channels());
|
||||
EXPECT_MAT_NEAR(b_gold, cv::Mat(d_b), rows * cols * 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Dft, C2C)
|
||||
{
|
||||
int cols = randomInt(2, 100);
|
||||
int rows = randomInt(2, 100);
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
bool inplace = i != 0;
|
||||
|
||||
testC2C("no flags", cols, rows, 0, inplace);
|
||||
testC2C("no flags 0 1", cols, rows + 1, 0, inplace);
|
||||
testC2C("no flags 1 0", cols, rows + 1, 0, inplace);
|
||||
testC2C("no flags 1 1", cols + 1, rows, 0, inplace);
|
||||
testC2C("DFT_INVERSE", cols, rows, cv::DFT_INVERSE, inplace);
|
||||
testC2C("DFT_ROWS", cols, rows, cv::DFT_ROWS, inplace);
|
||||
testC2C("single col", 1, rows, 0, inplace);
|
||||
testC2C("single row", cols, 1, 0, inplace);
|
||||
testC2C("single col inversed", 1, rows, cv::DFT_INVERSE, inplace);
|
||||
testC2C("single row inversed", cols, 1, cv::DFT_INVERSE, 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);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Dft, Algorithm)
|
||||
{
|
||||
int cols = randomInt(2, 100);
|
||||
int rows = randomInt(2, 100);
|
||||
|
||||
int flags = 0 | DFT_COMPLEX_INPUT;
|
||||
cv::Ptr<cv::cuda::DFT> dft = cv::cuda::createDFT(cv::Size(cols, rows), flags);
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
SCOPED_TRACE("dft algorithm");
|
||||
|
||||
cv::Mat a = randomMat(cv::Size(cols, rows), CV_32FC2, 0.0, 10.0);
|
||||
|
||||
cv::cuda::GpuMat d_b;
|
||||
cv::cuda::GpuMat d_b_data;
|
||||
dft->compute(loadMat(a), d_b);
|
||||
|
||||
cv::Mat b_gold;
|
||||
cv::dft(a, b_gold, flags);
|
||||
|
||||
ASSERT_EQ(CV_32F, d_b.depth());
|
||||
ASSERT_EQ(2, d_b.channels());
|
||||
EXPECT_MAT_NEAR(b_gold, cv::Mat(d_b), rows * cols * 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void testR2CThenC2R(const std::string& hint, int cols, int rows, bool inplace)
|
||||
{
|
||||
SCOPED_TRACE(hint);
|
||||
|
||||
cv::Mat a = randomMat(cv::Size(cols, rows), CV_32FC1, 0.0, 10.0);
|
||||
|
||||
cv::cuda::GpuMat d_b, d_c;
|
||||
cv::cuda::GpuMat d_b_data, d_c_data;
|
||||
if (inplace)
|
||||
{
|
||||
if (a.cols == 1)
|
||||
{
|
||||
d_b_data.create(1, (a.rows / 2 + 1) * a.cols, CV_32FC2);
|
||||
d_b = cv::cuda::GpuMat(a.rows / 2 + 1, a.cols, CV_32FC2, d_b_data.ptr(), a.cols * d_b_data.elemSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
d_b_data.create(1, a.rows * (a.cols / 2 + 1), CV_32FC2);
|
||||
d_b = cv::cuda::GpuMat(a.rows, a.cols / 2 + 1, CV_32FC2, d_b_data.ptr(), (a.cols / 2 + 1) * d_b_data.elemSize());
|
||||
}
|
||||
d_c_data.create(1, a.size().area(), CV_32F);
|
||||
d_c = cv::cuda::GpuMat(a.rows, a.cols, CV_32F, d_c_data.ptr(), a.cols * d_c_data.elemSize());
|
||||
}
|
||||
|
||||
cv::cuda::dft(loadMat(a), d_b, cv::Size(cols, rows), 0);
|
||||
cv::cuda::dft(d_b, d_c, cv::Size(cols, rows), cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
|
||||
|
||||
EXPECT_TRUE(!inplace || d_b.ptr() == d_b_data.ptr());
|
||||
EXPECT_TRUE(!inplace || d_c.ptr() == d_c_data.ptr());
|
||||
ASSERT_EQ(CV_32F, d_c.depth());
|
||||
ASSERT_EQ(1, d_c.channels());
|
||||
|
||||
cv::Mat c(d_c);
|
||||
EXPECT_MAT_NEAR(a, c, rows * cols * 1e-5);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Dft, R2CThenC2R)
|
||||
{
|
||||
int cols = randomInt(2, 100);
|
||||
int rows = randomInt(2, 100);
|
||||
|
||||
testR2CThenC2R("sanity", cols, rows, false);
|
||||
testR2CThenC2R("sanity 0 1", cols, rows + 1, false);
|
||||
testR2CThenC2R("sanity 1 0", cols + 1, rows, false);
|
||||
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, false);
|
||||
testR2CThenC2R("single col", 1, rows, false);
|
||||
testR2CThenC2R("single col 1", 1, rows + 1, false);
|
||||
testR2CThenC2R("single row", cols, 1, false);
|
||||
testR2CThenC2R("single row 1", cols + 1, 1, false);
|
||||
|
||||
testR2CThenC2R("sanity", cols, rows, true);
|
||||
testR2CThenC2R("sanity 0 1", cols, rows + 1, true);
|
||||
testR2CThenC2R("sanity 1 0", cols + 1, rows, true);
|
||||
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, true);
|
||||
testR2CThenC2R("single row", cols, 1, true);
|
||||
testR2CThenC2R("single row 1", cols + 1, 1, true);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Dft, ALL_DEVICES);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Convolve
|
||||
|
||||
namespace
|
||||
{
|
||||
void convolveDFT(const cv::Mat& A, const cv::Mat& B, cv::Mat& C, bool ccorr = false)
|
||||
{
|
||||
// reallocate the output array if needed
|
||||
C.create(std::abs(A.rows - B.rows) + 1, std::abs(A.cols - B.cols) + 1, A.type());
|
||||
cv::Size dftSize;
|
||||
|
||||
// compute the size of DFT transform
|
||||
dftSize.width = cv::getOptimalDFTSize(A.cols + B.cols - 1);
|
||||
dftSize.height = cv::getOptimalDFTSize(A.rows + B.rows - 1);
|
||||
|
||||
// allocate temporary buffers and initialize them with 0s
|
||||
cv::Mat tempA(dftSize, A.type(), cv::Scalar::all(0));
|
||||
cv::Mat tempB(dftSize, B.type(), cv::Scalar::all(0));
|
||||
|
||||
// copy A and B to the top-left corners of tempA and tempB, respectively
|
||||
cv::Mat roiA(tempA, cv::Rect(0, 0, A.cols, A.rows));
|
||||
A.copyTo(roiA);
|
||||
cv::Mat roiB(tempB, cv::Rect(0, 0, B.cols, B.rows));
|
||||
B.copyTo(roiB);
|
||||
|
||||
// now transform the padded A & B in-place;
|
||||
// use "nonzeroRows" hint for faster processing
|
||||
cv::dft(tempA, tempA, 0, A.rows);
|
||||
cv::dft(tempB, tempB, 0, B.rows);
|
||||
|
||||
// multiply the spectrums;
|
||||
// the function handles packed spectrum representations well
|
||||
cv::mulSpectrums(tempA, tempB, tempA, 0, ccorr);
|
||||
|
||||
// transform the product back from the frequency domain.
|
||||
// Even though all the result rows will be non-zero,
|
||||
// you need only the first C.rows of them, and thus you
|
||||
// pass nonzeroRows == C.rows
|
||||
cv::dft(tempA, tempA, cv::DFT_INVERSE + cv::DFT_SCALE, C.rows);
|
||||
|
||||
// now copy the result back to C.
|
||||
tempA(cv::Rect(0, 0, C.cols, C.rows)).copyTo(C);
|
||||
}
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(KSize, int)
|
||||
IMPLEMENT_PARAM_CLASS(Ccorr, bool)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(Convolve, cv::cuda::DeviceInfo, cv::Size, KSize, Ccorr)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int ksize;
|
||||
bool ccorr;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
ksize = GET_PARAM(2);
|
||||
ccorr = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Convolve, Accuracy)
|
||||
{
|
||||
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::Ptr<cv::cuda::Convolution> conv = cv::cuda::createConvolution();
|
||||
|
||||
cv::cuda::GpuMat dst;
|
||||
conv->convolve(loadMat(src), loadMat(kernel), dst, ccorr);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
convolveDFT(src, kernel, dst_gold, ccorr);
|
||||
|
||||
EXPECT_MAT_NEAR(dst, dst_gold, 1e-1);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Convolve, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(KSize(3), KSize(7), KSize(11), KSize(17), KSize(19), KSize(23), KSize(45)),
|
||||
testing::Values(Ccorr(false), Ccorr(true))));
|
||||
|
||||
#endif // HAVE_CUBLAS
|
||||
|
||||
}} // namespace
|
||||
|
||||
#endif // HAVE_CUDA
|
||||
@@ -0,0 +1,120 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
struct BufferPoolTest : TestWithParam<DeviceInfo>
|
||||
{
|
||||
void RunSimpleTest(Stream& stream, HostMem& dst_1, HostMem& dst_2)
|
||||
{
|
||||
BufferPool pool(stream);
|
||||
|
||||
{
|
||||
GpuMat buf0 = pool.getBuffer(Size(640, 480), CV_8UC1);
|
||||
EXPECT_FALSE( buf0.empty() );
|
||||
|
||||
buf0.setTo(Scalar::all(0), stream);
|
||||
|
||||
GpuMat buf1 = pool.getBuffer(Size(640, 480), CV_8UC1);
|
||||
EXPECT_FALSE( buf1.empty() );
|
||||
|
||||
buf0.convertTo(buf1, buf1.type(), 1.0, 1.0, stream);
|
||||
|
||||
buf1.download(dst_1, stream);
|
||||
}
|
||||
|
||||
{
|
||||
GpuMat buf2 = pool.getBuffer(Size(1280, 1024), CV_32SC1);
|
||||
EXPECT_FALSE( buf2.empty() );
|
||||
|
||||
buf2.setTo(Scalar::all(2), stream);
|
||||
|
||||
buf2.download(dst_2, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckSimpleTest(HostMem& dst_1, HostMem& dst_2)
|
||||
{
|
||||
EXPECT_MAT_NEAR(Mat(Size(640, 480), CV_8UC1, Scalar::all(1)), dst_1, 0.0);
|
||||
EXPECT_MAT_NEAR(Mat(Size(1280, 1024), CV_32SC1, Scalar::all(2)), dst_2, 0.0);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(BufferPoolTest, FromNullStream)
|
||||
{
|
||||
HostMem dst_1, dst_2;
|
||||
|
||||
RunSimpleTest(Stream::Null(), dst_1, dst_2);
|
||||
|
||||
cudaSafeCall(cudaDeviceSynchronize());
|
||||
|
||||
CheckSimpleTest(dst_1, dst_2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(BufferPoolTest, From2Streams)
|
||||
{
|
||||
HostMem dst1_1, dst1_2;
|
||||
HostMem dst2_1, dst2_2;
|
||||
|
||||
Stream stream1, stream2;
|
||||
RunSimpleTest(stream1, dst1_1, dst1_2);
|
||||
RunSimpleTest(stream2, dst2_1, dst2_2);
|
||||
|
||||
stream1.waitForCompletion();
|
||||
stream2.waitForCompletion();
|
||||
|
||||
CheckSimpleTest(dst1_1, dst1_2);
|
||||
CheckSimpleTest(dst2_1, dst2_2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Stream, BufferPoolTest, ALL_DEVICES);
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
@@ -0,0 +1,439 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Merge
|
||||
|
||||
PARAM_TEST_CASE(Merge, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
int channels;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
channels = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Merge, Accuracy)
|
||||
{
|
||||
std::vector<cv::Mat> src;
|
||||
src.reserve(channels);
|
||||
for (int i = 0; i < channels; ++i)
|
||||
src.push_back(cv::Mat(size, depth, cv::Scalar::all(i)));
|
||||
|
||||
std::vector<cv::cuda::GpuMat> d_src;
|
||||
for (int i = 0; i < channels; ++i)
|
||||
d_src.push_back(loadMat(src[i], useRoi));
|
||||
|
||||
if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::merge(d_src, dst);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::merge(d_src, dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::merge(src, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Merge, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_DEPTH,
|
||||
testing::Values(1, 2, 3, 4),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Split
|
||||
|
||||
PARAM_TEST_CASE(Split, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
int channels;
|
||||
bool useRoi;
|
||||
|
||||
int type;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
channels = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
type = CV_MAKE_TYPE(depth, channels);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Split, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<cv::cuda::GpuMat> dst;
|
||||
cv::cuda::split(loadMat(src), dst);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<cv::cuda::GpuMat> dst;
|
||||
cv::cuda::split(loadMat(src, useRoi), dst);
|
||||
|
||||
std::vector<cv::Mat> dst_gold;
|
||||
cv::split(src, dst_gold);
|
||||
|
||||
ASSERT_EQ(dst_gold.size(), dst.size());
|
||||
|
||||
for (size_t i = 0; i < dst_gold.size(); ++i)
|
||||
{
|
||||
EXPECT_MAT_NEAR(dst_gold[i], dst[i], 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Split, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_DEPTH,
|
||||
testing::Values(1, 2, 3, 4),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Transpose
|
||||
|
||||
PARAM_TEST_CASE(Transpose, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Transpose, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat dst;
|
||||
cv::cuda::transpose(loadMat(src), dst);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat dst = createMat(cv::Size(size.height, size.width), type, useRoi);
|
||||
cv::cuda::transpose(loadMat(src, useRoi), dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::transpose(src, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Transpose, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1),
|
||||
MatType(CV_8UC4),
|
||||
MatType(CV_16UC2),
|
||||
MatType(CV_16SC2),
|
||||
MatType(CV_32SC1),
|
||||
MatType(CV_32SC2),
|
||||
MatType(CV_64FC1)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Flip
|
||||
|
||||
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
|
||||
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
|
||||
#define ALL_FLIP_CODES testing::Values(FlipCode(FLIP_BOTH), FlipCode(FLIP_X), FlipCode(FLIP_Y))
|
||||
|
||||
PARAM_TEST_CASE(Flip, cv::cuda::DeviceInfo, cv::Size, MatType, FlipCode, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int flip_code;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
flip_code = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Flip, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::cuda::GpuMat dst = createMat(size, type, useRoi);
|
||||
cv::cuda::flip(loadMat(src, useRoi), dst, flip_code);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::flip(src, dst_gold, flip_code);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Flip, AccuracyInplace)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
bool isSizeOdd = ((size.width & 1) == 1) || ((size.height & 1) == 1);
|
||||
cv::cuda::GpuMat srcDst = loadMat(src, useRoi);
|
||||
if(isSizeOdd)
|
||||
{
|
||||
EXPECT_THROW(cv::cuda::flip(srcDst, srcDst, flip_code), cv::Exception);
|
||||
return;
|
||||
}
|
||||
cv::cuda::flip(srcDst, srcDst, flip_code);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::flip(src, dst_gold, flip_code);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, srcDst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Flip, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1),
|
||||
MatType(CV_8UC3),
|
||||
MatType(CV_8UC4),
|
||||
MatType(CV_16UC1),
|
||||
MatType(CV_16UC3),
|
||||
MatType(CV_16UC4),
|
||||
MatType(CV_32SC1),
|
||||
MatType(CV_32SC3),
|
||||
MatType(CV_32SC4),
|
||||
MatType(CV_32FC1),
|
||||
MatType(CV_32FC3),
|
||||
MatType(CV_32FC4)),
|
||||
ALL_FLIP_CODES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// LUT
|
||||
|
||||
PARAM_TEST_CASE(LUT, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(LUT, OneChannel)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat lut = randomMat(cv::Size(256, 1), CV_8UC1);
|
||||
|
||||
cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
|
||||
|
||||
cv::cuda::GpuMat dst = createMat(size, CV_MAKE_TYPE(lut.depth(), src.channels()));
|
||||
lutAlg->transform(loadMat(src, useRoi), dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::LUT(src, lut, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(LUT, MultiChannel)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Mat lut = randomMat(cv::Size(256, 1), CV_MAKE_TYPE(CV_8U, src.channels()));
|
||||
|
||||
cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
|
||||
|
||||
cv::cuda::GpuMat dst = createMat(size, CV_MAKE_TYPE(lut.depth(), src.channels()), useRoi);
|
||||
lutAlg->transform(loadMat(src, useRoi), dst);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::LUT(src, lut, dst_gold);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, LUT, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3)),
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// CopyMakeBorder
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(Border, int)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(CopyMakeBorder, cv::cuda::DeviceInfo, cv::Size, MatType, Border, BorderType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
int border;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
border = GET_PARAM(3);
|
||||
borderType = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(CopyMakeBorder, Accuracy)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
cv::Scalar val = randomScalar(0, 255);
|
||||
|
||||
cv::cuda::GpuMat dst = createMat(cv::Size(size.width + 2 * border, size.height + 2 * border), type, useRoi);
|
||||
cv::cuda::copyMakeBorder(loadMat(src, useRoi), dst, border, border, border, border, borderType, val);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::copyMakeBorder(src, dst_gold, border, border, border, border, borderType, val);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Arithm, CopyMakeBorder, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
testing::Values(MatType(CV_8UC1),
|
||||
MatType(CV_8UC3),
|
||||
MatType(CV_8UC4),
|
||||
MatType(CV_16UC1),
|
||||
MatType(CV_16UC3),
|
||||
MatType(CV_16UC4),
|
||||
MatType(CV_32FC1),
|
||||
MatType(CV_32FC3),
|
||||
MatType(CV_32FC4)),
|
||||
testing::Values(Border(1), Border(10), Border(50)),
|
||||
ALL_BORDER_TYPES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,104 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/core/cuda_stream_accessor.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
struct AsyncEvent : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
cv::cuda::HostMem src;
|
||||
cv::cuda::GpuMat d_src;
|
||||
|
||||
cv::cuda::HostMem dst;
|
||||
cv::cuda::GpuMat d_dst;
|
||||
|
||||
cv::cuda::Stream stream;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo = GetParam();
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
src = cv::cuda::HostMem(cv::cuda::HostMem::PAGE_LOCKED);
|
||||
|
||||
cv::Mat m = randomMat(cv::Size(128, 128), CV_8UC1);
|
||||
m.copyTo(src);
|
||||
}
|
||||
};
|
||||
|
||||
void deviceWork(void* userData)
|
||||
{
|
||||
AsyncEvent* test = reinterpret_cast<AsyncEvent*>(userData);
|
||||
test->d_src.upload(test->src, test->stream);
|
||||
test->d_src.convertTo(test->d_dst, CV_32S, test->stream);
|
||||
test->d_dst.download(test->dst, test->stream);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(AsyncEvent, WrapEvent)
|
||||
{
|
||||
cudaEvent_t cuda_event = NULL;
|
||||
ASSERT_EQ(cudaSuccess, cudaEventCreate(&cuda_event));
|
||||
{
|
||||
cv::cuda::Event cudaEvent = cv::cuda::EventAccessor::wrapEvent(cuda_event);
|
||||
deviceWork(this);
|
||||
cudaEvent.record(stream);
|
||||
cudaEvent.waitForCompletion();
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
}
|
||||
ASSERT_EQ(cudaSuccess, cudaEventDestroy(cuda_event));
|
||||
}
|
||||
|
||||
CUDA_TEST_P(AsyncEvent, WithFlags)
|
||||
{
|
||||
cv::cuda::Event cudaEvent = cv::cuda::Event(cv::cuda::Event::CreateFlags::BLOCKING_SYNC);
|
||||
deviceWork(this);
|
||||
cudaEvent.record(stream);
|
||||
cudaEvent.waitForCompletion();
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(AsyncEvent, Timing)
|
||||
{
|
||||
const std::vector<cv::cuda::Event::CreateFlags> eventFlags = { cv::cuda::Event::CreateFlags::BLOCKING_SYNC , cv::cuda::Event::CreateFlags::BLOCKING_SYNC | Event::CreateFlags::DISABLE_TIMING };
|
||||
const std::vector<bool> shouldFail = { false, true };
|
||||
for (size_t i = 0; i < eventFlags.size(); i++) {
|
||||
const auto& flags = eventFlags.at(i);
|
||||
cv::cuda::Event startEvent = cv::cuda::Event(flags);
|
||||
cv::cuda::Event stopEvent = cv::cuda::Event(flags);
|
||||
startEvent.record(stream);
|
||||
deviceWork(this);
|
||||
stopEvent.record(stream);
|
||||
stopEvent.waitForCompletion();
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
bool failed = false;
|
||||
try {
|
||||
const double elTimeMs = Event::elapsedTime(startEvent, stopEvent);
|
||||
ASSERT_GT(elTimeMs, 0);
|
||||
}
|
||||
catch (const cv::Exception& ex) {
|
||||
failed = true;
|
||||
}
|
||||
ASSERT_EQ(failed, shouldFail.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Event, AsyncEvent, ALL_DEVICES);
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
@@ -0,0 +1,514 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// SetTo
|
||||
|
||||
PARAM_TEST_CASE(GpuMat_SetTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GpuMat_SetTo, Zero)
|
||||
{
|
||||
cv::Scalar zero = cv::Scalar::all(0);
|
||||
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(zero);
|
||||
|
||||
EXPECT_MAT_NEAR(cv::Mat::zeros(size, type), mat, 0.0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_SetTo, SameVal)
|
||||
{
|
||||
cv::Scalar val = cv::Scalar::all(randomDouble(0.0, 255.0));
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val);
|
||||
|
||||
EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_SetTo, DifferentVal)
|
||||
{
|
||||
cv::Scalar val = randomScalar(0.0, 255.0);
|
||||
|
||||
if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val);
|
||||
|
||||
EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_SetTo, Masked)
|
||||
{
|
||||
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::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat mat = createMat(size, type, useRoi);
|
||||
mat.setTo(val, loadMat(mask));
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::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);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_SetTo, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_TYPES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// CopyTo
|
||||
|
||||
PARAM_TEST_CASE(GpuMat_CopyTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int type;
|
||||
bool useRoi;
|
||||
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
type = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GpuMat_CopyTo, WithOutMask)
|
||||
{
|
||||
cv::Mat src = randomMat(size, type);
|
||||
|
||||
cv::cuda::GpuMat d_src = loadMat(src, useRoi);
|
||||
cv::cuda::GpuMat dst = createMat(size, type, useRoi);
|
||||
d_src.copyTo(dst);
|
||||
|
||||
EXPECT_MAT_NEAR(src, dst, 0.0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_CopyTo, Masked)
|
||||
{
|
||||
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::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
d_src.copyTo(dst, loadMat(mask, useRoi));
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src, useRoi);
|
||||
cv::cuda::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);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_CopyTo, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_TYPES,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ConvertTo
|
||||
|
||||
PARAM_TEST_CASE(GpuMat_ConvertTo, cv::cuda::DeviceInfo, cv::Size, MatDepth, MatDepth, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth1;
|
||||
int depth2;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth1 = GET_PARAM(2);
|
||||
depth2 = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GpuMat_ConvertTo, WithOutScaling)
|
||||
{
|
||||
cv::Mat src = randomMat(size, depth1);
|
||||
|
||||
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
d_src.convertTo(dst, depth2);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src, useRoi);
|
||||
cv::cuda::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, depth2 < CV_32F ? 1.0 : 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_ConvertTo, WithScaling)
|
||||
{
|
||||
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::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src);
|
||||
cv::cuda::GpuMat dst;
|
||||
d_src.convertTo(dst, depth2, a, b);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_src = loadMat(src, useRoi);
|
||||
cv::cuda::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);
|
||||
}
|
||||
}
|
||||
|
||||
CUDA_TEST_P(GpuMat_ConvertTo, InplaceWithOutScaling)
|
||||
{
|
||||
cv::Mat src = randomMat(size, depth1);
|
||||
|
||||
if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_srcDst = loadMat(src);
|
||||
d_srcDst.convertTo(d_srcDst, depth2);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_srcDst = loadMat(src, useRoi);
|
||||
d_srcDst.convertTo(d_srcDst, depth2);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.convertTo(dst_gold, depth2);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, d_srcDst, depth2 < CV_32F ? 1.0 : 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CUDA_TEST_P(GpuMat_ConvertTo, InplaceWithScaling)
|
||||
{
|
||||
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::cuda::NATIVE_DOUBLE))
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::cuda::GpuMat d_srcDst = loadMat(src);
|
||||
d_srcDst.convertTo(d_srcDst, depth2, a, b);
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::cuda::GpuMat d_srcDst = loadMat(src, useRoi);
|
||||
d_srcDst.convertTo(d_srcDst, depth2, a, b);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.convertTo(dst_gold, depth2, a, b);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, d_srcDst, depth2 < CV_32F ? 1.0 : 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_ConvertTo, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_DEPTH,
|
||||
ALL_DEPTH,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// locateROI
|
||||
|
||||
PARAM_TEST_CASE(GpuMat_LocateROI, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(GpuMat_LocateROI, locateROI)
|
||||
{
|
||||
Point ofsGold;
|
||||
Size wholeSizeGold;
|
||||
GpuMat src = createMat(size, depth, wholeSizeGold, ofsGold, useRoi);
|
||||
|
||||
Point ofs;
|
||||
Size wholeSize;
|
||||
src.locateROI(wholeSize, ofs);
|
||||
ASSERT_TRUE(ofs == ofsGold && wholeSize == wholeSizeGold);
|
||||
|
||||
GpuMat srcPtr(src.size(), src.type(), src.data, src.step);
|
||||
src.locateROI(wholeSize, ofs);
|
||||
ASSERT_TRUE(ofs == ofsGold && wholeSize == wholeSizeGold);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_LocateROI, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
ALL_DEPTH,
|
||||
WHOLE_SUBMAT));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ensureSizeIsEnough
|
||||
|
||||
struct EnsureSizeIsEnough : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
virtual void SetUp()
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo = GetParam();
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(EnsureSizeIsEnough, BufferReuse)
|
||||
{
|
||||
cv::cuda::GpuMat buffer(100, 100, CV_8U);
|
||||
cv::cuda::GpuMat old = buffer;
|
||||
|
||||
// don't reallocate memory
|
||||
cv::cuda::ensureSizeIsEnough(10, 20, CV_8U, buffer);
|
||||
EXPECT_EQ(10, buffer.rows);
|
||||
EXPECT_EQ(20, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_EQ(reinterpret_cast<intptr_t>(old.data), reinterpret_cast<intptr_t>(buffer.data));
|
||||
|
||||
// don't reallocate memory
|
||||
cv::cuda::ensureSizeIsEnough(20, 30, CV_8U, buffer);
|
||||
EXPECT_EQ(20, buffer.rows);
|
||||
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));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, EnsureSizeIsEnough, ALL_DEVICES);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// createContinuous
|
||||
|
||||
struct CreateContinuous : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
virtual void SetUp()
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo = GetParam();
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(CreateContinuous, BufferReuse)
|
||||
{
|
||||
cv::cuda::GpuMat buffer;
|
||||
|
||||
cv::cuda::createContinuous(100, 100, CV_8UC1, buffer);
|
||||
EXPECT_EQ(100, buffer.rows);
|
||||
EXPECT_EQ(100, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_TRUE(buffer.isContinuous());
|
||||
EXPECT_EQ(buffer.cols * sizeof(uchar), buffer.step);
|
||||
|
||||
cv::cuda::createContinuous(10, 1000, CV_8UC1, buffer);
|
||||
EXPECT_EQ(10, buffer.rows);
|
||||
EXPECT_EQ(1000, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_TRUE(buffer.isContinuous());
|
||||
EXPECT_EQ(buffer.cols * sizeof(uchar), buffer.step);
|
||||
|
||||
cv::cuda::createContinuous(10, 10, CV_8UC1, buffer);
|
||||
EXPECT_EQ(10, buffer.rows);
|
||||
EXPECT_EQ(10, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_TRUE(buffer.isContinuous());
|
||||
EXPECT_EQ(buffer.cols * sizeof(uchar), buffer.step);
|
||||
|
||||
cv::cuda::createContinuous(100, 100, CV_8UC1, buffer);
|
||||
EXPECT_EQ(100, buffer.rows);
|
||||
EXPECT_EQ(100, buffer.cols);
|
||||
EXPECT_EQ(CV_8UC1, buffer.type());
|
||||
EXPECT_TRUE(buffer.isContinuous());
|
||||
EXPECT_EQ(buffer.cols * sizeof(uchar), buffer.step);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA, CreateContinuous, ALL_DEVICES);
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
@@ -0,0 +1,45 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
CV_CUDA_TEST_MAIN("gpu")
|
||||
@@ -0,0 +1,457 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#if defined(HAVE_CUDA) && defined(HAVE_OPENGL)
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/core/opengl.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Buffer
|
||||
|
||||
PARAM_TEST_CASE(Buffer, cv::Size, MatType)
|
||||
{
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
cv::Size size;
|
||||
int type;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
size = GET_PARAM(0);
|
||||
type = GET_PARAM(1);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Buffer, Constructor1)
|
||||
{
|
||||
cv::ogl::Buffer buf(size.height, size.width, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_EQ(size.height, buf.rows());
|
||||
EXPECT_EQ(size.width, buf.cols());
|
||||
EXPECT_EQ(type, buf.type());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, Constructor2)
|
||||
{
|
||||
cv::ogl::Buffer buf(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_EQ(size.height, buf.rows());
|
||||
EXPECT_EQ(size.width, buf.cols());
|
||||
EXPECT_EQ(type, buf.type());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, ConstructorFromMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, ConstructorFromGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
cv::cuda::GpuMat d_gold(gold);
|
||||
|
||||
cv::ogl::Buffer buf(d_gold, cv::ogl::Buffer::ARRAY_BUFFER);
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, ConstructorFromBuffer)
|
||||
{
|
||||
cv::ogl::Buffer buf_gold(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::ogl::Buffer buf(buf_gold);
|
||||
|
||||
EXPECT_EQ(buf_gold.bufId(), buf.bufId());
|
||||
EXPECT_EQ(buf_gold.rows(), buf.rows());
|
||||
EXPECT_EQ(buf_gold.cols(), buf.cols());
|
||||
EXPECT_EQ(buf_gold.type(), buf.type());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, Create)
|
||||
{
|
||||
cv::ogl::Buffer buf;
|
||||
buf.create(size.height, size.width, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_EQ(size.height, buf.rows());
|
||||
EXPECT_EQ(size.width, buf.cols());
|
||||
EXPECT_EQ(type, buf.type());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyFromMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf;
|
||||
buf.copyFrom(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyFromGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
cv::cuda::GpuMat d_gold(gold);
|
||||
|
||||
cv::ogl::Buffer buf;
|
||||
buf.copyFrom(d_gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyFromBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::ogl::Buffer buf;
|
||||
buf.copyFrom(buf_gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_NE(buf_gold.bufId(), buf.bufId());
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyToGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::cuda::GpuMat dst;
|
||||
buf.copyTo(dst);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, CopyToBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::ogl::Buffer dst;
|
||||
buf.copyTo(dst);
|
||||
dst.setAutoRelease(true);
|
||||
|
||||
EXPECT_NE(buf.bufId(), dst.bufId());
|
||||
|
||||
cv::Mat bufData;
|
||||
dst.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, Clone)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::ogl::Buffer dst = buf.clone(cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
EXPECT_NE(buf.bufId(), dst.bufId());
|
||||
|
||||
cv::Mat bufData;
|
||||
dst.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, MapHostRead)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat dst = buf.mapHost(cv::ogl::Buffer::READ_ONLY);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||
|
||||
buf.unmapHost();
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, MapHostWrite)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(size, type, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::Mat dst = buf.mapHost(cv::ogl::Buffer::WRITE_ONLY);
|
||||
gold.copyTo(dst);
|
||||
buf.unmapHost();
|
||||
dst.release();
|
||||
|
||||
cv::Mat bufData;
|
||||
buf.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Buffer, MapDevice)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type);
|
||||
|
||||
cv::ogl::Buffer buf(gold, cv::ogl::Buffer::ARRAY_BUFFER, true);
|
||||
|
||||
cv::cuda::GpuMat dst = buf.mapDevice();
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 0);
|
||||
|
||||
buf.unmapDevice();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(OpenGL, Buffer, testing::Combine(DIFFERENT_SIZES, ALL_TYPES));
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Texture2D
|
||||
|
||||
PARAM_TEST_CASE(Texture2D, cv::Size, MatType)
|
||||
{
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
cv::namedWindow("test", cv::WINDOW_OPENGL);
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
cv::Size size;
|
||||
int type;
|
||||
int depth;
|
||||
int cn;
|
||||
cv::ogl::Texture2D::Format format;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
size = GET_PARAM(0);
|
||||
type = GET_PARAM(1);
|
||||
|
||||
depth = CV_MAT_DEPTH(type);
|
||||
cn = CV_MAT_CN(type);
|
||||
format = cn == 1 ? cv::ogl::Texture2D::DEPTH_COMPONENT : cn == 3 ? cv::ogl::Texture2D::RGB : cn == 4 ? cv::ogl::Texture2D::RGBA : cv::ogl::Texture2D::NONE;
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(Texture2D, Constructor1)
|
||||
{
|
||||
cv::ogl::Texture2D tex(size.height, size.width, format, true);
|
||||
|
||||
EXPECT_EQ(size.height, tex.rows());
|
||||
EXPECT_EQ(size.width, tex.cols());
|
||||
EXPECT_EQ(format, tex.format());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, Constructor2)
|
||||
{
|
||||
cv::ogl::Texture2D tex(size, format, true);
|
||||
|
||||
EXPECT_EQ(size.height, tex.rows());
|
||||
EXPECT_EQ(size.width, tex.cols());
|
||||
EXPECT_EQ(format, tex.format());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, ConstructorFromMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
|
||||
cv::ogl::Texture2D tex(gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, ConstructorFromGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
cv::cuda::GpuMat d_gold(gold);
|
||||
|
||||
cv::ogl::Texture2D tex(d_gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, ConstructorFromBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||||
|
||||
cv::ogl::Texture2D tex(buf_gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, ConstructorFromTexture2D)
|
||||
{
|
||||
cv::ogl::Texture2D tex_gold(size, format, true);
|
||||
cv::ogl::Texture2D tex(tex_gold);
|
||||
|
||||
EXPECT_EQ(tex_gold.texId(), tex.texId());
|
||||
EXPECT_EQ(tex_gold.rows(), tex.rows());
|
||||
EXPECT_EQ(tex_gold.cols(), tex.cols());
|
||||
EXPECT_EQ(tex_gold.format(), tex.format());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, Create)
|
||||
{
|
||||
cv::ogl::Texture2D tex;
|
||||
tex.create(size.height, size.width, format, true);
|
||||
|
||||
EXPECT_EQ(size.height, tex.rows());
|
||||
EXPECT_EQ(size.width, tex.cols());
|
||||
EXPECT_EQ(format, tex.format());
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyFromMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
|
||||
cv::ogl::Texture2D tex;
|
||||
tex.copyFrom(gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyFromGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
cv::cuda::GpuMat d_gold(gold);
|
||||
|
||||
cv::ogl::Texture2D tex;
|
||||
tex.copyFrom(d_gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyFromBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
cv::ogl::Buffer buf_gold(gold, cv::ogl::Buffer::PIXEL_UNPACK_BUFFER, true);
|
||||
|
||||
cv::ogl::Texture2D tex;
|
||||
tex.copyFrom(buf_gold, true);
|
||||
|
||||
cv::Mat texData;
|
||||
tex.copyTo(texData, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, texData, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyToGpuMat)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
|
||||
cv::ogl::Texture2D tex(gold, true);
|
||||
|
||||
cv::cuda::GpuMat dst;
|
||||
tex.copyTo(dst, depth);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, dst, 1e-2);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Texture2D, CopyToBuffer)
|
||||
{
|
||||
cv::Mat gold = randomMat(size, type, 0, depth == CV_8U ? 255 : 1);
|
||||
|
||||
cv::ogl::Texture2D tex(gold, true);
|
||||
|
||||
cv::ogl::Buffer dst;
|
||||
tex.copyTo(dst, depth, true);
|
||||
|
||||
cv::Mat bufData;
|
||||
dst.copyTo(bufData);
|
||||
|
||||
EXPECT_MAT_NEAR(gold, bufData, 1e-2);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(OpenGL, Texture2D, testing::Combine(DIFFERENT_SIZES, testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4)));
|
||||
|
||||
}} // namespace
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
#include "opencv2/cudaarithm.hpp"
|
||||
|
||||
#include "cvconfig.h"
|
||||
|
||||
namespace opencv_test {
|
||||
using namespace cv::cuda;
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,176 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/core/cuda_stream_accessor.hpp"
|
||||
#include "opencv2/ts/cuda_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
struct Async : testing::TestWithParam<cv::cuda::DeviceInfo>
|
||||
{
|
||||
cv::cuda::HostMem src;
|
||||
cv::cuda::GpuMat d_src;
|
||||
|
||||
cv::cuda::HostMem dst;
|
||||
cv::cuda::GpuMat d_dst;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo = GetParam();
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
src = cv::cuda::HostMem(cv::cuda::HostMem::PAGE_LOCKED);
|
||||
|
||||
cv::Mat m = randomMat(cv::Size(128, 128), CV_8UC1);
|
||||
m.copyTo(src);
|
||||
}
|
||||
};
|
||||
|
||||
void checkMemSet(int status, void* userData)
|
||||
{
|
||||
ASSERT_EQ(cudaSuccess, status);
|
||||
|
||||
Async* test = reinterpret_cast<Async*>(userData);
|
||||
|
||||
cv::cuda::HostMem src = test->src;
|
||||
cv::cuda::HostMem dst = test->dst;
|
||||
|
||||
cv::Mat dst_gold = cv::Mat::zeros(src.size(), src.type());
|
||||
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Async, MemSet)
|
||||
{
|
||||
cv::cuda::Stream stream;
|
||||
|
||||
d_dst.upload(src);
|
||||
|
||||
d_dst.setTo(cv::Scalar::all(0), stream);
|
||||
d_dst.download(dst, stream);
|
||||
|
||||
Async* test = this;
|
||||
stream.enqueueHostCallback(checkMemSet, test);
|
||||
|
||||
stream.waitForCompletion();
|
||||
}
|
||||
|
||||
void checkConvert(int status, void* userData)
|
||||
{
|
||||
ASSERT_EQ(cudaSuccess, status);
|
||||
|
||||
Async* test = reinterpret_cast<Async*>(userData);
|
||||
|
||||
cv::cuda::HostMem src = test->src;
|
||||
cv::cuda::HostMem dst = test->dst;
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
|
||||
ASSERT_MAT_NEAR(dst_gold, dst, 0);
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Async, Convert)
|
||||
{
|
||||
cv::cuda::Stream stream;
|
||||
|
||||
d_src.upload(src, stream);
|
||||
d_src.convertTo(d_dst, CV_32S, stream);
|
||||
d_dst.download(dst, stream);
|
||||
|
||||
Async* test = this;
|
||||
stream.enqueueHostCallback(checkConvert, test);
|
||||
|
||||
stream.waitForCompletion();
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Async, WrapStream)
|
||||
{
|
||||
cudaStream_t cuda_stream = NULL;
|
||||
ASSERT_EQ(cudaSuccess, cudaStreamCreate(&cuda_stream));
|
||||
|
||||
{
|
||||
cv::cuda::Stream stream = cv::cuda::StreamAccessor::wrapStream(cuda_stream);
|
||||
|
||||
d_src.upload(src, stream);
|
||||
d_src.convertTo(d_dst, CV_32S, stream);
|
||||
d_dst.download(dst, stream);
|
||||
|
||||
Async* test = this;
|
||||
stream.enqueueHostCallback(checkConvert, test);
|
||||
|
||||
stream.waitForCompletion();
|
||||
}
|
||||
|
||||
ASSERT_EQ(cudaSuccess, cudaStreamDestroy(cuda_stream));
|
||||
}
|
||||
|
||||
CUDA_TEST_P(Async, HostMemAllocator)
|
||||
{
|
||||
cv::cuda::Stream stream;
|
||||
|
||||
cv::Mat h_dst;
|
||||
h_dst.allocator = cv::cuda::HostMem::getAllocator();
|
||||
|
||||
d_src.upload(src, stream);
|
||||
d_src.convertTo(d_dst, CV_32S, stream);
|
||||
d_dst.download(h_dst, stream);
|
||||
|
||||
stream.waitForCompletion();
|
||||
|
||||
cv::Mat dst_gold;
|
||||
src.createMatHeader().convertTo(dst_gold, CV_32S);
|
||||
|
||||
ASSERT_MAT_NEAR(dst_gold, h_dst, 0);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_Stream, Async, ALL_DEVICES);
|
||||
|
||||
}} // namespace
|
||||
#endif // HAVE_CUDA
|
||||
Reference in New Issue
Block a user