From 7f64f31f662edf718363831b4a3a77e6500610c5 Mon Sep 17 00:00:00 2001 From: catree Date: Sun, 17 Jul 2016 23:21:15 +0200 Subject: [PATCH] Fix NAryMatIterator code example. --- modules/core/include/opencv2/core/mat.hpp | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index a0560a197..ab2ba7973 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -3146,21 +3146,29 @@ The example below illustrates how you can compute a normalized and threshold 3D } minProb *= image.rows*image.cols; - Mat plane; - NAryMatIterator it(&hist, &plane, 1); + + // initialize iterator (the style is different from STL). + // after initialization the iterator will contain + // the number of slices or planes the iterator will go through. + // it simultaneously increments iterators for several matrices + // supplied as a null terminated list of pointers + const Mat* arrays[] = {&hist, 0}; + Mat planes[1]; + NAryMatIterator itNAry(arrays, planes, 1); double s = 0; // iterate through the matrix. on each iteration - // it.planes[*] (of type Mat) will be set to the current plane. - for(int p = 0; p < it.nplanes; p++, ++it) + // itNAry.planes[i] (of type Mat) will be set to the current plane + // of the i-th n-dim matrix passed to the iterator constructor. + for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) { - threshold(it.planes[0], it.planes[0], minProb, 0, THRESH_TOZERO); - s += sum(it.planes[0])[0]; + threshold(itNAry.planes[0], itNAry.planes[0], minProb, 0, THRESH_TOZERO); + s += sum(itNAry.planes[0])[0]; } s = 1./s; - it = NAryMatIterator(&hist, &plane, 1); - for(int p = 0; p < it.nplanes; p++, ++it) - it.planes[0] *= s; + itNAry = NAryMatIterator(arrays, planes, 1); + for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) + itNAry.planes[0] *= s; } @endcode */