mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-19 11:21:39 +08:00
Merge pull request #372 from alalek:ocl_off
This commit is contained in:
@@ -153,6 +153,7 @@ namespace dnn
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if (useOpenCL && ocl::useOpenCL() && inpBlob.type() == CV_32F && !is1x1())
|
||||
{
|
||||
std::vector<Range> ranges(4, Range::all());
|
||||
@@ -165,6 +166,7 @@ namespace dnn
|
||||
dst.copyTo(colMat);
|
||||
return;
|
||||
}
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
if (inpBlob.type() == CV_32F)
|
||||
im2col_cpu((float *)srcPtr, inpGroupCn, inpH, inpW, kerH, kerW, padH, padW, strideH, strideW, (float *)colMat.ptr());
|
||||
|
@@ -49,6 +49,7 @@ namespace cv
|
||||
namespace dnn
|
||||
{
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
void im2col_ocl(UMat &img,
|
||||
int channels, int height, int width,
|
||||
int kernel_h, int kernel_w,
|
||||
@@ -78,6 +79,7 @@ void im2col_ocl(UMat &img,
|
||||
|
||||
CV_Assert(im2col_ker.run(1, &globalSize, &localSize, true));
|
||||
}
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -111,12 +111,14 @@ void col2im_cpu(const Dtype* data_col,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
void im2col_ocl(UMat &img,
|
||||
int channels, int height, int width,
|
||||
int kernel_h, int kernel_w,
|
||||
int pad_h, int pad_w,
|
||||
int stride_h, int stride_w,
|
||||
UMat &col);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -83,6 +83,7 @@ namespace cv
|
||||
return splus / (sminus + splus);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
double TLDDetector::ocl_Sr(const Mat_<uchar>& patch)
|
||||
{
|
||||
double splus = 0.0, sminus = 0.0;
|
||||
@@ -185,6 +186,7 @@ namespace cv
|
||||
resultSc[id] = spc / (smc + spc);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Calculate Conservative similarity of the patch (NN-Model)
|
||||
double TLDDetector::Sc(const Mat_<uchar>& patch)
|
||||
@@ -212,6 +214,7 @@ namespace cv
|
||||
return splus / (sminus + splus);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
double TLDDetector::ocl_Sc(const Mat_<uchar>& patch)
|
||||
{
|
||||
double splus = 0.0, sminus = 0.0;
|
||||
@@ -256,6 +259,7 @@ namespace cv
|
||||
return 0.0;
|
||||
return splus / (sminus + splus);
|
||||
}
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
// Generate Search Windows for detector from aspect ratio of initial BBs
|
||||
void TLDDetector::generateScanGrid(int rows, int cols, Size initBox, std::vector<Rect2d>& res, bool withScaling)
|
||||
@@ -393,6 +397,7 @@ namespace cv
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
bool TLDDetector::ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize)
|
||||
{
|
||||
patches.clear();
|
||||
@@ -507,6 +512,7 @@ namespace cv
|
||||
res = maxScRect;
|
||||
return true;
|
||||
}
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
// Computes the variance of subimage given by box, with the help of two integral
|
||||
// images intImgP and intImgP2 (sum of squares), which should be also provided.
|
||||
|
@@ -76,10 +76,12 @@ namespace cv
|
||||
double ensembleClassifierNum(const uchar* data);
|
||||
void prepareClassifiers(int rowstep);
|
||||
double Sr(const Mat_<uchar>& patch);
|
||||
double ocl_Sr(const Mat_<uchar>& patch);
|
||||
double Sc(const Mat_<uchar>& patch);
|
||||
#ifdef HAVE_OPENCL
|
||||
double ocl_Sr(const Mat_<uchar>& patch);
|
||||
double ocl_Sc(const Mat_<uchar>& patch);
|
||||
void ocl_batchSrSc(const Mat_<uchar>& patches, double *resultSr, double *resultSc, int numOfPatches);
|
||||
#endif
|
||||
|
||||
std::vector<TLDEnsembleClassifier> classifiers;
|
||||
Mat *posExp, *negExp;
|
||||
|
@@ -219,6 +219,7 @@ namespace cv
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
void TrackerTLDModel::ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive)
|
||||
{
|
||||
int positiveIntoModel = 0, negativeIntoModel = 0, positiveIntoEnsemble = 0, negativeIntoEnsemble = 0;
|
||||
@@ -271,6 +272,7 @@ namespace cv
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
//Push the patch to the model
|
||||
void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example, bool positive)
|
||||
|
@@ -58,7 +58,9 @@ namespace cv
|
||||
void setBoudingBox(Rect2d boundingBox){ boundingBox_ = boundingBox; }
|
||||
void integrateRelabeled(Mat& img, Mat& imgBlurred, const std::vector<TLDDetector::LabeledPatch>& patches);
|
||||
void integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive);
|
||||
#ifdef HAVE_OPENCL
|
||||
void ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive);
|
||||
#endif
|
||||
Size getMinSize(){ return minSize_; }
|
||||
void printme(FILE* port = stdout);
|
||||
Ptr<TLDDetector> detector;
|
||||
|
@@ -129,9 +129,11 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
#ifdef HAVE_OPENCL
|
||||
if (ocl::haveOpenCL())
|
||||
DETECT_FLG = tldModel->detector->ocl_detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
|
||||
else
|
||||
#endif
|
||||
DETECT_FLG = tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
|
||||
}
|
||||
if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) || ( DETECT_FLG))
|
||||
@@ -199,16 +201,20 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
|
||||
}
|
||||
tldModel->integrateRelabeled(imageForDetector, image_blurred, detectorResults);
|
||||
pExpert.additionalExamples(examplesForModel, examplesForEnsemble);
|
||||
#ifdef HAVE_OPENCL
|
||||
if (ocl::haveOpenCL())
|
||||
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true);
|
||||
else
|
||||
#endif
|
||||
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true);
|
||||
examplesForModel.clear(); examplesForEnsemble.clear();
|
||||
nExpert.additionalExamples(examplesForModel, examplesForEnsemble);
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if (ocl::haveOpenCL())
|
||||
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false);
|
||||
else
|
||||
#endif
|
||||
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
|
||||
}
|
||||
else
|
||||
|
@@ -892,6 +892,7 @@ void SURF_Impl::detectAndCompute(InputArray _img, InputArray _mask,
|
||||
CV_Assert(!_img.empty() && CV_MAT_DEPTH(imgtype) == CV_8U && (imgcn == 1 || imgcn == 3 || imgcn == 4));
|
||||
CV_Assert(_descriptors.needed() || !useProvidedKeypoints);
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
if( ocl::useOpenCL() )
|
||||
{
|
||||
SURF_OCL ocl_surf;
|
||||
@@ -918,6 +919,7 @@ void SURF_Impl::detectAndCompute(InputArray _img, InputArray _mask,
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
Mat img = _img.getMat(), mask = _mask.getMat(), mask1, sum, msum;
|
||||
|
||||
|
@@ -64,6 +64,7 @@ public:
|
||||
bool upright;
|
||||
};
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
class SURF_OCL
|
||||
{
|
||||
public:
|
||||
@@ -145,6 +146,7 @@ protected:
|
||||
|
||||
int status;
|
||||
};
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
/*
|
||||
template<typename _Tp> void copyVectorToUMat(const std::vector<_Tp>& v, UMat& um)
|
||||
|
@@ -43,6 +43,9 @@
|
||||
//
|
||||
//M*/
|
||||
#include "precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
#include "surf.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
@@ -461,3 +464,4 @@ bool SURF_OCL::calcOrientation(UMat &keypoints)
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
|
Reference in New Issue
Block a user