You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
215 lines
8.4 KiB
215 lines
8.4 KiB
From ac8dd366e4a1877e0af16961a4094496bed955f7 Mon Sep 17 00:00:00 2001
|
|
From: Alexander Alekhin <alexander.alekhin@itseez.com>
|
|
Date: Sun, 13 Sep 2015 21:18:47 +0300
|
|
Subject: [PATCH] ocl: fix "off" mode
|
|
|
|
diff --git opencv_contrib-master/modules/tracking/src/tldDetector.cpp opencv_contrib-master/modules/tracking/src/tldDetector.cpp
|
|
index cbb783e..d61444b 100644
|
|
--- opencv_contrib-master/modules/tracking/src/tldDetector.cpp
|
|
+++ opencv_contrib-master/modules/tracking/src/tldDetector.cpp
|
|
@@ -104,6 +104,7 @@ namespace cv
|
|
return splus / (sminus + splus);
|
|
}
|
|
|
|
+#ifdef HAVE_OPENCL
|
|
double TLDDetector::ocl_Sr(const Mat_<uchar>& patch)
|
|
{
|
|
//int64 e1, e2, e3, e4;
|
|
@@ -283,6 +284,7 @@ namespace cv
|
|
//t = (e2 - e1) / getTickFrequency()*1000.0;
|
|
//printf("Sr GPU: %f\n\n", t);
|
|
}
|
|
+#endif
|
|
|
|
// Calculate Conservative similarity of the patch (NN-Model)
|
|
double TLDDetector::Sc(const Mat_<uchar>& patch)
|
|
@@ -337,6 +339,7 @@ namespace cv
|
|
return splus / (sminus + splus);
|
|
}
|
|
|
|
+#ifdef HAVE_OPENCL
|
|
double TLDDetector::ocl_Sc(const Mat_<uchar>& patch)
|
|
{
|
|
//int64 e1, e2, e3, e4;
|
|
@@ -415,6 +418,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)
|
|
@@ -565,6 +569,7 @@ namespace cv
|
|
return true;
|
|
}
|
|
|
|
+#ifdef HAVE_OPENCL
|
|
bool TLDDetector::ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize)
|
|
{
|
|
patches.clear();
|
|
@@ -696,6 +701,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.
|
|
diff --git opencv_contrib-master/modules/tracking/src/tldDetector.hpp opencv_contrib-master/modules/tracking/src/tldDetector.hpp
|
|
index 3e11895..1caff57 100644
|
|
--- opencv_contrib-master/modules/tracking/src/tldDetector.hpp
|
|
+++ opencv_contrib-master/modules/tracking/src/tldDetector.hpp
|
|
@@ -74,10 +74,12 @@ namespace cv
|
|
inline double ensembleClassifierNum(const uchar* data);
|
|
inline 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;
|
|
diff --git opencv_contrib-master/modules/tracking/src/tldModel.cpp opencv_contrib-master/modules/tracking/src/tldModel.cpp
|
|
index 0854022..47fc32a 100644
|
|
--- opencv_contrib-master/modules/tracking/src/tldModel.cpp
|
|
+++ opencv_contrib-master/modules/tracking/src/tldModel.cpp
|
|
@@ -246,6 +246,7 @@ namespace cv
|
|
dfprintf((stdout, "\n"));*/
|
|
}
|
|
|
|
+#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;
|
|
@@ -315,6 +316,7 @@ namespace cv
|
|
dfprintf((stdout, "positiveIntoEnsemble = %d ", positiveIntoEnsemble));
|
|
dfprintf((stdout, "\n"));*/
|
|
}
|
|
+#endif // HAVE_OPENCL
|
|
|
|
//Push the patch to the model
|
|
void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example, bool positive)
|
|
diff --git opencv_contrib-master/modules/tracking/src/tldModel.hpp opencv_contrib-master/modules/tracking/src/tldModel.hpp
|
|
index be9141a..ba7c926 100644
|
|
--- opencv_contrib-master/modules/tracking/src/tldModel.hpp
|
|
+++ opencv_contrib-master/modules/tracking/src/tldModel.hpp
|
|
@@ -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;
|
|
diff --git opencv_contrib-master/modules/tracking/src/tldTracker.cpp opencv_contrib-master/modules/tracking/src/tldTracker.cpp
|
|
index 0f1e2f7..a5190f5 100644
|
|
--- opencv_contrib-master/modules/tracking/src/tldTracker.cpp
|
|
+++ opencv_contrib-master/modules/tracking/src/tldTracker.cpp
|
|
@@ -123,9 +123,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());
|
|
}
|
|
|
|
@@ -211,17 +213,21 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
|
|
tldModel->integrateRelabeled(imageForDetector, image_blurred, detectorResults);
|
|
//dprintf(("%d relabeled by nExpert\n", negRelabeled));
|
|
pExpert.additionalExamples(examplesForModel, examplesForEnsemble);
|
|
- if (ocl::haveOpenCL())
|
|
- tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true);
|
|
- else
|
|
- tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true);
|
|
+#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);
|
|
|
|
- if (ocl::haveOpenCL())
|
|
- tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false);
|
|
- else
|
|
- tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
|
|
+#ifdef HAVE_OPENCL
|
|
+ if (ocl::haveOpenCL())
|
|
+ tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false);
|
|
+ else
|
|
+#endif
|
|
+ tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
|
|
}
|
|
else
|
|
{
|
|
diff --git opencv_contrib-master/modules/xfeatures2d/src/surf.cpp opencv_contrib-master/modules/xfeatures2d/src/surf.cpp
|
|
index 673817e..af5ceaf6 100644
|
|
--- opencv_contrib-master/modules/xfeatures2d/src/surf.cpp
|
|
+++ opencv_contrib-master/modules/xfeatures2d/src/surf.cpp
|
|
@@ -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;
|
|
|
|
diff --git opencv_contrib-master/modules/xfeatures2d/src/surf.hpp opencv_contrib-master/modules/xfeatures2d/src/surf.hpp
|
|
index 2c4e271..cf3fda1 100644
|
|
--- opencv_contrib-master/modules/xfeatures2d/src/surf.hpp
|
|
+++ opencv_contrib-master/modules/xfeatures2d/src/surf.hpp
|
|
@@ -64,6 +64,7 @@ class SURF_Impl : public SURF
|
|
bool upright;
|
|
};
|
|
|
|
+#ifdef HAVE_OPENCL
|
|
class SURF_OCL
|
|
{
|
|
public:
|
|
@@ -145,6 +146,7 @@ class SURF_OCL
|
|
|
|
int status;
|
|
};
|
|
+#endif // HAVE_OPENCL
|
|
|
|
/*
|
|
template<typename _Tp> void copyVectorToUMat(const std::vector<_Tp>& v, UMat& um)
|
|
diff --git opencv_contrib-master/modules/xfeatures2d/src/surf.ocl.cpp opencv_contrib-master/modules/xfeatures2d/src/surf.ocl.cpp
|
|
index b12ebd3..3d9845d 100644
|
|
--- opencv_contrib-master/modules/xfeatures2d/src/surf.ocl.cpp
|
|
+++ opencv_contrib-master/modules/xfeatures2d/src/surf.ocl.cpp
|
|
@@ -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
|