////////////////////////// Corners Detection ///////////////////////////
+class CV_EXPORTS CornernessCriteria : public Algorithm
+{
+public:
+ virtual void compute(InputArray src, OutputArray dst, Stream& stream = Stream::Null()) = 0;
+};
+
//! computes Harris cornerness criteria at each image pixel
-CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101);
-CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101);
-CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, double k,
- int borderType = BORDER_REFLECT101, Stream& stream = Stream::Null());
+CV_EXPORTS Ptr<CornernessCriteria> createHarrisCorner(int srcType, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101);
//! computes minimum eigen value of 2x2 derivative covariation matrix at each pixel - the cornerness criteria
-CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101);
-CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, int borderType=BORDER_REFLECT101);
-CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize,
- int borderType=BORDER_REFLECT101, Stream& stream = Stream::Null());
+CV_EXPORTS Ptr<CornernessCriteria> createMinEigenValCorner(int srcType, int blockSize, int ksize, int borderType = BORDER_REFLECT101);
+
+// obsolete
+
+__OPENCV_GPUIMGPROC_DEPR_BEFORE__ void cornerHarris(InputArray src, OutputArray dst,
+ int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101,
+ Stream& stream = Stream::Null()) __OPENCV_GPUIMGPROC_DEPR_AFTER__;
+
+inline void cornerHarris(InputArray src, OutputArray dst, int blockSize, int ksize, double k, int borderType, Stream& stream)
+{
+ gpu::createHarrisCorner(src.type(), blockSize, ksize, k, borderType)->compute(src, dst, stream);
+}
+
+__OPENCV_GPUIMGPROC_DEPR_BEFORE__ void cornerMinEigenVal(InputArray src, OutputArray dst,
+ int blockSize, int ksize, int borderType = BORDER_REFLECT101,
+ Stream& stream = Stream::Null()) __OPENCV_GPUIMGPROC_DEPR_AFTER__;
+
+inline void cornerMinEigenVal(InputArray src, OutputArray dst, int blockSize, int ksize, int borderType, Stream& stream)
+{
+ gpu::createMinEigenValCorner(src.type(), blockSize, ksize, borderType)->compute(src, dst, stream);
+}
////////////////////////// Feature Detection ///////////////////////////
#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(); }
+Ptr<gpu::CornernessCriteria> cv::gpu::createHarrisCorner(int, int, int, double, int) { throw_no_cuda(); return Ptr<gpu::CornernessCriteria>(); }
+Ptr<gpu::CornernessCriteria> cv::gpu::createMinEigenValCorner(int, int, int, int) { throw_no_cuda(); return Ptr<gpu::CornernessCriteria>(); }
#else /* !defined (HAVE_CUDA) */
namespace
{
- void extractCovData(const GpuMat& src, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, int borderType, Stream& stream)
+ class CornerBase : public CornernessCriteria
+ {
+ protected:
+ CornerBase(int srcType, int blockSize, int ksize, int borderType);
+
+ void extractCovData(const GpuMat& src, Stream& stream);
+
+ int srcType_;
+ int blockSize_;
+ int ksize_;
+ int borderType_;
+ GpuMat Dx_, Dy_;
+
+ private:
+ Ptr<gpu::Filter> filterDx_, filterDy_;
+ };
+
+ CornerBase::CornerBase(int srcType, int blockSize, int ksize, int borderType) :
+ srcType_(srcType), blockSize_(blockSize), ksize_(ksize), borderType_(borderType)
{
- (void) buf;
+ CV_Assert( borderType_ == BORDER_REFLECT101 || borderType_ == BORDER_REPLICATE || borderType_ == BORDER_REFLECT );
- double scale = static_cast<double>(1 << ((ksize > 0 ? ksize : 3) - 1)) * blockSize;
+ const int sdepth = CV_MAT_DEPTH(srcType_);
+ const int cn = CV_MAT_CN(srcType_);
- if (ksize < 0)
+ CV_Assert( cn == 1 );
+
+ double scale = static_cast<double>(1 << ((ksize_ > 0 ? ksize_ : 3) - 1)) * blockSize_;
+
+ if (ksize_ < 0)
scale *= 2.;
- if (src.depth() == CV_8U)
+ if (sdepth == CV_8U)
scale *= 255.;
scale = 1./scale;
- Dx.create(src.size(), CV_32F);
- Dy.create(src.size(), CV_32F);
-
- Ptr<gpu::Filter> filterDx, filterDy;
-
- if (ksize > 0)
+ if (ksize_ > 0)
{
- filterDx = gpu::createSobelFilter(src.type(), CV_32F, 1, 0, ksize, scale, borderType);
- filterDy = gpu::createSobelFilter(src.type(), CV_32F, 0, 1, ksize, scale, borderType);
+ filterDx_ = gpu::createSobelFilter(srcType, CV_32F, 1, 0, ksize_, scale, borderType_);
+ filterDy_ = gpu::createSobelFilter(srcType, CV_32F, 0, 1, ksize_, scale, borderType_);
}
else
{
- filterDx = gpu::createScharrFilter(src.type(), CV_32F, 1, 0, scale, borderType);
- filterDy = gpu::createScharrFilter(src.type(), CV_32F, 0, 1, scale, borderType);
+ filterDx_ = gpu::createScharrFilter(srcType, CV_32F, 1, 0, scale, borderType_);
+ filterDy_ = gpu::createScharrFilter(srcType, CV_32F, 0, 1, scale, borderType_);
}
+ }
- filterDx->apply(src, Dx);
- filterDy->apply(src, Dy);
+ void CornerBase::extractCovData(const GpuMat& src, Stream& stream)
+ {
+ CV_Assert( src.type() == srcType_ );
+ filterDx_->apply(src, Dx_, stream);
+ filterDy_->apply(src, Dy_, 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);
-}
+ class Harris : public CornerBase
+ {
+ public:
+ Harris(int srcType, int blockSize, int ksize, double k, int borderType) :
+ CornerBase(srcType, blockSize, ksize, borderType), k_(static_cast<float>(k))
+ {
+ }
-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 compute(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
-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;
+ private:
+ float k_;
+ };
- CV_Assert(borderType == cv::BORDER_REFLECT101 || borderType == cv::BORDER_REPLICATE || borderType == cv::BORDER_REFLECT);
+ void Harris::compute(InputArray _src, OutputArray _dst, Stream& stream)
+ {
+ using namespace cv::gpu::cudev::imgproc;
- extractCovData(src, Dx, Dy, buf, blockSize, ksize, borderType, stream);
+ GpuMat src = _src.getGpuMat();
- dst.create(src.size(), CV_32F);
+ extractCovData(src, stream);
- cornerHarris_gpu(blockSize, static_cast<float>(k), Dx, Dy, dst, borderType, StreamAccessor::getStream(stream));
-}
+ _dst.create(src.size(), CV_32FC1);
+ GpuMat dst = _dst.getGpuMat();
-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);
-}
+ cornerHarris_gpu(blockSize_, k_, Dx_, Dy_, dst, borderType_, StreamAccessor::getStream(stream));
+ }
-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);
-}
+ class MinEigenVal : public CornerBase
+ {
+ public:
+ MinEigenVal(int srcType, int blockSize, int ksize, int borderType) :
+ CornerBase(srcType, 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;
+ void compute(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
- CV_Assert(borderType == cv::BORDER_REFLECT101 || borderType == cv::BORDER_REPLICATE || borderType == cv::BORDER_REFLECT);
+ private:
+ float k_;
+ };
- extractCovData(src, Dx, Dy, buf, blockSize, ksize, borderType, stream);
+ void MinEigenVal::compute(InputArray _src, OutputArray _dst, Stream& stream)
+ {
+ using namespace cv::gpu::cudev::imgproc;
+
+ GpuMat src = _src.getGpuMat();
+
+ extractCovData(src, stream);
+
+ _dst.create(src.size(), CV_32FC1);
+ GpuMat dst = _dst.getGpuMat();
+
+ cornerMinEigenVal_gpu(blockSize_, Dx_, Dy_, dst, borderType_, StreamAccessor::getStream(stream));
+ }
+}
- dst.create(src.size(), CV_32F);
+Ptr<gpu::CornernessCriteria> cv::gpu::createHarrisCorner(int srcType, int blockSize, int ksize, double k, int borderType)
+{
+ return new Harris(srcType, blockSize, ksize, k, borderType);
+}
- cornerMinEigenVal_gpu(blockSize, Dx, Dy, dst, borderType, StreamAccessor::getStream(stream));
+Ptr<gpu::CornernessCriteria> cv::gpu::createMinEigenValCorner(int srcType, int blockSize, int ksize, int borderType)
+{
+ return new MinEigenVal(srcType, blockSize, ksize, borderType);
}
#endif /* !defined (HAVE_CUDA) */