Permalink
Browse files

some attempts to tune the performance

1 parent 02fb3f0 commit b7553d4e2eddc5645023a94a850fe092dd9f223e @vpisarev vpisarev committed Dec 19, 2013
Showing with 187 additions and 150 deletions.
  1. +0 −1 data/haarcascades/haarcascade_eye.xml
  2. +0 −1 data/haarcascades/haarcascade_eye_tree_eyeglasses.xml
  3. +0 −1 data/haarcascades/haarcascade_frontalface_alt.xml
  4. +0 −1 data/haarcascades/haarcascade_frontalface_alt2.xml
  5. +0 −1 data/haarcascades/haarcascade_frontalface_alt_tree.xml
  6. +0 −1 data/haarcascades/haarcascade_frontalface_default.xml
  7. +0 −1 data/haarcascades/haarcascade_fullbody.xml
  8. +0 −1 data/haarcascades/haarcascade_lefteye_2splits.xml
  9. +0 −1 data/haarcascades/haarcascade_lowerbody.xml
  10. +0 −1 data/haarcascades/haarcascade_mcs_eyepair_big.xml
  11. +0 −1 data/haarcascades/haarcascade_mcs_eyepair_small.xml
  12. +0 −1 data/haarcascades/haarcascade_mcs_leftear.xml
  13. +0 −1 data/haarcascades/haarcascade_mcs_lefteye.xml
  14. +0 −1 data/haarcascades/haarcascade_mcs_mouth.xml
  15. +0 −1 data/haarcascades/haarcascade_mcs_nose.xml
  16. +0 −1 data/haarcascades/haarcascade_mcs_rightear.xml
  17. +0 −1 data/haarcascades/haarcascade_mcs_righteye.xml
  18. +0 −1 data/haarcascades/haarcascade_mcs_upperbody.xml
  19. +0 −1 data/haarcascades/haarcascade_profileface.xml
  20. +0 −1 data/haarcascades/haarcascade_righteye_2splits.xml
  21. +0 −1 data/haarcascades/haarcascade_smile.xml
  22. +0 −1 data/haarcascades/haarcascade_upperbody.xml
  23. +37 −19 modules/objdetect/src/cascadedetect.cpp
  24. +53 −43 modules/objdetect/src/cascadedetect.hpp
  25. +0 −1 modules/objdetect/src/cascadedetect_convert.cpp
  26. +97 −65 modules/objdetect/src/opencl/haarobjectdetect.cl
@@ -48,7 +48,6 @@
<height>20</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>93</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -48,7 +48,6 @@
<height>20</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>47</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -48,7 +48,6 @@
<height>20</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>213</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -48,7 +48,6 @@
<height>20</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>109</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -49,7 +49,6 @@
<height>20</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>406</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -48,7 +48,6 @@
<height>24</height>
<width>24</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>211</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -142,7 +142,6 @@ Thanks to Martin Spengler, ETH Zurich, for providing the demo movie.
<height>14</height>
<width>28</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>107</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -49,7 +49,6 @@
<height>20</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>33</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -142,7 +142,6 @@ Thanks to Martin Spengler, ETH Zurich, for providing the demo movie.
<height>19</height>
<width>23</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>89</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -88,7 +88,6 @@ mcastrillon@iusiani.ulpgc.es
<height>45</height>
<width>11</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>85</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -87,7 +87,6 @@ mcastrillon@iusiani.ulpgc.es
<height>22</height>
<width>5</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>133</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -67,7 +67,6 @@ mcastrillon@iusiani.ulpgc.es
<height>12</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>65</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -87,7 +87,6 @@ mcastrillon@iusiani.ulpgc.es
<height>18</height>
<width>12</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>279</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -87,7 +87,6 @@ mcastrillon@iusiani.ulpgc.es
<height>25</height>
<width>15</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>218</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -87,7 +87,6 @@ mcastrillon@iusiani.ulpgc.es
<height>18</height>
<width>15</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>377</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -67,7 +67,6 @@ mcastrillon@iusiani.ulpgc.es
<height>12</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>61</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -87,7 +87,6 @@ mcastrillon@iusiani.ulpgc.es
<height>18</height>
<width>12</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>415</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -85,7 +85,6 @@ mcastrillon@iusiani.ulpgc.es
<height>22</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>334</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -48,7 +48,6 @@
<height>20</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>195</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -49,7 +49,6 @@
<height>20</height>
<width>20</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>34</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -50,7 +50,6 @@
<height>36</height>
<width>18</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>53</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -142,7 +142,6 @@ Thanks to Martin Spengler, ETH Zurich, for providing the demo movie.
<height>22</height>
<width>18</width>
<stageParams>
- <maxDepth>0</maxDepth>
<maxWeakCount>152</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
@@ -954,7 +954,7 @@ int CascadeClassifierImpl::runAt( Ptr<FeatureEvaluator>& evaluator, Point pt, do
if( !evaluator->setWindow(pt) )
return -1;
- if( data.isStumpBased )
+ if( data.isStumpBased() )
{
if( data.featureType == FeatureEvaluator::HAAR )
return predictOrderedStump<HaarEvaluator>( *this, evaluator, weight );
@@ -1133,6 +1133,7 @@ bool CascadeClassifierImpl::detectSingleScale( InputArray _image, Size processin
bool CascadeClassifierImpl::ocl_detectSingleScale( InputArray _image, Size processingRectSize,
int yStep, double factor, Size sumSize0 )
{
+ const int VECTOR_SIZE = 4;
Ptr<HaarEvaluator> haar = featureEvaluator.dynamicCast<HaarEvaluator>();
if( haar.empty() )
return false;
@@ -1142,17 +1143,15 @@ bool CascadeClassifierImpl::ocl_detectSingleScale( InputArray _image, Size proce
if( cascadeKernel.empty() )
{
cascadeKernel.create("runHaarClassifierStump", ocl::objdetect::haarobjectdetect_oclsrc,
- format("-D MAX_FACES=%d", MAX_FACES));
+ format("-D VECTOR_SIZE=%d", VECTOR_SIZE));
if( cascadeKernel.empty() )
return false;
}
if( ustages.empty() )
{
copyVectorToUMat(data.stages, ustages);
- copyVectorToUMat(data.classifiers, uclassifiers);
- copyVectorToUMat(data.nodes, unodes);
- copyVectorToUMat(data.leaves, uleaves);
+ copyVectorToUMat(data.stumps, ustumps);
}
std::vector<UMat> bufs;
@@ -1162,7 +1161,7 @@ bool CascadeClassifierImpl::ocl_detectSingleScale( InputArray _image, Size proce
Rect normrect = haar->getNormRect();
//processingRectSize = Size(yStep, yStep);
- size_t globalsize[] = { processingRectSize.width/yStep, processingRectSize.height/yStep };
+ size_t globalsize[] = { (processingRectSize.width/yStep + VECTOR_SIZE-1)/VECTOR_SIZE, processingRectSize.height/yStep };
cascadeKernel.args(ocl::KernelArg::ReadOnlyNoSize(bufs[0]), // sum
ocl::KernelArg::ReadOnlyNoSize(bufs[1]), // sqsum
@@ -1171,14 +1170,12 @@ bool CascadeClassifierImpl::ocl_detectSingleScale( InputArray _image, Size proce
// cascade classifier
(int)data.stages.size(),
ocl::KernelArg::PtrReadOnly(ustages),
- ocl::KernelArg::PtrReadOnly(uclassifiers),
- ocl::KernelArg::PtrReadOnly(unodes),
- ocl::KernelArg::PtrReadOnly(uleaves),
+ ocl::KernelArg::PtrReadOnly(ustumps),
ocl::KernelArg::PtrWriteOnly(ufacepos), // positions
processingRectSize,
yStep, (float)factor,
- normrect, data.origWinSize);
+ normrect, data.origWinSize, MAX_FACES);
bool ok = cascadeKernel.run(2, globalsize, 0, true);
//CV_Assert(ok);
return ok;
@@ -1243,7 +1240,7 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( InputArray _image, std::
bool use_ocl = ocl::useOpenCL() &&
getFeatureType() == FeatureEvaluator::HAAR &&
!isOldFormatCascade() &&
- data.isStumpBased &&
+ data.isStumpBased() &&
maskGenerator.empty() &&
!outputRejectLevels &&
tryOpenCL;
@@ -1345,7 +1342,6 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( InputArray _image, std::
Mat facepos = ufacepos.getMat(ACCESS_READ);
const int* fptr = facepos.ptr<int>();
int i, nfaces = fptr[0];
- printf("nfaces = %d\n", nfaces);
for( i = 0; i < nfaces; i++ )
{
candidates.push_back(Rect(fptr[i*4+1], fptr[i*4+2], fptr[i*4+3], fptr[i*4+4]));
@@ -1428,6 +1424,12 @@ void CascadeClassifierImpl::detectMultiScale( InputArray _image, std::vector<Rec
}
}
+
+CascadeClassifierImpl::Data::Data()
+{
+ stageType = featureType = ncategories = maxNodesPerTree = 0;
+}
+
bool CascadeClassifierImpl::Data::read(const FileNode &root)
{
static const float THRESHOLD_EPS = 1e-5f;
@@ -1471,9 +1473,10 @@ bool CascadeClassifierImpl::Data::read(const FileNode &root)
stages.reserve(fn.size());
classifiers.clear();
nodes.clear();
+ stumps.clear();
FileNodeIterator it = fn.begin(), it_end = fn.end();
- isStumpBased = true;
+ maxNodesPerTree = 0;
for( int si = 0; it != it_end; si++, ++it )
{
@@ -1499,9 +1502,8 @@ bool CascadeClassifierImpl::Data::read(const FileNode &root)
DTree tree;
tree.nodeCount = (int)internalNodes.size()/nodeStep;
- if( tree.nodeCount > 1 )
- isStumpBased = false;
-
+ maxNodesPerTree = std::max(maxNodesPerTree, tree.nodeCount);
+
classifiers.push_back(tree);
nodes.reserve(nodes.size() + tree.nodeCount);
@@ -1536,6 +1538,24 @@ bool CascadeClassifierImpl::Data::read(const FileNode &root)
leaves.push_back((float)*internalNodesIter);
}
}
+
+ if( isStumpBased() )
+ {
+ int nodeOfs = 0, leafOfs = 0;
+ size_t nstages = stages.size();
+ for( size_t stageIdx = 0; stageIdx < nstages; stageIdx++ )
+ {
+ const Stage& stage = stages[stageIdx];
+
+ int ntrees = stage.ntrees;
+ for( int i = 0; i < ntrees; i++, nodeOfs++, leafOfs+= 2 )
+ {
+ const DTreeNode& node = nodes[nodeOfs];
+ stumps.push_back(Stump(node.featureIdx, node.threshold,
+ leaves[leafOfs], leaves[leafOfs+1]));
+ }
+ }
+ }
return true;
}
@@ -1546,9 +1566,7 @@ bool CascadeClassifierImpl::read_(const FileNode& root)
tryOpenCL = true;
cascadeKernel = ocl::Kernel();
ustages.release();
- uclassifiers.release();
- unodes.release();
- uleaves.release();
+ ustumps.release();
if( !data.read(root) )
return false;
Oops, something went wrong.

1 comment on commit b7553d4

@tomnasweezy

hello i am working on my graduation project which requires extracting the plate numbers as well but arabic letters and number i was wondering if you could help by providing any links how to do a similar xml file but with the Arabic plate recognition letters
thanks in advance

Please sign in to comment.