mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
gpuimgproc module fixes
This commit is contained in:
@@ -51,6 +51,9 @@ void cv::gpu::blendLinear(const GpuMat&, const GpuMat&, const GpuMat&, const Gpu
|
||||
|
||||
#else
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// blendLinear
|
||||
|
||||
namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace blend
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*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::gpu;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::Canny(const GpuMat&, GpuMat&, double, double, int, bool) { throw_no_cuda(); }
|
||||
void cv::gpu::Canny(const GpuMat&, CannyBuf&, GpuMat&, double, double, int, bool) { throw_no_cuda(); }
|
||||
void cv::gpu::Canny(const GpuMat&, const GpuMat&, GpuMat&, double, double, bool) { throw_no_cuda(); }
|
||||
void cv::gpu::Canny(const GpuMat&, const GpuMat&, CannyBuf&, GpuMat&, double, double, bool) { throw_no_cuda(); }
|
||||
void cv::gpu::CannyBuf::create(const Size&, int) { throw_no_cuda(); }
|
||||
void cv::gpu::CannyBuf::release() { throw_no_cuda(); }
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
void cv::gpu::CannyBuf::create(const Size& image_size, int apperture_size)
|
||||
{
|
||||
if (apperture_size > 0)
|
||||
{
|
||||
ensureSizeIsEnough(image_size, CV_32SC1, dx);
|
||||
ensureSizeIsEnough(image_size, CV_32SC1, dy);
|
||||
|
||||
if (apperture_size != 3)
|
||||
{
|
||||
filterDX = createDerivFilter_GPU(CV_8UC1, CV_32S, 1, 0, apperture_size, BORDER_REPLICATE);
|
||||
filterDY = createDerivFilter_GPU(CV_8UC1, CV_32S, 0, 1, apperture_size, BORDER_REPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
ensureSizeIsEnough(image_size, CV_32FC1, mag);
|
||||
ensureSizeIsEnough(image_size, CV_32SC1, map);
|
||||
|
||||
ensureSizeIsEnough(1, image_size.area(), CV_16UC2, st1);
|
||||
ensureSizeIsEnough(1, image_size.area(), CV_16UC2, st2);
|
||||
}
|
||||
|
||||
void cv::gpu::CannyBuf::release()
|
||||
{
|
||||
dx.release();
|
||||
dy.release();
|
||||
mag.release();
|
||||
map.release();
|
||||
st1.release();
|
||||
st2.release();
|
||||
}
|
||||
|
||||
namespace canny
|
||||
{
|
||||
void calcMagnitude(PtrStepSzb srcWhole, int xoff, int yoff, PtrStepSzi dx, PtrStepSzi dy, PtrStepSzf mag, bool L2Grad);
|
||||
void calcMagnitude(PtrStepSzi dx, PtrStepSzi dy, PtrStepSzf mag, bool L2Grad);
|
||||
|
||||
void calcMap(PtrStepSzi dx, PtrStepSzi dy, PtrStepSzf mag, PtrStepSzi map, float low_thresh, float high_thresh);
|
||||
|
||||
void edgesHysteresisLocal(PtrStepSzi map, ushort2* st1);
|
||||
|
||||
void edgesHysteresisGlobal(PtrStepSzi map, ushort2* st1, ushort2* st2);
|
||||
|
||||
void getEdges(PtrStepSzi map, PtrStepSzb dst);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void CannyCaller(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& dst, float low_thresh, float high_thresh)
|
||||
{
|
||||
using namespace canny;
|
||||
|
||||
buf.map.setTo(Scalar::all(0));
|
||||
calcMap(dx, dy, buf.mag, buf.map, low_thresh, high_thresh);
|
||||
|
||||
edgesHysteresisLocal(buf.map, buf.st1.ptr<ushort2>());
|
||||
|
||||
edgesHysteresisGlobal(buf.map, buf.st1.ptr<ushort2>(), buf.st2.ptr<ushort2>());
|
||||
|
||||
getEdges(buf.map, dst);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gpu::Canny(const GpuMat& src, GpuMat& dst, double low_thresh, double high_thresh, int apperture_size, bool L2gradient)
|
||||
{
|
||||
CannyBuf buf;
|
||||
Canny(src, buf, dst, low_thresh, high_thresh, apperture_size, L2gradient);
|
||||
}
|
||||
|
||||
void cv::gpu::Canny(const GpuMat& src, CannyBuf& buf, GpuMat& dst, double low_thresh, double high_thresh, int apperture_size, bool L2gradient)
|
||||
{
|
||||
using namespace canny;
|
||||
|
||||
CV_Assert(src.type() == CV_8UC1);
|
||||
|
||||
if (!deviceSupports(SHARED_ATOMICS))
|
||||
CV_Error(cv::Error::StsNotImplemented, "The device doesn't support shared atomics");
|
||||
|
||||
if( low_thresh > high_thresh )
|
||||
std::swap( low_thresh, high_thresh);
|
||||
|
||||
dst.create(src.size(), CV_8U);
|
||||
buf.create(src.size(), apperture_size);
|
||||
|
||||
if (apperture_size == 3)
|
||||
{
|
||||
Size wholeSize;
|
||||
Point ofs;
|
||||
src.locateROI(wholeSize, ofs);
|
||||
GpuMat srcWhole(wholeSize, src.type(), src.datastart, src.step);
|
||||
|
||||
calcMagnitude(srcWhole, ofs.x, ofs.y, buf.dx, buf.dy, buf.mag, L2gradient);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.filterDX->apply(src, buf.dx, Rect(0, 0, src.cols, src.rows));
|
||||
buf.filterDY->apply(src, buf.dy, Rect(0, 0, src.cols, src.rows));
|
||||
|
||||
calcMagnitude(buf.dx, buf.dy, buf.mag, L2gradient);
|
||||
}
|
||||
|
||||
CannyCaller(buf.dx, buf.dy, buf, dst, static_cast<float>(low_thresh), static_cast<float>(high_thresh));
|
||||
}
|
||||
|
||||
void cv::gpu::Canny(const GpuMat& dx, const GpuMat& dy, GpuMat& dst, double low_thresh, double high_thresh, bool L2gradient)
|
||||
{
|
||||
CannyBuf buf;
|
||||
Canny(dx, dy, buf, dst, low_thresh, high_thresh, L2gradient);
|
||||
}
|
||||
|
||||
void cv::gpu::Canny(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& dst, double low_thresh, double high_thresh, bool L2gradient)
|
||||
{
|
||||
using namespace canny;
|
||||
|
||||
CV_Assert(TargetArchs::builtWith(SHARED_ATOMICS) && DeviceInfo().supports(SHARED_ATOMICS));
|
||||
CV_Assert(dx.type() == CV_32SC1 && dy.type() == CV_32SC1 && dx.size() == dy.size());
|
||||
|
||||
if( low_thresh > high_thresh )
|
||||
std::swap( low_thresh, high_thresh);
|
||||
|
||||
dst.create(dx.size(), CV_8U);
|
||||
buf.create(dx.size(), -1);
|
||||
|
||||
calcMagnitude(dx, dy, buf.mag, L2gradient);
|
||||
|
||||
CannyCaller(dx, dy, buf, dst, static_cast<float>(low_thresh), static_cast<float>(high_thresh));
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
@@ -48,10 +48,16 @@ using namespace cv::gpu;
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::cvtColor(const GpuMat&, GpuMat&, int, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::demosaicing(const GpuMat&, GpuMat&, int, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::swapChannels(GpuMat&, const int[], Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::gammaCorrection(const GpuMat&, GpuMat&, bool, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::alphaComp(const GpuMat&, const GpuMat&, GpuMat&, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
#include "cvt_color_internal.h"
|
||||
@@ -1581,7 +1587,7 @@ namespace
|
||||
(void)src;
|
||||
(void)dst;
|
||||
(void)st;
|
||||
CV_Error( CV_StsBadFlag, "Unknown/unsupported color conversion code" );
|
||||
CV_Error( cv::Error::StsBadFlag, "Unknown/unsupported color conversion code" );
|
||||
#else
|
||||
CV_Assert(src.type() == CV_8UC4 || src.type() == CV_16UC4);
|
||||
|
||||
@@ -1676,6 +1682,9 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// cvtColor
|
||||
|
||||
void cv::gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream);
|
||||
@@ -1859,6 +1868,9 @@ void cv::gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, Stream
|
||||
func(src, dst, dcn, stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// demosaicing
|
||||
|
||||
void cv::gpu::demosaicing(const GpuMat& src, GpuMat& dst, int code, int dcn, Stream& stream)
|
||||
{
|
||||
const int depth = src.depth();
|
||||
@@ -1927,6 +1939,9 @@ void cv::gpu::demosaicing(const GpuMat& src, GpuMat& dst, int code, int dcn, Str
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// swapChannels
|
||||
|
||||
void cv::gpu::swapChannels(GpuMat& image, const int dstOrder[4], Stream& s)
|
||||
{
|
||||
CV_Assert(image.type() == CV_8UC4);
|
||||
@@ -1945,6 +1960,9 @@ void cv::gpu::swapChannels(GpuMat& image, const int dstOrder[4], Stream& s)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// gammaCorrection
|
||||
|
||||
void cv::gpu::gammaCorrection(const GpuMat& src, GpuMat& dst, bool forward, Stream& stream)
|
||||
{
|
||||
#if (CUDA_VERSION < 5000)
|
||||
@@ -1986,4 +2004,77 @@ void cv::gpu::gammaCorrection(const GpuMat& src, GpuMat& dst, bool forward, Stre
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// alphaComp
|
||||
|
||||
namespace
|
||||
{
|
||||
template <int DEPTH> struct NppAlphaCompFunc
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_t;
|
||||
|
||||
typedef NppStatus (*func_t)(const npp_t* pSrc1, int nSrc1Step, const npp_t* pSrc2, int nSrc2Step, npp_t* pDst, int nDstStep, NppiSize oSizeROI, NppiAlphaOp eAlphaOp);
|
||||
};
|
||||
|
||||
template <int DEPTH, typename NppAlphaCompFunc<DEPTH>::func_t func> struct NppAlphaComp
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_t;
|
||||
|
||||
static void call(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, NppiAlphaOp eAlphaOp, cudaStream_t stream)
|
||||
{
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize oSizeROI;
|
||||
oSizeROI.width = img1.cols;
|
||||
oSizeROI.height = img2.rows;
|
||||
|
||||
nppSafeCall( func(img1.ptr<npp_t>(), static_cast<int>(img1.step), img2.ptr<npp_t>(), static_cast<int>(img2.step),
|
||||
dst.ptr<npp_t>(), static_cast<int>(dst.step), oSizeROI, eAlphaOp) );
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void cv::gpu::alphaComp(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, int alpha_op, Stream& stream)
|
||||
{
|
||||
static const NppiAlphaOp npp_alpha_ops[] = {
|
||||
NPPI_OP_ALPHA_OVER,
|
||||
NPPI_OP_ALPHA_IN,
|
||||
NPPI_OP_ALPHA_OUT,
|
||||
NPPI_OP_ALPHA_ATOP,
|
||||
NPPI_OP_ALPHA_XOR,
|
||||
NPPI_OP_ALPHA_PLUS,
|
||||
NPPI_OP_ALPHA_OVER_PREMUL,
|
||||
NPPI_OP_ALPHA_IN_PREMUL,
|
||||
NPPI_OP_ALPHA_OUT_PREMUL,
|
||||
NPPI_OP_ALPHA_ATOP_PREMUL,
|
||||
NPPI_OP_ALPHA_XOR_PREMUL,
|
||||
NPPI_OP_ALPHA_PLUS_PREMUL,
|
||||
NPPI_OP_ALPHA_PREMUL
|
||||
};
|
||||
|
||||
typedef void (*func_t)(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, NppiAlphaOp eAlphaOp, cudaStream_t stream);
|
||||
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
NppAlphaComp<CV_8U, nppiAlphaComp_8u_AC4R>::call,
|
||||
0,
|
||||
NppAlphaComp<CV_16U, nppiAlphaComp_16u_AC4R>::call,
|
||||
0,
|
||||
NppAlphaComp<CV_32S, nppiAlphaComp_32s_AC4R>::call,
|
||||
NppAlphaComp<CV_32F, nppiAlphaComp_32f_AC4R>::call
|
||||
};
|
||||
|
||||
CV_Assert( img1.type() == CV_8UC4 || img1.type() == CV_16UC4 || img1.type() == CV_32SC4 || img1.type() == CV_32FC4 );
|
||||
CV_Assert( img1.size() == img2.size() && img1.type() == img2.type() );
|
||||
|
||||
dst.create(img1.size(), img1.type());
|
||||
|
||||
const func_t func = funcs[img1.depth()];
|
||||
|
||||
func(img1, img2, dst, npp_alpha_ops[alpha_op], StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
/*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::gpu;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::cornerHarris(const GpuMat&, GpuMat&, int, int, double, int) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerHarris(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, int, int, double, int) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerHarris(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, int, int, double, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat&, GpuMat&, int, int, int) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, int, int, int) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, int, int, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace imgproc
|
||||
{
|
||||
void cornerHarris_gpu(int block_size, float k, PtrStepSzf Dx, PtrStepSzf Dy, PtrStepSzf dst, int border_type, cudaStream_t stream);
|
||||
void cornerMinEigenVal_gpu(int block_size, PtrStepSzf Dx, PtrStepSzf Dy, PtrStepSzf dst, int border_type, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
|
||||
namespace
|
||||
{
|
||||
void extractCovData(const GpuMat& src, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, int borderType, Stream& stream)
|
||||
{
|
||||
double scale = static_cast<double>(1 << ((ksize > 0 ? ksize : 3) - 1)) * blockSize;
|
||||
|
||||
if (ksize < 0)
|
||||
scale *= 2.;
|
||||
|
||||
if (src.depth() == CV_8U)
|
||||
scale *= 255.;
|
||||
|
||||
scale = 1./scale;
|
||||
|
||||
Dx.create(src.size(), CV_32F);
|
||||
Dy.create(src.size(), CV_32F);
|
||||
|
||||
if (ksize > 0)
|
||||
{
|
||||
Sobel(src, Dx, CV_32F, 1, 0, buf, ksize, scale, borderType, -1, stream);
|
||||
Sobel(src, Dy, CV_32F, 0, 1, buf, ksize, scale, borderType, -1, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
Scharr(src, Dx, CV_32F, 1, 0, buf, scale, borderType, -1, stream);
|
||||
Scharr(src, Dy, CV_32F, 0, 1, buf, scale, borderType, -1, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gpu::cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType)
|
||||
{
|
||||
GpuMat Dx, Dy;
|
||||
cornerHarris(src, dst, Dx, Dy, blockSize, ksize, k, borderType);
|
||||
}
|
||||
|
||||
void cv::gpu::cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, double k, int borderType)
|
||||
{
|
||||
GpuMat buf;
|
||||
cornerHarris(src, dst, Dx, Dy, buf, blockSize, ksize, k, borderType);
|
||||
}
|
||||
|
||||
void cv::gpu::cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, double k, int borderType, Stream& stream)
|
||||
{
|
||||
using namespace cv::gpu::cudev::imgproc;
|
||||
|
||||
CV_Assert(borderType == cv::BORDER_REFLECT101 || borderType == cv::BORDER_REPLICATE || borderType == cv::BORDER_REFLECT);
|
||||
|
||||
extractCovData(src, Dx, Dy, buf, blockSize, ksize, borderType, stream);
|
||||
|
||||
dst.create(src.size(), CV_32F);
|
||||
|
||||
cornerHarris_gpu(blockSize, static_cast<float>(k), Dx, Dy, dst, borderType, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType)
|
||||
{
|
||||
GpuMat Dx, Dy;
|
||||
cornerMinEigenVal(src, dst, Dx, Dy, blockSize, ksize, borderType);
|
||||
}
|
||||
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, int borderType)
|
||||
{
|
||||
GpuMat buf;
|
||||
cornerMinEigenVal(src, dst, Dx, Dy, buf, blockSize, ksize, borderType);
|
||||
}
|
||||
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, int borderType, Stream& stream)
|
||||
{
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
|
||||
CV_Assert(borderType == cv::BORDER_REFLECT101 || borderType == cv::BORDER_REPLICATE || borderType == cv::BORDER_REFLECT);
|
||||
|
||||
extractCovData(src, Dx, Dy, buf, blockSize, ksize, borderType, stream);
|
||||
|
||||
dst.create(src.size(), CV_32F);
|
||||
|
||||
cornerMinEigenVal_gpu(blockSize, Dx, Dy, dst, borderType, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
@@ -52,137 +52,6 @@ namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace imgproc
|
||||
{
|
||||
/////////////////////////////////// MeanShiftfiltering ///////////////////////////////////////////////
|
||||
|
||||
texture<uchar4, 2> tex_meanshift;
|
||||
|
||||
__device__ short2 do_mean_shift(int x0, int y0, unsigned char* out,
|
||||
size_t out_step, int cols, int rows,
|
||||
int sp, int sr, int maxIter, float eps)
|
||||
{
|
||||
int isr2 = sr*sr;
|
||||
uchar4 c = tex2D(tex_meanshift, x0, y0 );
|
||||
|
||||
// iterate meanshift procedure
|
||||
for( int iter = 0; iter < maxIter; iter++ )
|
||||
{
|
||||
int count = 0;
|
||||
int s0 = 0, s1 = 0, s2 = 0, sx = 0, sy = 0;
|
||||
float icount;
|
||||
|
||||
//mean shift: process pixels in window (p-sigmaSp)x(p+sigmaSp)
|
||||
int minx = x0-sp;
|
||||
int miny = y0-sp;
|
||||
int maxx = x0+sp;
|
||||
int maxy = y0+sp;
|
||||
|
||||
for( int y = miny; y <= maxy; y++)
|
||||
{
|
||||
int rowCount = 0;
|
||||
for( int x = minx; x <= maxx; x++ )
|
||||
{
|
||||
uchar4 t = tex2D( tex_meanshift, x, y );
|
||||
|
||||
int norm2 = (t.x - c.x) * (t.x - c.x) + (t.y - c.y) * (t.y - c.y) + (t.z - c.z) * (t.z - c.z);
|
||||
if( norm2 <= isr2 )
|
||||
{
|
||||
s0 += t.x; s1 += t.y; s2 += t.z;
|
||||
sx += x; rowCount++;
|
||||
}
|
||||
}
|
||||
count += rowCount;
|
||||
sy += y*rowCount;
|
||||
}
|
||||
|
||||
if( count == 0 )
|
||||
break;
|
||||
|
||||
icount = 1.f/count;
|
||||
int x1 = __float2int_rz(sx*icount);
|
||||
int y1 = __float2int_rz(sy*icount);
|
||||
s0 = __float2int_rz(s0*icount);
|
||||
s1 = __float2int_rz(s1*icount);
|
||||
s2 = __float2int_rz(s2*icount);
|
||||
|
||||
int norm2 = (s0 - c.x) * (s0 - c.x) + (s1 - c.y) * (s1 - c.y) + (s2 - c.z) * (s2 - c.z);
|
||||
|
||||
bool stopFlag = (x0 == x1 && y0 == y1) || (::abs(x1-x0) + ::abs(y1-y0) + norm2 <= eps);
|
||||
|
||||
x0 = x1; y0 = y1;
|
||||
c.x = s0; c.y = s1; c.z = s2;
|
||||
|
||||
if( stopFlag )
|
||||
break;
|
||||
}
|
||||
|
||||
int base = (blockIdx.y * blockDim.y + threadIdx.y) * out_step + (blockIdx.x * blockDim.x + threadIdx.x) * 4 * sizeof(uchar);
|
||||
*(uchar4*)(out + base) = c;
|
||||
|
||||
return make_short2((short)x0, (short)y0);
|
||||
}
|
||||
|
||||
__global__ void meanshift_kernel(unsigned char* out, size_t out_step, int cols, int rows, int sp, int sr, int maxIter, float eps )
|
||||
{
|
||||
int x0 = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y0 = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if( x0 < cols && y0 < rows )
|
||||
do_mean_shift(x0, y0, out, out_step, cols, rows, sp, sr, maxIter, eps);
|
||||
}
|
||||
|
||||
__global__ void meanshiftproc_kernel(unsigned char* outr, size_t outrstep,
|
||||
unsigned char* outsp, size_t outspstep,
|
||||
int cols, int rows,
|
||||
int sp, int sr, int maxIter, float eps)
|
||||
{
|
||||
int x0 = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y0 = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if( x0 < cols && y0 < rows )
|
||||
{
|
||||
int basesp = (blockIdx.y * blockDim.y + threadIdx.y) * outspstep + (blockIdx.x * blockDim.x + threadIdx.x) * 2 * sizeof(short);
|
||||
*(short2*)(outsp + basesp) = do_mean_shift(x0, y0, outr, outrstep, cols, rows, sp, sr, maxIter, eps);
|
||||
}
|
||||
}
|
||||
|
||||
void meanShiftFiltering_gpu(const PtrStepSzb& src, PtrStepSzb dst, int sp, int sr, int maxIter, float eps, cudaStream_t stream)
|
||||
{
|
||||
dim3 grid(1, 1, 1);
|
||||
dim3 threads(32, 8, 1);
|
||||
grid.x = divUp(src.cols, threads.x);
|
||||
grid.y = divUp(src.rows, threads.y);
|
||||
|
||||
cudaChannelFormatDesc desc = cudaCreateChannelDesc<uchar4>();
|
||||
cudaSafeCall( cudaBindTexture2D( 0, tex_meanshift, src.data, desc, src.cols, src.rows, src.step ) );
|
||||
|
||||
meanshift_kernel<<< grid, threads, 0, stream >>>( dst.data, dst.step, dst.cols, dst.rows, sp, sr, maxIter, eps );
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
|
||||
//cudaSafeCall( cudaUnbindTexture( tex_meanshift ) );
|
||||
}
|
||||
|
||||
void meanShiftProc_gpu(const PtrStepSzb& src, PtrStepSzb dstr, PtrStepSzb dstsp, int sp, int sr, int maxIter, float eps, cudaStream_t stream)
|
||||
{
|
||||
dim3 grid(1, 1, 1);
|
||||
dim3 threads(32, 8, 1);
|
||||
grid.x = divUp(src.cols, threads.x);
|
||||
grid.y = divUp(src.rows, threads.y);
|
||||
|
||||
cudaChannelFormatDesc desc = cudaCreateChannelDesc<uchar4>();
|
||||
cudaSafeCall( cudaBindTexture2D( 0, tex_meanshift, src.data, desc, src.cols, src.rows, src.step ) );
|
||||
|
||||
meanshiftproc_kernel<<< grid, threads, 0, stream >>>( dstr.data, dstr.step, dstsp.data, dstsp.step, dstr.cols, dstr.rows, sp, sr, maxIter, eps );
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
|
||||
//cudaSafeCall( cudaUnbindTexture( tex_meanshift ) );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////// Corner Harris /////////////////////////////////////////////////
|
||||
|
||||
texture<float, cudaTextureType2D, cudaReadModeElementType> harrisDxTex(0, cudaFilterModePoint, cudaAddressModeClamp);
|
||||
@@ -399,8 +268,7 @@ namespace cv { namespace gpu { namespace cudev
|
||||
if (stream == 0)
|
||||
cudaSafeCall(cudaDeviceSynchronize());
|
||||
}
|
||||
} // namespace imgproc
|
||||
}}} // namespace cv { namespace gpu { namespace cudev {
|
||||
}
|
||||
}}}
|
||||
|
||||
|
||||
#endif /* CUDA_DISABLER */
|
||||
#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*/
|
||||
|
||||
#if !defined CUDA_DISABLER
|
||||
|
||||
#include "opencv2/core/cuda/common.hpp"
|
||||
#include "opencv2/core/cuda/vec_traits.hpp"
|
||||
#include "opencv2/core/cuda/vec_math.hpp"
|
||||
#include "opencv2/core/cuda/saturate_cast.hpp"
|
||||
#include "opencv2/core/cuda/border_interpolate.hpp"
|
||||
|
||||
namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace imgproc
|
||||
{
|
||||
texture<uchar4, 2> tex_meanshift;
|
||||
|
||||
__device__ short2 do_mean_shift(int x0, int y0, unsigned char* out,
|
||||
size_t out_step, int cols, int rows,
|
||||
int sp, int sr, int maxIter, float eps)
|
||||
{
|
||||
int isr2 = sr*sr;
|
||||
uchar4 c = tex2D(tex_meanshift, x0, y0 );
|
||||
|
||||
// iterate meanshift procedure
|
||||
for( int iter = 0; iter < maxIter; iter++ )
|
||||
{
|
||||
int count = 0;
|
||||
int s0 = 0, s1 = 0, s2 = 0, sx = 0, sy = 0;
|
||||
float icount;
|
||||
|
||||
//mean shift: process pixels in window (p-sigmaSp)x(p+sigmaSp)
|
||||
int minx = x0-sp;
|
||||
int miny = y0-sp;
|
||||
int maxx = x0+sp;
|
||||
int maxy = y0+sp;
|
||||
|
||||
for( int y = miny; y <= maxy; y++)
|
||||
{
|
||||
int rowCount = 0;
|
||||
for( int x = minx; x <= maxx; x++ )
|
||||
{
|
||||
uchar4 t = tex2D( tex_meanshift, x, y );
|
||||
|
||||
int norm2 = (t.x - c.x) * (t.x - c.x) + (t.y - c.y) * (t.y - c.y) + (t.z - c.z) * (t.z - c.z);
|
||||
if( norm2 <= isr2 )
|
||||
{
|
||||
s0 += t.x; s1 += t.y; s2 += t.z;
|
||||
sx += x; rowCount++;
|
||||
}
|
||||
}
|
||||
count += rowCount;
|
||||
sy += y*rowCount;
|
||||
}
|
||||
|
||||
if( count == 0 )
|
||||
break;
|
||||
|
||||
icount = 1.f/count;
|
||||
int x1 = __float2int_rz(sx*icount);
|
||||
int y1 = __float2int_rz(sy*icount);
|
||||
s0 = __float2int_rz(s0*icount);
|
||||
s1 = __float2int_rz(s1*icount);
|
||||
s2 = __float2int_rz(s2*icount);
|
||||
|
||||
int norm2 = (s0 - c.x) * (s0 - c.x) + (s1 - c.y) * (s1 - c.y) + (s2 - c.z) * (s2 - c.z);
|
||||
|
||||
bool stopFlag = (x0 == x1 && y0 == y1) || (::abs(x1-x0) + ::abs(y1-y0) + norm2 <= eps);
|
||||
|
||||
x0 = x1; y0 = y1;
|
||||
c.x = s0; c.y = s1; c.z = s2;
|
||||
|
||||
if( stopFlag )
|
||||
break;
|
||||
}
|
||||
|
||||
int base = (blockIdx.y * blockDim.y + threadIdx.y) * out_step + (blockIdx.x * blockDim.x + threadIdx.x) * 4 * sizeof(uchar);
|
||||
*(uchar4*)(out + base) = c;
|
||||
|
||||
return make_short2((short)x0, (short)y0);
|
||||
}
|
||||
|
||||
__global__ void meanshift_kernel(unsigned char* out, size_t out_step, int cols, int rows, int sp, int sr, int maxIter, float eps )
|
||||
{
|
||||
int x0 = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y0 = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if( x0 < cols && y0 < rows )
|
||||
do_mean_shift(x0, y0, out, out_step, cols, rows, sp, sr, maxIter, eps);
|
||||
}
|
||||
|
||||
void meanShiftFiltering_gpu(const PtrStepSzb& src, PtrStepSzb dst, int sp, int sr, int maxIter, float eps, cudaStream_t stream)
|
||||
{
|
||||
dim3 grid(1, 1, 1);
|
||||
dim3 threads(32, 8, 1);
|
||||
grid.x = divUp(src.cols, threads.x);
|
||||
grid.y = divUp(src.rows, threads.y);
|
||||
|
||||
cudaChannelFormatDesc desc = cudaCreateChannelDesc<uchar4>();
|
||||
cudaSafeCall( cudaBindTexture2D( 0, tex_meanshift, src.data, desc, src.cols, src.rows, src.step ) );
|
||||
|
||||
meanshift_kernel<<< grid, threads, 0, stream >>>( dst.data, dst.step, dst.cols, dst.rows, sp, sr, maxIter, eps );
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
__global__ void meanshiftproc_kernel(unsigned char* outr, size_t outrstep,
|
||||
unsigned char* outsp, size_t outspstep,
|
||||
int cols, int rows,
|
||||
int sp, int sr, int maxIter, float eps)
|
||||
{
|
||||
int x0 = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y0 = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if( x0 < cols && y0 < rows )
|
||||
{
|
||||
int basesp = (blockIdx.y * blockDim.y + threadIdx.y) * outspstep + (blockIdx.x * blockDim.x + threadIdx.x) * 2 * sizeof(short);
|
||||
*(short2*)(outsp + basesp) = do_mean_shift(x0, y0, outr, outrstep, cols, rows, sp, sr, maxIter, eps);
|
||||
}
|
||||
}
|
||||
|
||||
void meanShiftProc_gpu(const PtrStepSzb& src, PtrStepSzb dstr, PtrStepSzb dstsp, int sp, int sr, int maxIter, float eps, cudaStream_t stream)
|
||||
{
|
||||
dim3 grid(1, 1, 1);
|
||||
dim3 threads(32, 8, 1);
|
||||
grid.x = divUp(src.cols, threads.x);
|
||||
grid.y = divUp(src.rows, threads.y);
|
||||
|
||||
cudaChannelFormatDesc desc = cudaCreateChannelDesc<uchar4>();
|
||||
cudaSafeCall( cudaBindTexture2D( 0, tex_meanshift, src.data, desc, src.cols, src.rows, src.step ) );
|
||||
|
||||
meanshiftproc_kernel<<< grid, threads, 0, stream >>>( dstr.data, dstr.step, dstsp.data, dstsp.step, dstr.cols, dstr.rows, sp, sr, maxIter, eps );
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
}
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -62,6 +62,12 @@ namespace cv { namespace gpu { namespace cudev
|
||||
|
||||
void cv::gpu::GoodFeaturesToTrackDetector_GPU::operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask)
|
||||
{
|
||||
#ifndef HAVE_OPENCV_GPUARITHM
|
||||
(void) image;
|
||||
(void) corners;
|
||||
(void) mask;
|
||||
throw_no_cuda();
|
||||
#else
|
||||
using namespace cv::gpu::cudev::gfft;
|
||||
|
||||
CV_Assert(qualityLevel > 0 && minDistance >= 0 && maxCorners >= 0);
|
||||
@@ -75,7 +81,7 @@ void cv::gpu::GoodFeaturesToTrackDetector_GPU::operator ()(const GpuMat& image,
|
||||
cornerMinEigenVal(image, eig_, Dx_, Dy_, buf_, blockSize, 3);
|
||||
|
||||
double maxVal = 0;
|
||||
minMax(eig_, 0, &maxVal, GpuMat(), minMaxbuf_);
|
||||
gpu::minMax(eig_, 0, &maxVal, GpuMat(), minMaxbuf_);
|
||||
|
||||
ensureSizeIsEnough(1, std::max(1000, static_cast<int>(image.size().area() * 0.05)), CV_32FC2, tmpCorners_);
|
||||
|
||||
@@ -164,6 +170,7 @@ void cv::gpu::GoodFeaturesToTrackDetector_GPU::operator ()(const GpuMat& image,
|
||||
|
||||
corners.upload(Mat(1, static_cast<int>(tmp2.size()), CV_32FC2, &tmp2[0]));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
||||
@@ -47,113 +47,29 @@ using namespace cv::gpu;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::meanShiftFiltering(const GpuMat&, GpuMat&, int, int, TermCriteria, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::meanShiftProc(const GpuMat&, GpuMat&, GpuMat&, int, int, TermCriteria, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::evenLevels(GpuMat&, int, int, int) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::histEven(const GpuMat&, GpuMat&, int, int, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::histEven(const GpuMat&, GpuMat&, GpuMat&, int, int, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::histEven(const GpuMat&, GpuMat*, int*, int*, int*, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::histEven(const GpuMat&, GpuMat*, GpuMat&, int*, int*, int*, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::histRange(const GpuMat&, GpuMat&, const GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::histRange(const GpuMat&, GpuMat&, const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::histRange(const GpuMat&, GpuMat*, const GpuMat*, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::histRange(const GpuMat&, GpuMat*, const GpuMat*, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::calcHist(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::equalizeHist(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::equalizeHist(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerHarris(const GpuMat&, GpuMat&, int, int, double, int) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerHarris(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, int, int, double, int) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerHarris(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, int, int, double, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat&, GpuMat&, int, int, int) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, int, int, int) { throw_no_cuda(); }
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, int, int, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::Canny(const GpuMat&, GpuMat&, double, double, int, bool) { throw_no_cuda(); }
|
||||
void cv::gpu::Canny(const GpuMat&, CannyBuf&, GpuMat&, double, double, int, bool) { throw_no_cuda(); }
|
||||
void cv::gpu::Canny(const GpuMat&, const GpuMat&, GpuMat&, double, double, bool) { throw_no_cuda(); }
|
||||
void cv::gpu::Canny(const GpuMat&, const GpuMat&, CannyBuf&, GpuMat&, double, double, bool) { throw_no_cuda(); }
|
||||
void cv::gpu::CannyBuf::create(const Size&, int) { throw_no_cuda(); }
|
||||
void cv::gpu::CannyBuf::release() { throw_no_cuda(); }
|
||||
|
||||
cv::Ptr<cv::gpu::CLAHE> cv::gpu::createCLAHE(double, cv::Size) { throw_no_cuda(); return cv::Ptr<cv::gpu::CLAHE>(); }
|
||||
void cv::gpu::alphaComp(const GpuMat&, const GpuMat&, GpuMat&, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// meanShiftFiltering_GPU
|
||||
|
||||
namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace imgproc
|
||||
{
|
||||
void meanShiftFiltering_gpu(const PtrStepSzb& src, PtrStepSzb dst, int sp, int sr, int maxIter, float eps, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr, TermCriteria criteria, Stream& stream)
|
||||
{
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
|
||||
if( src.empty() )
|
||||
CV_Error( cv::Error::StsBadArg, "The input image is empty" );
|
||||
|
||||
if( src.depth() != CV_8U || src.channels() != 4 )
|
||||
CV_Error( cv::Error::StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
|
||||
|
||||
dst.create( src.size(), CV_8UC4 );
|
||||
|
||||
if( !(criteria.type & TermCriteria::MAX_ITER) )
|
||||
criteria.maxCount = 5;
|
||||
|
||||
int maxIter = std::min(std::max(criteria.maxCount, 1), 100);
|
||||
|
||||
float eps;
|
||||
if( !(criteria.type & TermCriteria::EPS) )
|
||||
eps = 1.f;
|
||||
eps = (float)std::max(criteria.epsilon, 0.0);
|
||||
|
||||
meanShiftFiltering_gpu(src, dst, sp, sr, maxIter, eps, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// meanShiftProc_GPU
|
||||
|
||||
namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace imgproc
|
||||
{
|
||||
void meanShiftProc_gpu(const PtrStepSzb& src, PtrStepSzb dstr, PtrStepSzb dstsp, int sp, int sr, int maxIter, float eps, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr, TermCriteria criteria, Stream& stream)
|
||||
{
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
|
||||
if( src.empty() )
|
||||
CV_Error( cv::Error::StsBadArg, "The input image is empty" );
|
||||
|
||||
if( src.depth() != CV_8U || src.channels() != 4 )
|
||||
CV_Error( cv::Error::StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
|
||||
|
||||
dstr.create( src.size(), CV_8UC4 );
|
||||
dstsp.create( src.size(), CV_16SC2 );
|
||||
|
||||
if( !(criteria.type & TermCriteria::MAX_ITER) )
|
||||
criteria.maxCount = 5;
|
||||
|
||||
int maxIter = std::min(std::max(criteria.maxCount, 1), 100);
|
||||
|
||||
float eps;
|
||||
if( !(criteria.type & TermCriteria::EPS) )
|
||||
eps = 1.f;
|
||||
eps = (float)std::max(criteria.epsilon, 0.0);
|
||||
|
||||
meanShiftProc_gpu(src, dstr, dstsp, sp, sr, maxIter, eps, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Histogram
|
||||
// NPP Histogram
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -444,10 +360,12 @@ void cv::gpu::histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4
|
||||
hist_callers[src.depth()](src, hist, levels, buf, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// calcHist
|
||||
|
||||
namespace hist
|
||||
{
|
||||
void histogram256(PtrStepSzb src, int* hist, cudaStream_t stream);
|
||||
void equalizeHist(PtrStepSzb src, PtrStepSzb dst, const int* lut, cudaStream_t stream);
|
||||
}
|
||||
|
||||
void cv::gpu::calcHist(const GpuMat& src, GpuMat& hist, Stream& stream)
|
||||
@@ -460,6 +378,14 @@ void cv::gpu::calcHist(const GpuMat& src, GpuMat& hist, Stream& stream)
|
||||
hist::histogram256(src, hist.ptr<int>(), StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// equalizeHist
|
||||
|
||||
namespace hist
|
||||
{
|
||||
void equalizeHist(PtrStepSzb src, PtrStepSzb dst, const int* lut, cudaStream_t stream);
|
||||
}
|
||||
|
||||
void cv::gpu::equalizeHist(const GpuMat& src, GpuMat& dst, Stream& stream)
|
||||
{
|
||||
GpuMat hist;
|
||||
@@ -492,229 +418,6 @@ void cv::gpu::equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, GpuMat&
|
||||
hist::equalizeHist(src, dst, lut.ptr<int>(), stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// cornerHarris & minEgenVal
|
||||
|
||||
namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace imgproc
|
||||
{
|
||||
void cornerHarris_gpu(int block_size, float k, PtrStepSzf Dx, PtrStepSzf Dy, PtrStepSzf dst, int border_type, cudaStream_t stream);
|
||||
void cornerMinEigenVal_gpu(int block_size, PtrStepSzf Dx, PtrStepSzf Dy, PtrStepSzf dst, int border_type, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
|
||||
namespace
|
||||
{
|
||||
void extractCovData(const GpuMat& src, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, int borderType, Stream& stream)
|
||||
{
|
||||
double scale = static_cast<double>(1 << ((ksize > 0 ? ksize : 3) - 1)) * blockSize;
|
||||
|
||||
if (ksize < 0)
|
||||
scale *= 2.;
|
||||
|
||||
if (src.depth() == CV_8U)
|
||||
scale *= 255.;
|
||||
|
||||
scale = 1./scale;
|
||||
|
||||
Dx.create(src.size(), CV_32F);
|
||||
Dy.create(src.size(), CV_32F);
|
||||
|
||||
if (ksize > 0)
|
||||
{
|
||||
Sobel(src, Dx, CV_32F, 1, 0, buf, ksize, scale, borderType, -1, stream);
|
||||
Sobel(src, Dy, CV_32F, 0, 1, buf, ksize, scale, borderType, -1, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
Scharr(src, Dx, CV_32F, 1, 0, buf, scale, borderType, -1, stream);
|
||||
Scharr(src, Dy, CV_32F, 0, 1, buf, scale, borderType, -1, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gpu::cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType)
|
||||
{
|
||||
GpuMat Dx, Dy;
|
||||
cornerHarris(src, dst, Dx, Dy, blockSize, ksize, k, borderType);
|
||||
}
|
||||
|
||||
void cv::gpu::cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, double k, int borderType)
|
||||
{
|
||||
GpuMat buf;
|
||||
cornerHarris(src, dst, Dx, Dy, buf, blockSize, ksize, k, borderType);
|
||||
}
|
||||
|
||||
void cv::gpu::cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, double k, int borderType, Stream& stream)
|
||||
{
|
||||
using namespace cv::gpu::cudev::imgproc;
|
||||
|
||||
CV_Assert(borderType == cv::BORDER_REFLECT101 || borderType == cv::BORDER_REPLICATE || borderType == cv::BORDER_REFLECT);
|
||||
|
||||
extractCovData(src, Dx, Dy, buf, blockSize, ksize, borderType, stream);
|
||||
|
||||
dst.create(src.size(), CV_32F);
|
||||
|
||||
cornerHarris_gpu(blockSize, static_cast<float>(k), Dx, Dy, dst, borderType, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType)
|
||||
{
|
||||
GpuMat Dx, Dy;
|
||||
cornerMinEigenVal(src, dst, Dx, Dy, blockSize, ksize, borderType);
|
||||
}
|
||||
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, int borderType)
|
||||
{
|
||||
GpuMat buf;
|
||||
cornerMinEigenVal(src, dst, Dx, Dy, buf, blockSize, ksize, borderType);
|
||||
}
|
||||
|
||||
void cv::gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, int borderType, Stream& stream)
|
||||
{
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
|
||||
CV_Assert(borderType == cv::BORDER_REFLECT101 || borderType == cv::BORDER_REPLICATE || borderType == cv::BORDER_REFLECT);
|
||||
|
||||
extractCovData(src, Dx, Dy, buf, blockSize, ksize, borderType, stream);
|
||||
|
||||
dst.create(src.size(), CV_32F);
|
||||
|
||||
cornerMinEigenVal_gpu(blockSize, Dx, Dy, dst, borderType, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Canny
|
||||
|
||||
void cv::gpu::CannyBuf::create(const Size& image_size, int apperture_size)
|
||||
{
|
||||
if (apperture_size > 0)
|
||||
{
|
||||
ensureSizeIsEnough(image_size, CV_32SC1, dx);
|
||||
ensureSizeIsEnough(image_size, CV_32SC1, dy);
|
||||
|
||||
if (apperture_size != 3)
|
||||
{
|
||||
filterDX = createDerivFilter_GPU(CV_8UC1, CV_32S, 1, 0, apperture_size, BORDER_REPLICATE);
|
||||
filterDY = createDerivFilter_GPU(CV_8UC1, CV_32S, 0, 1, apperture_size, BORDER_REPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
ensureSizeIsEnough(image_size, CV_32FC1, mag);
|
||||
ensureSizeIsEnough(image_size, CV_32SC1, map);
|
||||
|
||||
ensureSizeIsEnough(1, image_size.area(), CV_16UC2, st1);
|
||||
ensureSizeIsEnough(1, image_size.area(), CV_16UC2, st2);
|
||||
}
|
||||
|
||||
void cv::gpu::CannyBuf::release()
|
||||
{
|
||||
dx.release();
|
||||
dy.release();
|
||||
mag.release();
|
||||
map.release();
|
||||
st1.release();
|
||||
st2.release();
|
||||
}
|
||||
|
||||
namespace canny
|
||||
{
|
||||
void calcMagnitude(PtrStepSzb srcWhole, int xoff, int yoff, PtrStepSzi dx, PtrStepSzi dy, PtrStepSzf mag, bool L2Grad);
|
||||
void calcMagnitude(PtrStepSzi dx, PtrStepSzi dy, PtrStepSzf mag, bool L2Grad);
|
||||
|
||||
void calcMap(PtrStepSzi dx, PtrStepSzi dy, PtrStepSzf mag, PtrStepSzi map, float low_thresh, float high_thresh);
|
||||
|
||||
void edgesHysteresisLocal(PtrStepSzi map, ushort2* st1);
|
||||
|
||||
void edgesHysteresisGlobal(PtrStepSzi map, ushort2* st1, ushort2* st2);
|
||||
|
||||
void getEdges(PtrStepSzi map, PtrStepSzb dst);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void CannyCaller(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& dst, float low_thresh, float high_thresh)
|
||||
{
|
||||
using namespace canny;
|
||||
|
||||
buf.map.setTo(Scalar::all(0));
|
||||
calcMap(dx, dy, buf.mag, buf.map, low_thresh, high_thresh);
|
||||
|
||||
edgesHysteresisLocal(buf.map, buf.st1.ptr<ushort2>());
|
||||
|
||||
edgesHysteresisGlobal(buf.map, buf.st1.ptr<ushort2>(), buf.st2.ptr<ushort2>());
|
||||
|
||||
getEdges(buf.map, dst);
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gpu::Canny(const GpuMat& src, GpuMat& dst, double low_thresh, double high_thresh, int apperture_size, bool L2gradient)
|
||||
{
|
||||
CannyBuf buf;
|
||||
Canny(src, buf, dst, low_thresh, high_thresh, apperture_size, L2gradient);
|
||||
}
|
||||
|
||||
void cv::gpu::Canny(const GpuMat& src, CannyBuf& buf, GpuMat& dst, double low_thresh, double high_thresh, int apperture_size, bool L2gradient)
|
||||
{
|
||||
using namespace canny;
|
||||
|
||||
CV_Assert(src.type() == CV_8UC1);
|
||||
|
||||
if (!deviceSupports(SHARED_ATOMICS))
|
||||
CV_Error(cv::Error::StsNotImplemented, "The device doesn't support shared atomics");
|
||||
|
||||
if( low_thresh > high_thresh )
|
||||
std::swap( low_thresh, high_thresh);
|
||||
|
||||
dst.create(src.size(), CV_8U);
|
||||
buf.create(src.size(), apperture_size);
|
||||
|
||||
if (apperture_size == 3)
|
||||
{
|
||||
Size wholeSize;
|
||||
Point ofs;
|
||||
src.locateROI(wholeSize, ofs);
|
||||
GpuMat srcWhole(wholeSize, src.type(), src.datastart, src.step);
|
||||
|
||||
calcMagnitude(srcWhole, ofs.x, ofs.y, buf.dx, buf.dy, buf.mag, L2gradient);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.filterDX->apply(src, buf.dx, Rect(0, 0, src.cols, src.rows));
|
||||
buf.filterDY->apply(src, buf.dy, Rect(0, 0, src.cols, src.rows));
|
||||
|
||||
calcMagnitude(buf.dx, buf.dy, buf.mag, L2gradient);
|
||||
}
|
||||
|
||||
CannyCaller(buf.dx, buf.dy, buf, dst, static_cast<float>(low_thresh), static_cast<float>(high_thresh));
|
||||
}
|
||||
|
||||
void cv::gpu::Canny(const GpuMat& dx, const GpuMat& dy, GpuMat& dst, double low_thresh, double high_thresh, bool L2gradient)
|
||||
{
|
||||
CannyBuf buf;
|
||||
Canny(dx, dy, buf, dst, low_thresh, high_thresh, L2gradient);
|
||||
}
|
||||
|
||||
void cv::gpu::Canny(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& dst, double low_thresh, double high_thresh, bool L2gradient)
|
||||
{
|
||||
using namespace canny;
|
||||
|
||||
CV_Assert(TargetArchs::builtWith(SHARED_ATOMICS) && DeviceInfo().supports(SHARED_ATOMICS));
|
||||
CV_Assert(dx.type() == CV_32SC1 && dy.type() == CV_32SC1 && dx.size() == dy.size());
|
||||
|
||||
if( low_thresh > high_thresh )
|
||||
std::swap( low_thresh, high_thresh);
|
||||
|
||||
dst.create(dx.size(), CV_8U);
|
||||
buf.create(dx.size(), -1);
|
||||
|
||||
calcMagnitude(dx, dy, buf.mag, L2gradient);
|
||||
|
||||
CannyCaller(dx, dy, buf, dst, static_cast<float>(low_thresh), static_cast<float>(high_thresh));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// CLAHE
|
||||
|
||||
@@ -793,7 +496,11 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef HAVE_OPENCV_GPUARITHM
|
||||
throw_no_cuda();
|
||||
#else
|
||||
cv::gpu::copyMakeBorder(src, srcExt_, 0, tilesY_ - (src.rows % tilesY_), 0, tilesX_ - (src.cols % tilesX_), cv::BORDER_REFLECT_101, cv::Scalar(), s);
|
||||
#endif
|
||||
|
||||
tileSize = cv::Size(srcExt_.cols / tilesX_, srcExt_.rows / tilesY_);
|
||||
srcForLut = srcExt_;
|
||||
@@ -847,77 +554,4 @@ cv::Ptr<cv::gpu::CLAHE> cv::gpu::createCLAHE(double clipLimit, cv::Size tileGrid
|
||||
return new CLAHE_Impl(clipLimit, tileGridSize.width, tileGridSize.height);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// alphaComp
|
||||
|
||||
namespace
|
||||
{
|
||||
template <int DEPTH> struct NppAlphaCompFunc
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_t;
|
||||
|
||||
typedef NppStatus (*func_t)(const npp_t* pSrc1, int nSrc1Step, const npp_t* pSrc2, int nSrc2Step, npp_t* pDst, int nDstStep, NppiSize oSizeROI, NppiAlphaOp eAlphaOp);
|
||||
};
|
||||
|
||||
template <int DEPTH, typename NppAlphaCompFunc<DEPTH>::func_t func> struct NppAlphaComp
|
||||
{
|
||||
typedef typename NPPTypeTraits<DEPTH>::npp_type npp_t;
|
||||
|
||||
static void call(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, NppiAlphaOp eAlphaOp, cudaStream_t stream)
|
||||
{
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize oSizeROI;
|
||||
oSizeROI.width = img1.cols;
|
||||
oSizeROI.height = img2.rows;
|
||||
|
||||
nppSafeCall( func(img1.ptr<npp_t>(), static_cast<int>(img1.step), img2.ptr<npp_t>(), static_cast<int>(img2.step),
|
||||
dst.ptr<npp_t>(), static_cast<int>(dst.step), oSizeROI, eAlphaOp) );
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void cv::gpu::alphaComp(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, int alpha_op, Stream& stream)
|
||||
{
|
||||
static const NppiAlphaOp npp_alpha_ops[] = {
|
||||
NPPI_OP_ALPHA_OVER,
|
||||
NPPI_OP_ALPHA_IN,
|
||||
NPPI_OP_ALPHA_OUT,
|
||||
NPPI_OP_ALPHA_ATOP,
|
||||
NPPI_OP_ALPHA_XOR,
|
||||
NPPI_OP_ALPHA_PLUS,
|
||||
NPPI_OP_ALPHA_OVER_PREMUL,
|
||||
NPPI_OP_ALPHA_IN_PREMUL,
|
||||
NPPI_OP_ALPHA_OUT_PREMUL,
|
||||
NPPI_OP_ALPHA_ATOP_PREMUL,
|
||||
NPPI_OP_ALPHA_XOR_PREMUL,
|
||||
NPPI_OP_ALPHA_PLUS_PREMUL,
|
||||
NPPI_OP_ALPHA_PREMUL
|
||||
};
|
||||
|
||||
typedef void (*func_t)(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, NppiAlphaOp eAlphaOp, cudaStream_t stream);
|
||||
|
||||
static const func_t funcs[] =
|
||||
{
|
||||
NppAlphaComp<CV_8U, nppiAlphaComp_8u_AC4R>::call,
|
||||
0,
|
||||
NppAlphaComp<CV_16U, nppiAlphaComp_16u_AC4R>::call,
|
||||
0,
|
||||
NppAlphaComp<CV_32S, nppiAlphaComp_32s_AC4R>::call,
|
||||
NppAlphaComp<CV_32F, nppiAlphaComp_32f_AC4R>::call
|
||||
};
|
||||
|
||||
CV_Assert( img1.type() == CV_8UC4 || img1.type() == CV_16UC4 || img1.type() == CV_32SC4 || img1.type() == CV_32FC4 );
|
||||
CV_Assert( img1.size() == img2.size() && img1.type() == img2.type() );
|
||||
|
||||
dst.create(img1.size(), img1.type());
|
||||
|
||||
const func_t func = funcs[img1.depth()];
|
||||
|
||||
func(img1, img2, dst, npp_alpha_ops[alpha_op], StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
@@ -45,7 +45,7 @@
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
#if !defined (HAVE_CUDA) || !defined (HAVE_OPENCV_GPUARITHM) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::matchTemplate(const GpuMat&, const GpuMat&, GpuMat&, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
@@ -172,15 +172,15 @@ namespace
|
||||
return;
|
||||
}
|
||||
|
||||
ConvolveBuf convolve_buf;
|
||||
gpu::ConvolveBuf convolve_buf;
|
||||
convolve_buf.user_block_size = buf.user_block_size;
|
||||
|
||||
if (image.channels() == 1)
|
||||
convolve(image.reshape(1), templ.reshape(1), result, true, convolve_buf, stream);
|
||||
gpu::convolve(image.reshape(1), templ.reshape(1), result, true, convolve_buf, stream);
|
||||
else
|
||||
{
|
||||
GpuMat result_;
|
||||
convolve(image.reshape(1), templ.reshape(1), result_, true, convolve_buf, stream);
|
||||
gpu::convolve(image.reshape(1), templ.reshape(1), result_, true, convolve_buf, stream);
|
||||
extractFirstChannel_32F(result_, result, image.channels(), StreamAccessor::getStream(stream));
|
||||
}
|
||||
}
|
||||
@@ -216,9 +216,9 @@ namespace
|
||||
matchTemplate_CCORR_8U(image, templ, result, buf, stream);
|
||||
|
||||
buf.image_sqsums.resize(1);
|
||||
sqrIntegral(image.reshape(1), buf.image_sqsums[0], stream);
|
||||
gpu::sqrIntegral(image.reshape(1), buf.image_sqsums[0], stream);
|
||||
|
||||
unsigned long long templ_sqsum = (unsigned long long)sqrSum(templ.reshape(1))[0];
|
||||
unsigned long long templ_sqsum = (unsigned long long)gpu::sqrSum(templ.reshape(1))[0];
|
||||
normalize_8U(templ.cols, templ.rows, buf.image_sqsums[0], templ_sqsum, result, image.channels(), StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
@@ -243,9 +243,9 @@ namespace
|
||||
}
|
||||
|
||||
buf.image_sqsums.resize(1);
|
||||
sqrIntegral(image.reshape(1), buf.image_sqsums[0], stream);
|
||||
gpu::sqrIntegral(image.reshape(1), buf.image_sqsums[0], stream);
|
||||
|
||||
unsigned long long templ_sqsum = (unsigned long long)sqrSum(templ.reshape(1))[0];
|
||||
unsigned long long templ_sqsum = (unsigned long long)gpu::sqrSum(templ.reshape(1))[0];
|
||||
|
||||
matchTemplate_CCORR_8U(image, templ, result, buf, stream);
|
||||
matchTemplatePrepared_SQDIFF_8U(templ.cols, templ.rows, buf.image_sqsums[0], templ_sqsum, result, image.channels(), StreamAccessor::getStream(stream));
|
||||
@@ -256,9 +256,9 @@ namespace
|
||||
const GpuMat& image, const GpuMat& templ, GpuMat& result, MatchTemplateBuf &buf, Stream& stream)
|
||||
{
|
||||
buf.image_sqsums.resize(1);
|
||||
sqrIntegral(image.reshape(1), buf.image_sqsums[0], stream);
|
||||
gpu::sqrIntegral(image.reshape(1), buf.image_sqsums[0], stream);
|
||||
|
||||
unsigned long long templ_sqsum = (unsigned long long)sqrSum(templ.reshape(1))[0];
|
||||
unsigned long long templ_sqsum = (unsigned long long)gpu::sqrSum(templ.reshape(1))[0];
|
||||
|
||||
matchTemplate_CCORR_8U(image, templ, result, buf, stream);
|
||||
matchTemplatePrepared_SQDIFF_NORMED_8U(templ.cols, templ.rows, buf.image_sqsums[0], templ_sqsum, result, image.channels(), StreamAccessor::getStream(stream));
|
||||
@@ -273,19 +273,19 @@ namespace
|
||||
if (image.channels() == 1)
|
||||
{
|
||||
buf.image_sums.resize(1);
|
||||
integral(image, buf.image_sums[0], stream);
|
||||
gpu::integral(image, buf.image_sums[0], stream);
|
||||
|
||||
unsigned int templ_sum = (unsigned int)sum(templ)[0];
|
||||
matchTemplatePrepared_CCOFF_8U(templ.cols, templ.rows, buf.image_sums[0], templ_sum, result, StreamAccessor::getStream(stream));
|
||||
}
|
||||
else
|
||||
{
|
||||
split(image, buf.images);
|
||||
gpu::split(image, buf.images);
|
||||
buf.image_sums.resize(buf.images.size());
|
||||
for (int i = 0; i < image.channels(); ++i)
|
||||
integral(buf.images[i], buf.image_sums[i], stream);
|
||||
gpu::integral(buf.images[i], buf.image_sums[i], stream);
|
||||
|
||||
Scalar templ_sum = sum(templ);
|
||||
Scalar templ_sum = gpu::sum(templ);
|
||||
|
||||
switch (image.channels())
|
||||
{
|
||||
@@ -333,12 +333,12 @@ namespace
|
||||
if (image.channels() == 1)
|
||||
{
|
||||
buf.image_sums.resize(1);
|
||||
integral(image, buf.image_sums[0], stream);
|
||||
gpu::integral(image, buf.image_sums[0], stream);
|
||||
buf.image_sqsums.resize(1);
|
||||
sqrIntegral(image, buf.image_sqsums[0], stream);
|
||||
gpu::sqrIntegral(image, buf.image_sqsums[0], stream);
|
||||
|
||||
unsigned int templ_sum = (unsigned int)sum(templ)[0];
|
||||
unsigned long long templ_sqsum = (unsigned long long)sqrSum(templ)[0];
|
||||
unsigned int templ_sum = (unsigned int)gpu::sum(templ)[0];
|
||||
unsigned long long templ_sqsum = (unsigned long long)gpu::sqrSum(templ)[0];
|
||||
|
||||
matchTemplatePrepared_CCOFF_NORMED_8U(
|
||||
templ.cols, templ.rows, buf.image_sums[0], buf.image_sqsums[0],
|
||||
@@ -346,17 +346,17 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
split(image, buf.images);
|
||||
gpu::split(image, buf.images);
|
||||
buf.image_sums.resize(buf.images.size());
|
||||
buf.image_sqsums.resize(buf.images.size());
|
||||
for (int i = 0; i < image.channels(); ++i)
|
||||
{
|
||||
integral(buf.images[i], buf.image_sums[i], stream);
|
||||
sqrIntegral(buf.images[i], buf.image_sqsums[i], stream);
|
||||
gpu::integral(buf.images[i], buf.image_sums[i], stream);
|
||||
gpu::sqrIntegral(buf.images[i], buf.image_sqsums[i], stream);
|
||||
}
|
||||
|
||||
Scalar templ_sum = sum(templ);
|
||||
Scalar templ_sqsum = sqrSum(templ);
|
||||
Scalar templ_sum = gpu::sum(templ);
|
||||
Scalar templ_sqsum = gpu::sqrSum(templ);
|
||||
|
||||
switch (image.channels())
|
||||
{
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/*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::gpu;
|
||||
|
||||
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::meanShiftFiltering(const GpuMat&, GpuMat&, int, int, TermCriteria, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::meanShiftProc(const GpuMat&, GpuMat&, GpuMat&, int, int, TermCriteria, Stream&) { throw_no_cuda(); }
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// meanShiftFiltering_GPU
|
||||
|
||||
namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace imgproc
|
||||
{
|
||||
void meanShiftFiltering_gpu(const PtrStepSzb& src, PtrStepSzb dst, int sp, int sr, int maxIter, float eps, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr, TermCriteria criteria, Stream& stream)
|
||||
{
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
|
||||
if( src.empty() )
|
||||
CV_Error( cv::Error::StsBadArg, "The input image is empty" );
|
||||
|
||||
if( src.depth() != CV_8U || src.channels() != 4 )
|
||||
CV_Error( cv::Error::StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
|
||||
|
||||
dst.create( src.size(), CV_8UC4 );
|
||||
|
||||
if( !(criteria.type & TermCriteria::MAX_ITER) )
|
||||
criteria.maxCount = 5;
|
||||
|
||||
int maxIter = std::min(std::max(criteria.maxCount, 1), 100);
|
||||
|
||||
float eps;
|
||||
if( !(criteria.type & TermCriteria::EPS) )
|
||||
eps = 1.f;
|
||||
eps = (float)std::max(criteria.epsilon, 0.0);
|
||||
|
||||
meanShiftFiltering_gpu(src, dst, sp, sr, maxIter, eps, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// meanShiftProc_GPU
|
||||
|
||||
namespace cv { namespace gpu { namespace cudev
|
||||
{
|
||||
namespace imgproc
|
||||
{
|
||||
void meanShiftProc_gpu(const PtrStepSzb& src, PtrStepSzb dstr, PtrStepSzb dstsp, int sp, int sr, int maxIter, float eps, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr, TermCriteria criteria, Stream& stream)
|
||||
{
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
|
||||
if( src.empty() )
|
||||
CV_Error( cv::Error::StsBadArg, "The input image is empty" );
|
||||
|
||||
if( src.depth() != CV_8U || src.channels() != 4 )
|
||||
CV_Error( cv::Error::StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
|
||||
|
||||
dstr.create( src.size(), CV_8UC4 );
|
||||
dstsp.create( src.size(), CV_16SC2 );
|
||||
|
||||
if( !(criteria.type & TermCriteria::MAX_ITER) )
|
||||
criteria.maxCount = 5;
|
||||
|
||||
int maxIter = std::min(std::max(criteria.maxCount, 1), 100);
|
||||
|
||||
float eps;
|
||||
if( !(criteria.type & TermCriteria::EPS) )
|
||||
eps = 1.f;
|
||||
eps = (float)std::max(criteria.epsilon, 0.0);
|
||||
|
||||
meanShiftProc_gpu(src, dstr, dstsp, sp, sr, maxIter, eps, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
@@ -45,9 +45,14 @@
|
||||
|
||||
#include "opencv2/gpuimgproc.hpp"
|
||||
#include "opencv2/gpufilters.hpp"
|
||||
#include "opencv2/gpuarithm.hpp"
|
||||
|
||||
#include "opencv2/core/private.hpp"
|
||||
#include "opencv2/core/gpu_private.hpp"
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_GPUARITHM
|
||||
# include "opencv2/gpuarithm.hpp"
|
||||
#endif
|
||||
|
||||
#endif /* __OPENCV_PRECOMP_H__ */
|
||||
|
||||
Reference in New Issue
Block a user