Merge pull request #5340 from alalek:ocl_off
This commit is contained in:
commit
3942b1f362
@ -26,6 +26,8 @@ set(STR_CPP "// This file is auto-generated. Do not edit!
|
||||
#include \"precomp.hpp\"
|
||||
#include \"${OUTPUT_HPP_NAME}\"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace ocl
|
||||
@ -40,6 +42,8 @@ set(STR_HPP "// This file is auto-generated. Do not edit!
|
||||
#include \"opencv2/core/ocl_genbase.hpp\"
|
||||
#include \"opencv2/core/opencl/ocl_defs.hpp\"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace ocl
|
||||
@ -82,8 +86,8 @@ foreach(cl ${cl_list})
|
||||
set(STR_HPP "${STR_HPP}${STR_HPP_DECL}")
|
||||
endforeach()
|
||||
|
||||
set(STR_CPP "${STR_CPP}}\n${nested_namespace_end}}\n")
|
||||
set(STR_HPP "${STR_HPP}}\n${nested_namespace_end}}\n")
|
||||
set(STR_CPP "${STR_CPP}}\n${nested_namespace_end}}\n#endif\n")
|
||||
set(STR_HPP "${STR_HPP}}\n${nested_namespace_end}}\n#endif\n")
|
||||
|
||||
file(WRITE "${OUTPUT}" "${STR_CPP}")
|
||||
|
||||
|
@ -86,6 +86,7 @@ struct StereoBMParams
|
||||
int dispType;
|
||||
};
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static bool ocl_prefilter_norm(InputArray _input, OutputArray _output, int winsize, int prefilterCap)
|
||||
{
|
||||
ocl::Kernel k("prefilter_norm", ocl::calib3d::stereobm_oclsrc, cv::format("-D WSZ=%d", winsize));
|
||||
@ -106,6 +107,7 @@ static bool ocl_prefilter_norm(InputArray _input, OutputArray _output, int winsi
|
||||
|
||||
return k.run(2, globalThreads, NULL, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void prefilterNorm( const Mat& src, Mat& dst, int winsize, int ftzero, uchar* buf )
|
||||
{
|
||||
@ -170,6 +172,7 @@ static void prefilterNorm( const Mat& src, Mat& dst, int winsize, int ftzero, uc
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static bool ocl_prefilter_xsobel(InputArray _input, OutputArray _output, int prefilterCap)
|
||||
{
|
||||
ocl::Kernel k("prefilter_xsobel", ocl::calib3d::stereobm_oclsrc);
|
||||
@ -186,6 +189,7 @@ static bool ocl_prefilter_xsobel(InputArray _input, OutputArray _output, int pre
|
||||
|
||||
return k.run(2, globalThreads, NULL, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
prefilterXSobel( const Mat& src, Mat& dst, int ftzero )
|
||||
@ -849,6 +853,7 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static bool ocl_prefiltering(InputArray left0, InputArray right0, OutputArray left, OutputArray right, StereoBMParams* state)
|
||||
{
|
||||
if( state->preFilterType == StereoBM::PREFILTER_NORMALIZED_RESPONSE )
|
||||
@ -867,6 +872,7 @@ static bool ocl_prefiltering(InputArray left0, InputArray right0, OutputArray le
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct PrefilterInvoker : public ParallelLoopBody
|
||||
{
|
||||
@ -896,6 +902,7 @@ struct PrefilterInvoker : public ParallelLoopBody
|
||||
StereoBMParams* state;
|
||||
};
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static bool ocl_stereobm( InputArray _left, InputArray _right,
|
||||
OutputArray _disp, StereoBMParams* state)
|
||||
{
|
||||
@ -940,6 +947,7 @@ static bool ocl_stereobm( InputArray _left, InputArray _right,
|
||||
idx = k.set(idx, state->uniquenessRatio);
|
||||
return k.run(3, globalThreads, localThreads, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct FindStereoCorrespInvoker : public ParallelLoopBody
|
||||
{
|
||||
@ -1074,6 +1082,7 @@ public:
|
||||
|
||||
int FILTERED = (params.minDisparity - 1) << DISPARITY_SHIFT;
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if(ocl::useOpenCL() && disparr.isUMat() && params.textureThreshold == 0)
|
||||
{
|
||||
UMat left, right;
|
||||
@ -1090,6 +1099,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Mat left0 = leftarr.getMat(), right0 = rightarr.getMat();
|
||||
disparr.create(left0.size(), dtype);
|
||||
|
@ -1364,10 +1364,16 @@ void pow( InputArray _src, double power, OutputArray _dst )
|
||||
{
|
||||
int type = _src.type(), depth = CV_MAT_DEPTH(type),
|
||||
cn = CV_MAT_CN(type), ipower = cvRound(power);
|
||||
bool is_ipower = fabs(ipower - power) < DBL_EPSILON,
|
||||
useOpenCL = _dst.isUMat() && _src.dims() <= 2;
|
||||
bool is_ipower = fabs(ipower - power) < DBL_EPSILON;
|
||||
#ifdef HAVE_OPENCL
|
||||
bool useOpenCL = _dst.isUMat() && _src.dims() <= 2;
|
||||
#endif
|
||||
|
||||
if( is_ipower && !(ocl::Device::getDefault().isIntel() && useOpenCL && depth != CV_64F))
|
||||
if( is_ipower
|
||||
#ifdef HAVE_OPENCL
|
||||
&& !(useOpenCL && ocl::Device::getDefault().isIntel() && depth != CV_64F)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
switch( ipower )
|
||||
{
|
||||
|
@ -54,7 +54,9 @@
|
||||
|
||||
#include "opencv2/core/private.hpp"
|
||||
#include "opencv2/core/private.cuda.hpp"
|
||||
#ifdef HAVE_OPENCL
|
||||
#include "opencv2/core/ocl.hpp"
|
||||
#endif
|
||||
|
||||
#include "opencv2/hal.hpp"
|
||||
|
||||
@ -262,7 +264,11 @@ struct ImplCollector
|
||||
|
||||
struct CoreTLSData
|
||||
{
|
||||
CoreTLSData() : device(0), useOpenCL(-1), useIPP(-1)
|
||||
CoreTLSData() :
|
||||
//#ifdef HAVE_OPENCL
|
||||
device(0), useOpenCL(-1),
|
||||
//#endif
|
||||
useIPP(-1)
|
||||
{
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
useTegra = -1;
|
||||
@ -270,9 +276,11 @@ struct CoreTLSData
|
||||
}
|
||||
|
||||
RNG rng;
|
||||
//#ifdef HAVE_OPENCL
|
||||
int device;
|
||||
ocl::Queue oclQueue;
|
||||
int useOpenCL; // 1 - use, 0 - do not use, -1 - auto/not initialized
|
||||
//#endif
|
||||
int useIPP; // 1 - use, 0 - do not use, -1 - auto/not initialized
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
int useTegra; // 1 - use, 0 - do not use, -1 - auto/not initialized
|
||||
|
@ -391,7 +391,9 @@ void setUseOptimized( bool flag )
|
||||
USE_SSE2 = currentFeatures->have[CV_CPU_SSE2];
|
||||
|
||||
ipp::setUseIPP(flag);
|
||||
#ifdef HAVE_OPENCL
|
||||
ocl::setUseOpenCL(flag);
|
||||
#endif
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
::tegra::setUseTegra(flag);
|
||||
#endif
|
||||
|
@ -691,6 +691,7 @@ INSTANTIATE_TEST_CASE_P(UMat, getUMat, Combine(
|
||||
|
||||
///////////////////////////////////////////////////////////////// OpenCL ////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
TEST(UMat, BufferPoolGrowing)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
@ -716,6 +717,7 @@ TEST(UMat, BufferPoolGrowing)
|
||||
else
|
||||
std::cout << "Skipped, no OpenCL" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
class CV_UMatTest :
|
||||
public cvtest::BaseTest
|
||||
@ -956,6 +958,9 @@ TEST(UMat, CopyToIfDeviceCopyIsObsolete)
|
||||
|
||||
TEST(UMat, setOpenCL)
|
||||
{
|
||||
#ifndef HAVE_OPENCL
|
||||
return; // test skipped
|
||||
#else
|
||||
// save the current state
|
||||
bool useOCL = cv::ocl::useOpenCL();
|
||||
|
||||
@ -993,6 +998,7 @@ TEST(UMat, setOpenCL)
|
||||
|
||||
// reset state to the previous one
|
||||
cv::ocl::setUseOpenCL(useOCL);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(UMat, ReadBufferRect)
|
||||
|
@ -250,6 +250,7 @@ void FAST_t(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bo
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
template<typename pt>
|
||||
struct cmp_pt
|
||||
{
|
||||
@ -326,16 +327,18 @@ static bool ocl_FAST( InputArray _img, std::vector<KeyPoint>& keypoints,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool nonmax_suppression, int type)
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
if( ocl::useOpenCL() && _img.isUMat() && type == FastFeatureDetector::TYPE_9_16 &&
|
||||
ocl_FAST(_img, keypoints, threshold, nonmax_suppression, 10000))
|
||||
{
|
||||
CV_IMPL_ADD(CV_IMPL_OCL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch(type) {
|
||||
case FastFeatureDetector::TYPE_5_8:
|
||||
|
@ -52,6 +52,7 @@ namespace cv
|
||||
|
||||
/////////////////////// ocl functions for BFMatcher ///////////////////////////
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static void ensureSizeIsEnough(int rows, int cols, int type, UMat &m)
|
||||
{
|
||||
if (m.type() == type && m.rows >= rows && m.cols >= cols)
|
||||
@ -390,6 +391,7 @@ static bool ocl_radiusMatchDownload(const UMat &trainIdx, const UMat &distance,
|
||||
|
||||
return ocl_radiusMatchConvert(trainIdxCPU, distanceCPU, nMatchesCPU, matches, compactResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
* DescriptorMatcher *
|
||||
@ -693,6 +695,7 @@ Ptr<DescriptorMatcher> BFMatcher::clone( bool emptyTrainData ) const
|
||||
return matcher;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static bool ocl_match(InputArray query, InputArray _train, std::vector< std::vector<DMatch> > &matches, int dstType)
|
||||
{
|
||||
UMat trainIdx, distance;
|
||||
@ -714,6 +717,7 @@ static bool ocl_knnMatch(InputArray query, InputArray _train, std::vector< std::
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void BFMatcher::knnMatchImpl( InputArray _queryDescriptors, std::vector<std::vector<DMatch> >& matches, int knn,
|
||||
InputArrayOfArrays _masks, bool compactResult )
|
||||
@ -744,6 +748,7 @@ void BFMatcher::knnMatchImpl( InputArray _queryDescriptors, std::vector<std::vec
|
||||
utrainDescCollection.clear();
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
int trainDescVectorSize = trainDescCollection.empty() ? (int)utrainDescCollection.size() : (int)trainDescCollection.size();
|
||||
Size trainDescSize = trainDescCollection.empty() ? utrainDescCollection[0].size() : trainDescCollection[0].size();
|
||||
int trainDescOffset = trainDescCollection.empty() ? (int)utrainDescCollection[0].offset : 0;
|
||||
@ -791,6 +796,7 @@ void BFMatcher::knnMatchImpl( InputArray _queryDescriptors, std::vector<std::vec
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Mat queryDescriptors = _queryDescriptors.getMat();
|
||||
if(trainDescCollection.empty() && !utrainDescCollection.empty())
|
||||
@ -851,6 +857,7 @@ void BFMatcher::knnMatchImpl( InputArray _queryDescriptors, std::vector<std::vec
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static bool ocl_radiusMatch(InputArray query, InputArray _train, std::vector< std::vector<DMatch> > &matches,
|
||||
float maxDistance, int dstType, bool compactResult)
|
||||
{
|
||||
@ -861,6 +868,7 @@ static bool ocl_radiusMatch(InputArray query, InputArray _train, std::vector< st
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void BFMatcher::radiusMatchImpl( InputArray _queryDescriptors, std::vector<std::vector<DMatch> >& matches,
|
||||
float maxDistance, InputArrayOfArrays _masks, bool compactResult )
|
||||
@ -888,6 +896,7 @@ void BFMatcher::radiusMatchImpl( InputArray _queryDescriptors, std::vector<std::
|
||||
utrainDescCollection.clear();
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
int trainDescVectorSize = trainDescCollection.empty() ? (int)utrainDescCollection.size() : (int)trainDescCollection.size();
|
||||
Size trainDescSize = trainDescCollection.empty() ? utrainDescCollection[0].size() : trainDescCollection[0].size();
|
||||
int trainDescOffset = trainDescCollection.empty() ? (int)utrainDescCollection[0].offset : 0;
|
||||
@ -913,6 +922,7 @@ void BFMatcher::radiusMatchImpl( InputArray _queryDescriptors, std::vector<std::
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Mat queryDescriptors = _queryDescriptors.getMat();
|
||||
if(trainDescCollection.empty() && !utrainDescCollection.empty())
|
||||
|
@ -57,6 +57,7 @@ template<typename _Tp> inline void copyVectorToUMat(const std::vector<_Tp>& v, O
|
||||
Mat(1, (int)(v.size()*sizeof(v[0])), CV_8U, (void*)&v[0]).copyTo(um);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static bool
|
||||
ocl_HarrisResponses(const UMat& imgbuf,
|
||||
const UMat& layerinfo,
|
||||
@ -120,7 +121,7 @@ ocl_computeOrbDescriptors(const UMat& imgbuf, const UMat& layerInfo,
|
||||
ocl::KernelArg::PtrReadOnly(pattern),
|
||||
nkeypoints, dsize).run(1, globalSize, 0, true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Function that computes the Harris responses in a
|
||||
@ -726,6 +727,7 @@ int ORB_Impl::defaultNorm() const
|
||||
return NORM_HAMMING;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
static void uploadORBKeypoints(const std::vector<KeyPoint>& src, std::vector<Vec3i>& buf, OutputArray dst)
|
||||
{
|
||||
size_t i, n = src.size();
|
||||
@ -758,7 +760,7 @@ static void uploadORBKeypoints(const std::vector<KeyPoint>& src,
|
||||
}
|
||||
copyVectorToUMat(buf, dst);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** Compute the ORB_Impl keypoints on an image
|
||||
* @param image_pyramid the image pyramid to compute the features and descriptors on
|
||||
@ -776,6 +778,10 @@ static void computeKeyPoints(const Mat& imagePyramid,
|
||||
int edgeThreshold, int patchSize, int scoreType,
|
||||
bool useOCL, int fastThreshold )
|
||||
{
|
||||
#ifndef HAVE_OPENCL
|
||||
(void)uimagePyramid;(void)ulayerInfo;(void)useOCL;
|
||||
#endif
|
||||
|
||||
int i, nkeypoints, level, nlevels = (int)layerInfo.size();
|
||||
std::vector<int> nfeaturesPerLevel(nlevels);
|
||||
|
||||
@ -862,6 +868,7 @@ static void computeKeyPoints(const Mat& imagePyramid,
|
||||
// Select best features using the Harris cornerness (better scoring than FAST)
|
||||
if( scoreType == ORB_Impl::HARRIS_SCORE )
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
if( useOCL )
|
||||
{
|
||||
uploadORBKeypoints(allKeypoints, ukeypoints_buf, ukeypoints);
|
||||
@ -877,6 +884,7 @@ static void computeKeyPoints(const Mat& imagePyramid,
|
||||
}
|
||||
|
||||
if( !useOCL )
|
||||
#endif
|
||||
HarrisResponses(imagePyramid, layerInfo, allKeypoints, 7, HARRIS_K);
|
||||
|
||||
std::vector<KeyPoint> newAllKeypoints;
|
||||
@ -902,6 +910,8 @@ static void computeKeyPoints(const Mat& imagePyramid,
|
||||
}
|
||||
|
||||
nkeypoints = (int)allKeypoints.size();
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if( useOCL )
|
||||
{
|
||||
UMat uumax;
|
||||
@ -922,6 +932,7 @@ static void computeKeyPoints(const Mat& imagePyramid,
|
||||
}
|
||||
|
||||
if( !useOCL )
|
||||
#endif
|
||||
{
|
||||
ICAngles(imagePyramid, layerInfo, allKeypoints, umax, halfPatchSize);
|
||||
}
|
||||
@ -1147,6 +1158,7 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
|
||||
GaussianBlur(workingMat, workingMat, Size(7, 7), 2, 2, BORDER_REFLECT_101);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if( useOCL )
|
||||
{
|
||||
imagePyramid.copyTo(uimagePyramid);
|
||||
@ -1166,6 +1178,7 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
|
||||
}
|
||||
|
||||
if( !useOCL )
|
||||
#endif
|
||||
{
|
||||
Mat descriptors = _descriptors.getMat();
|
||||
computeOrbDescriptors(imagePyramid, layerInfo, layerScale,
|
||||
|
@ -1040,7 +1040,7 @@ public:
|
||||
struct getRect { Rect operator ()(const CvAvgComp& e) const { return e.rect; } };
|
||||
struct getNeighbors { int operator ()(const CvAvgComp& e) const { return e.neighbors; } };
|
||||
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
bool CascadeClassifierImpl::ocl_detectMultiScaleNoGrouping( const std::vector<float>& scales,
|
||||
std::vector<Rect>& candidates )
|
||||
{
|
||||
@ -1171,6 +1171,7 @@ bool CascadeClassifierImpl::ocl_detectMultiScaleNoGrouping( const std::vector<fl
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CascadeClassifierImpl::isOldFormatCascade() const
|
||||
{
|
||||
@ -1278,10 +1279,12 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( InputArray _image, std::
|
||||
if( scales.size() == 0 || !featureEvaluator->setImage(gray, scales) )
|
||||
return;
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
// OpenCL code
|
||||
CV_OCL_RUN(use_ocl, ocl_detectMultiScaleNoGrouping( scales, candidates ))
|
||||
|
||||
tryOpenCL = false;
|
||||
#endif
|
||||
|
||||
// CPU code
|
||||
featureEvaluator->getMats();
|
||||
@ -1527,9 +1530,11 @@ bool CascadeClassifierImpl::Data::read(const FileNode &root)
|
||||
|
||||
bool CascadeClassifierImpl::read_(const FileNode& root)
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
tryOpenCL = true;
|
||||
haarKernel = ocl::Kernel();
|
||||
lbpKernel = ocl::Kernel();
|
||||
#endif
|
||||
ustages.release();
|
||||
unodes.release();
|
||||
uleaves.release();
|
||||
|
@ -125,9 +125,10 @@ protected:
|
||||
int yStep, double factor, std::vector<Rect>& candidates,
|
||||
std::vector<int>& rejectLevels, std::vector<double>& levelWeights,
|
||||
Size sumSize0, bool outputRejectLevels = false );
|
||||
#ifdef HAVE_OPENCL
|
||||
bool ocl_detectMultiScaleNoGrouping( const std::vector<float>& scales,
|
||||
std::vector<Rect>& candidates );
|
||||
|
||||
#endif
|
||||
void detectMultiScaleNoGrouping( InputArray image, std::vector<Rect>& candidates,
|
||||
std::vector<int>& rejectLevels, std::vector<double>& levelWeights,
|
||||
double scaleFactor, Size minObjectSize, Size maxObjectSize,
|
||||
@ -218,8 +219,10 @@ protected:
|
||||
Ptr<MaskGenerator> maskGenerator;
|
||||
UMat ugrayImage;
|
||||
UMat ufacepos, ustages, unodes, uleaves, usubsets;
|
||||
#ifdef HAVE_OPENCL
|
||||
ocl::Kernel haarKernel, lbpKernel;
|
||||
bool tryOpenCL;
|
||||
#endif
|
||||
|
||||
Mutex mtx;
|
||||
};
|
||||
|
@ -110,6 +110,7 @@ Rect PlaneWarper::buildMaps(Size src_size, InputArray K, InputArray R, InputArra
|
||||
_xmap.create(dsize, CV_32FC1);
|
||||
_ymap.create(dsize, CV_32FC1);
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if (ocl::useOpenCL())
|
||||
{
|
||||
ocl::Kernel k("buildWarpPlaneMaps", ocl::stitching::warpers_oclsrc);
|
||||
@ -132,6 +133,7 @@ Rect PlaneWarper::buildMaps(Size src_size, InputArray K, InputArray R, InputArra
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Mat xmap = _xmap.getMat(), ymap = _ymap.getMat();
|
||||
|
||||
@ -310,6 +312,7 @@ void SphericalPortraitWarper::detectResultRoi(Size src_size, Point &dst_tl, Poin
|
||||
|
||||
Rect SphericalWarper::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
if (ocl::useOpenCL())
|
||||
{
|
||||
ocl::Kernel k("buildWarpSphericalMaps", ocl::stitching::warpers_oclsrc);
|
||||
@ -339,7 +342,7 @@ Rect SphericalWarper::buildMaps(Size src_size, InputArray K, InputArray R, Outpu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return RotationWarperBase<SphericalProjector>::buildMaps(src_size, K, R, xmap, ymap);
|
||||
}
|
||||
|
||||
@ -358,6 +361,7 @@ Point SphericalWarper::warp(InputArray src, InputArray K, InputArray R, int inte
|
||||
|
||||
Rect CylindricalWarper::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
if (ocl::useOpenCL())
|
||||
{
|
||||
ocl::Kernel k("buildWarpCylindricalMaps", ocl::stitching::warpers_oclsrc);
|
||||
@ -388,7 +392,7 @@ Rect CylindricalWarper::buildMaps(Size src_size, InputArray K, InputArray R, Out
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return RotationWarperBase<CylindricalProjector>::buildMaps(src_size, K, R, xmap, ymap);
|
||||
}
|
||||
|
||||
|
@ -142,8 +142,9 @@ public:
|
||||
fCT = defaultfCT2;
|
||||
nShadowDetection = defaultnShadowDetection2;
|
||||
fTau = defaultfTau;
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
opencl_ON = true;
|
||||
#endif
|
||||
}
|
||||
//! the full constructor that takes the length of the history,
|
||||
// the number of gaussian mixtures, the background ratio parameter and the noise strength
|
||||
@ -168,8 +169,9 @@ public:
|
||||
nShadowDetection = defaultnShadowDetection2;
|
||||
fTau = defaultfTau;
|
||||
name_ = "BackgroundSubtractor.MOG2";
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
opencl_ON = true;
|
||||
#endif
|
||||
}
|
||||
//! the destructor
|
||||
~BackgroundSubtractorMOG2Impl() {}
|
||||
@ -190,6 +192,7 @@ public:
|
||||
CV_Assert( nchannels <= CV_CN_MAX );
|
||||
CV_Assert( nmixtures <= 255);
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if (ocl::useOpenCL() && opencl_ON)
|
||||
{
|
||||
create_ocl_apply_kernel();
|
||||
@ -218,6 +221,7 @@ public:
|
||||
u_bgmodelUsedModes.setTo(cv::Scalar::all(0));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// for each gaussian mixture of each pixel bg model we store ...
|
||||
// the mixture weight (w),
|
||||
@ -263,11 +267,13 @@ public:
|
||||
if ((bShadowDetection && detectshadows) || (!bShadowDetection && !detectshadows))
|
||||
return;
|
||||
bShadowDetection = detectshadows;
|
||||
#ifdef HAVE_OPENCL
|
||||
if (!kernel_apply.empty())
|
||||
{
|
||||
create_ocl_apply_kernel();
|
||||
CV_Assert( !kernel_apply.empty() );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual int getShadowValue() const { return nShadowDetection; }
|
||||
@ -316,6 +322,7 @@ protected:
|
||||
Mat bgmodel;
|
||||
Mat bgmodelUsedModes;//keep track of number of modes per pixel
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
//for OCL
|
||||
|
||||
mutable bool opencl_ON;
|
||||
@ -327,6 +334,7 @@ protected:
|
||||
|
||||
mutable ocl::Kernel kernel_apply;
|
||||
mutable ocl::Kernel kernel_getBg;
|
||||
#endif
|
||||
|
||||
int nframes;
|
||||
int history;
|
||||
@ -379,9 +387,11 @@ protected:
|
||||
|
||||
String name_;
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
bool ocl_getBackgroundImage(OutputArray backgroundImage) const;
|
||||
bool ocl_apply(InputArray _image, OutputArray _fgmask, double learningRate=-1);
|
||||
void create_ocl_apply_kernel();
|
||||
#endif
|
||||
};
|
||||
|
||||
struct GaussBGStatModel2Params
|
||||
@ -810,8 +820,6 @@ bool BackgroundSubtractorMOG2Impl::ocl_getBackgroundImage(OutputArray _backgroun
|
||||
return kernel_getBg.run(2, globalsize, NULL, false);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void BackgroundSubtractorMOG2Impl::create_ocl_apply_kernel()
|
||||
{
|
||||
int nchannels = CV_MAT_CN(frameType);
|
||||
@ -819,6 +827,8 @@ void BackgroundSubtractorMOG2Impl::create_ocl_apply_kernel()
|
||||
kernel_apply.create("mog2_kernel", ocl::video::bgfg_mog2_oclsrc, opts);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void BackgroundSubtractorMOG2Impl::apply(InputArray _image, OutputArray _fgmask, double learningRate)
|
||||
{
|
||||
bool needToInitialize = nframes == 0 || learningRate >= 1 || _image.size() != frameSize || _image.type() != frameType;
|
||||
@ -826,6 +836,7 @@ void BackgroundSubtractorMOG2Impl::apply(InputArray _image, OutputArray _fgmask,
|
||||
if( needToInitialize )
|
||||
initialize(_image.size(), _image.type());
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if (opencl_ON)
|
||||
{
|
||||
CV_OCL_RUN(opencl_ON, ocl_apply(_image, _fgmask, learningRate))
|
||||
@ -833,6 +844,7 @@ void BackgroundSubtractorMOG2Impl::apply(InputArray _image, OutputArray _fgmask,
|
||||
opencl_ON = false;
|
||||
initialize(_image.size(), _image.type());
|
||||
}
|
||||
#endif
|
||||
|
||||
Mat image = _image.getMat();
|
||||
_fgmask.create( image.size(), CV_8U );
|
||||
@ -856,6 +868,7 @@ void BackgroundSubtractorMOG2Impl::apply(InputArray _image, OutputArray _fgmask,
|
||||
|
||||
void BackgroundSubtractorMOG2Impl::getBackgroundImage(OutputArray backgroundImage) const
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
if (opencl_ON)
|
||||
{
|
||||
CV_OCL_RUN(opencl_ON, ocl_getBackgroundImage(backgroundImage))
|
||||
@ -863,6 +876,7 @@ void BackgroundSubtractorMOG2Impl::getBackgroundImage(OutputArray backgroundImag
|
||||
opencl_ON = false;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
int nchannels = CV_MAT_CN(frameType);
|
||||
CV_Assert(nchannels == 1 || nchannels == 3);
|
||||
|
@ -837,6 +837,7 @@ int cv::buildOpticalFlowPyramid(InputArray _img, OutputArrayOfArrays pyramid, Si
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
namespace cv
|
||||
{
|
||||
class PyrLKOpticalFlow
|
||||
@ -1084,6 +1085,7 @@ namespace cv
|
||||
return opticalFlow.sparse(_prevImg.getUMat(), _nextImg.getUMat(), _prevPts.getUMat(), umatNextPts, umatStatus, umatErr);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
void cv::calcOpticalFlowPyrLK( InputArray _prevImg, InputArray _nextImg,
|
||||
InputArray _prevPts, InputOutputArray _nextPts,
|
||||
@ -1092,6 +1094,7 @@ void cv::calcOpticalFlowPyrLK( InputArray _prevImg, InputArray _nextImg,
|
||||
TermCriteria criteria,
|
||||
int flags, double minEigThreshold )
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
bool use_opencl = ocl::useOpenCL() &&
|
||||
(_prevImg.isUMat() || _nextImg.isUMat()) &&
|
||||
ocl::Image2D::isFormatSupported(CV_32F, 1, false);
|
||||
@ -1100,6 +1103,7 @@ void cv::calcOpticalFlowPyrLK( InputArray _prevImg, InputArray _nextImg,
|
||||
CV_IMPL_ADD(CV_IMPL_OCL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
Mat prevPtsMat = _prevPts.getMat();
|
||||
const int derivDepth = DataType<cv::detail::deriv_type>::depth;
|
||||
|
@ -583,6 +583,7 @@ FarnebackUpdateFlow_GaussianBlur( const Mat& _R0, const Mat& _R1,
|
||||
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
namespace cv
|
||||
{
|
||||
class FarnebackOpticalFlow
|
||||
@ -1074,17 +1075,20 @@ static bool ocl_calcOpticalFlowFarneback( InputArray _prev0, InputArray _next0,
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
void cv::calcOpticalFlowFarneback( InputArray _prev0, InputArray _next0,
|
||||
InputOutputArray _flow0, double pyr_scale, int levels, int winsize,
|
||||
int iterations, int poly_n, double poly_sigma, int flags )
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
bool use_opencl = ocl::useOpenCL() && _flow0.isUMat();
|
||||
if( use_opencl && ocl_calcOpticalFlowFarneback(_prev0, _next0, _flow0, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags))
|
||||
{
|
||||
CV_IMPL_ADD(CV_IMPL_OCL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
Mat prev0 = _prev0.getMat(), next0 = _next0.getMat();
|
||||
const int min_size = 32;
|
||||
|
@ -124,9 +124,11 @@ protected:
|
||||
private:
|
||||
void procOneScale(const Mat_<float>& I0, const Mat_<float>& I1, Mat_<float>& u1, Mat_<float>& u2, Mat_<float>& u3);
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
bool procOneScale_ocl(const UMat& I0, const UMat& I1, UMat& u1, UMat& u2);
|
||||
|
||||
bool calc_ocl(InputArray I0, InputArray I1, InputOutputArray flow);
|
||||
#endif
|
||||
struct dataMat
|
||||
{
|
||||
std::vector<Mat_<float> > I0s;
|
||||
@ -170,6 +172,8 @@ private:
|
||||
Mat_<float> u3x_buf;
|
||||
Mat_<float> u3y_buf;
|
||||
} dm;
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
struct dataUMat
|
||||
{
|
||||
std::vector<UMat> I0s;
|
||||
@ -195,8 +199,10 @@ private:
|
||||
UMat diff_buf;
|
||||
UMat norm_buf;
|
||||
} dum;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
namespace cv_ocl_tvl1flow
|
||||
{
|
||||
bool centeredGradient(const UMat &src, UMat &dx, UMat &dy);
|
||||
@ -353,6 +359,7 @@ bool cv_ocl_tvl1flow::estimateDualVariables(UMat &u1, UMat &u2,
|
||||
return kernel.run(2, globalsize, NULL, false);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
OpticalFlowDual_TVL1::OpticalFlowDual_TVL1()
|
||||
{
|
||||
@ -499,6 +506,7 @@ void OpticalFlowDual_TVL1::calc(InputArray _I0, InputArray _I1, InputOutputArray
|
||||
merge(uxy, 2, _flow);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
bool OpticalFlowDual_TVL1::calc_ocl(InputArray _I0, InputArray _I1, InputOutputArray _flow)
|
||||
{
|
||||
UMat I0 = _I0.getUMat();
|
||||
@ -598,6 +606,7 @@ bool OpticalFlowDual_TVL1::calc_ocl(InputArray _I0, InputArray _I1, InputOutputA
|
||||
merge(uxy, _flow);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// buildFlowMap
|
||||
@ -1180,6 +1189,7 @@ void estimateDualVariables(const Mat_<float>& u1x, const Mat_<float>& u1y,
|
||||
parallel_for_(Range(0, u1x.rows), body);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
bool OpticalFlowDual_TVL1::procOneScale_ocl(const UMat& I0, const UMat& I1, UMat& u1, UMat& u2)
|
||||
{
|
||||
using namespace cv_ocl_tvl1flow;
|
||||
@ -1267,6 +1277,7 @@ bool OpticalFlowDual_TVL1::procOneScale_ocl(const UMat& I0, const UMat& I1, UMat
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void OpticalFlowDual_TVL1::procOneScale(const Mat_<float>& I0, const Mat_<float>& I1, Mat_<float>& u1, Mat_<float>& u2, Mat_<float>& u3)
|
||||
{
|
||||
@ -1402,6 +1413,7 @@ void OpticalFlowDual_TVL1::collectGarbage()
|
||||
dm.u2x_buf.release();
|
||||
dm.u2y_buf.release();
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
//dataUMat structure dum
|
||||
dum.I0s.clear();
|
||||
dum.I1s.clear();
|
||||
@ -1425,6 +1437,7 @@ void OpticalFlowDual_TVL1::collectGarbage()
|
||||
|
||||
dum.diff_buf.release();
|
||||
dum.norm_buf.release();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user