Commit 06b03a7b authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #372 from alalek:ocl_off

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