|
|
|
@ -42,13 +42,15 @@ |
|
|
|
|
|
|
|
|
|
#include "precomp.hpp" |
|
|
|
|
|
|
|
|
|
using namespace cv; |
|
|
|
|
using namespace cv::gpu; |
|
|
|
|
|
|
|
|
|
#if !defined HAVE_CUDA || defined(CUDA_DISABLER) |
|
|
|
|
|
|
|
|
|
void cv::gpu::pyrDown(InputArray, OutputArray, Stream&) { throw_no_cuda(); } |
|
|
|
|
void cv::gpu::pyrUp(InputArray, OutputArray, Stream&) { throw_no_cuda(); } |
|
|
|
|
|
|
|
|
|
void cv::gpu::ImagePyramid::build(const GpuMat&, int, Stream&) { throw_no_cuda(); } |
|
|
|
|
void cv::gpu::ImagePyramid::getLayer(GpuMat&, Size, Stream&) const { throw_no_cuda(); } |
|
|
|
|
Ptr<ImagePyramid> cv::gpu::createImagePyramid(InputArray, int, Stream&) { throw_no_cuda(); return Ptr<ImagePyramid>(); } |
|
|
|
|
|
|
|
|
|
#else // HAVE_CUDA
|
|
|
|
|
|
|
|
|
@ -134,84 +136,108 @@ void cv::gpu::pyrUp(InputArray _src, OutputArray _dst, Stream& stream) |
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// ImagePyramid
|
|
|
|
|
|
|
|
|
|
void cv::gpu::ImagePyramid::build(const GpuMat& img, int numLayers, Stream& stream) |
|
|
|
|
{ |
|
|
|
|
#ifndef HAVE_OPENCV_GPULEGACY |
|
|
|
|
(void) img; |
|
|
|
|
(void) numLayers; |
|
|
|
|
(void) stream; |
|
|
|
|
throw_no_cuda(); |
|
|
|
|
#else |
|
|
|
|
CV_Assert(img.depth() <= CV_32F && img.channels() <= 4); |
|
|
|
|
#ifdef HAVE_OPENCV_GPULEGACY |
|
|
|
|
|
|
|
|
|
layer0_ = img; |
|
|
|
|
Size szLastLayer = img.size(); |
|
|
|
|
nLayers_ = 1; |
|
|
|
|
namespace |
|
|
|
|
{ |
|
|
|
|
class ImagePyramidImpl : public ImagePyramid |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
ImagePyramidImpl(InputArray img, int nLayers, Stream& stream); |
|
|
|
|
|
|
|
|
|
if (numLayers <= 0) |
|
|
|
|
numLayers = 255; //it will cut-off when any of the dimensions goes 1
|
|
|
|
|
void getLayer(OutputArray outImg, Size outRoi, Stream& stream = Stream::Null()) const; |
|
|
|
|
|
|
|
|
|
pyramid_.resize(numLayers); |
|
|
|
|
private: |
|
|
|
|
GpuMat layer0_; |
|
|
|
|
std::vector<GpuMat> pyramid_; |
|
|
|
|
int nLayers_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numLayers - 1; ++i) |
|
|
|
|
ImagePyramidImpl::ImagePyramidImpl(InputArray _img, int numLayers, Stream& stream) |
|
|
|
|
{ |
|
|
|
|
Size szCurLayer(szLastLayer.width / 2, szLastLayer.height / 2); |
|
|
|
|
GpuMat img = _img.getGpuMat(); |
|
|
|
|
|
|
|
|
|
if (szCurLayer.width == 0 || szCurLayer.height == 0) |
|
|
|
|
break; |
|
|
|
|
CV_Assert( img.depth() <= CV_32F && img.channels() <= 4 ); |
|
|
|
|
|
|
|
|
|
ensureSizeIsEnough(szCurLayer, img.type(), pyramid_[i]); |
|
|
|
|
nLayers_++; |
|
|
|
|
img.copyTo(layer0_, stream); |
|
|
|
|
|
|
|
|
|
const GpuMat& prevLayer = i == 0 ? layer0_ : pyramid_[i - 1]; |
|
|
|
|
Size szLastLayer = img.size(); |
|
|
|
|
nLayers_ = 1; |
|
|
|
|
|
|
|
|
|
cudev::pyramid::downsampleX2(prevLayer, pyramid_[i], img.depth(), img.channels(), StreamAccessor::getStream(stream)); |
|
|
|
|
if (numLayers <= 0) |
|
|
|
|
numLayers = 255; // it will cut-off when any of the dimensions goes 1
|
|
|
|
|
|
|
|
|
|
szLastLayer = szCurLayer; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
pyramid_.resize(numLayers); |
|
|
|
|
|
|
|
|
|
void cv::gpu::ImagePyramid::getLayer(GpuMat& outImg, Size outRoi, Stream& stream) const |
|
|
|
|
{ |
|
|
|
|
#ifndef HAVE_OPENCV_GPULEGACY |
|
|
|
|
(void) outImg; |
|
|
|
|
(void) outRoi; |
|
|
|
|
(void) stream; |
|
|
|
|
throw_no_cuda(); |
|
|
|
|
#else |
|
|
|
|
CV_Assert(outRoi.width <= layer0_.cols && outRoi.height <= layer0_.rows && outRoi.width > 0 && outRoi.height > 0); |
|
|
|
|
for (int i = 0; i < numLayers - 1; ++i) |
|
|
|
|
{ |
|
|
|
|
Size szCurLayer(szLastLayer.width / 2, szLastLayer.height / 2); |
|
|
|
|
|
|
|
|
|
ensureSizeIsEnough(outRoi, layer0_.type(), outImg); |
|
|
|
|
if (szCurLayer.width == 0 || szCurLayer.height == 0) |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
if (outRoi.width == layer0_.cols && outRoi.height == layer0_.rows) |
|
|
|
|
{ |
|
|
|
|
layer0_.copyTo(outImg, stream); |
|
|
|
|
} |
|
|
|
|
ensureSizeIsEnough(szCurLayer, img.type(), pyramid_[i]); |
|
|
|
|
nLayers_++; |
|
|
|
|
|
|
|
|
|
float lastScale = 1.0f; |
|
|
|
|
float curScale; |
|
|
|
|
GpuMat lastLayer = layer0_; |
|
|
|
|
GpuMat curLayer; |
|
|
|
|
const GpuMat& prevLayer = i == 0 ? layer0_ : pyramid_[i - 1]; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nLayers_ - 1; ++i) |
|
|
|
|
cudev::pyramid::downsampleX2(prevLayer, pyramid_[i], img.depth(), img.channels(), StreamAccessor::getStream(stream)); |
|
|
|
|
|
|
|
|
|
szLastLayer = szCurLayer; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ImagePyramidImpl::getLayer(OutputArray _outImg, Size outRoi, Stream& stream) const |
|
|
|
|
{ |
|
|
|
|
curScale = lastScale * 0.5f; |
|
|
|
|
curLayer = pyramid_[i]; |
|
|
|
|
CV_Assert( outRoi.width <= layer0_.cols && outRoi.height <= layer0_.rows && outRoi.width > 0 && outRoi.height > 0 ); |
|
|
|
|
|
|
|
|
|
ensureSizeIsEnough(outRoi, layer0_.type(), _outImg); |
|
|
|
|
GpuMat outImg = _outImg.getGpuMat(); |
|
|
|
|
|
|
|
|
|
if (outRoi.width == curLayer.cols && outRoi.height == curLayer.rows) |
|
|
|
|
if (outRoi.width == layer0_.cols && outRoi.height == layer0_.rows) |
|
|
|
|
{ |
|
|
|
|
curLayer.copyTo(outImg, stream); |
|
|
|
|
layer0_.copyTo(outImg, stream); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (outRoi.width >= curLayer.cols && outRoi.height >= curLayer.rows) |
|
|
|
|
break; |
|
|
|
|
float lastScale = 1.0f; |
|
|
|
|
float curScale; |
|
|
|
|
GpuMat lastLayer = layer0_; |
|
|
|
|
GpuMat curLayer; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nLayers_ - 1; ++i) |
|
|
|
|
{ |
|
|
|
|
curScale = lastScale * 0.5f; |
|
|
|
|
curLayer = pyramid_[i]; |
|
|
|
|
|
|
|
|
|
if (outRoi.width == curLayer.cols && outRoi.height == curLayer.rows) |
|
|
|
|
{ |
|
|
|
|
curLayer.copyTo(outImg, stream); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (outRoi.width >= curLayer.cols && outRoi.height >= curLayer.rows) |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
lastScale = curScale; |
|
|
|
|
lastLayer = curLayer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lastScale = curScale; |
|
|
|
|
lastLayer = curLayer; |
|
|
|
|
cudev::pyramid::interpolateFrom1(lastLayer, outImg, outImg.depth(), outImg.channels(), StreamAccessor::getStream(stream)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
cudev::pyramid::interpolateFrom1(lastLayer, outImg, outImg.depth(), outImg.channels(), StreamAccessor::getStream(stream)); |
|
|
|
|
Ptr<ImagePyramid> cv::gpu::createImagePyramid(InputArray img, int nLayers, Stream& stream) |
|
|
|
|
{ |
|
|
|
|
#ifndef HAVE_OPENCV_GPULEGACY |
|
|
|
|
(void) img; |
|
|
|
|
(void) numLayers; |
|
|
|
|
(void) stream; |
|
|
|
|
throw_no_cuda(); |
|
|
|
|
return Ptr<ImagePyramid>(); |
|
|
|
|
#else |
|
|
|
|
return new ImagePyramidImpl(img, nLayers, stream); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|