classCV_EXPORTS NAryMatIterator
{public://! the default constructorNAryMatIterator();//! the full constructor taking arbitrary number of n-dim matricesNAryMatIterator(const Mat** arrays, uchar** ptrs,int narrays=-1);//! the full constructor taking arbitrary number of n-dim matricesNAryMatIterator(const Mat** arrays, Mat* planes,int narrays=-1);//! the separate iterator initialization methodvoidinit(const Mat** arrays, Mat* planes, uchar** ptrs,int narrays=-1);//! proceeds to the next plane of every iterated matrix
NAryMatIterator&operator++();//! proceeds to the next plane of every iterated matrix (postfix increment operator)
NAryMatIterator operator++(int);//! the iterated arraysconst Mat** arrays;//! the current planes
Mat* planes;//! data pointers
uchar** ptrs;//! the number of arraysint narrays;//! the number of hyper-planes that the iterator steps through
size_t nplanes;//! the size of each segment (in elements)
size_t size;protected:int iterdepth;
size_t idx;};
6.1 按面进行多维数组相加
staticvoidtest(){constint n_mat_size =5;constint n_mat_sz[]={ n_mat_size,n_mat_size,n_mat_size };
cv::Mat n_mat(3, n_mat_sz, CV_32FC1);
cv::RNG rng;
rng.fill(n_mat, cv::RNG::UNIFORM,0.f,1.f);const cv::Mat* arrays[]={&n_mat,0};
cv::Mat my_planes[1];
cv::NAryMatIterator it(arrays, my_planes);float s =0.f;int n =0;for(int p =0; p < it.nplanes; p++,++it){
s += cv::sum(it.planes[0])[0];
n++;}}
6.2 使用N-ary将两个数组相加
staticvoidtest(){constint n_mat_size =5;constint n_mat_sz[]={ n_mat_size,n_mat_size,n_mat_size };
cv::Mat n_mat0(3, n_mat_sz, CV_32FC1);
cv::Mat n_mat1(3, n_mat_sz, CV_32FC1);
cv::RNG rng;
rng.fill(n_mat0, cv::RNG::UNIFORM,0.f,1.f);
rng.fill(n_mat1, cv::RNG::UNIFORM,0.f,1.f);const cv::Mat* arrays[]={&n_mat0,&n_mat1,0};
cv::Mat my_planes[2];
cv::NAryMatIterator it(arrays, my_planes);float s =0.f;//Total sum over all planes in both arraysint n =0;//Total number of planesfor(int p =0; p < it.nplanes; p++,++it){
s += cv::sum(it.planes[0])[0];
s += cv::sum(it.planes[1])[0];
n++;}}
七、通过块访问数组元素
classCV_EXPORTS Mat
{public:
Mat row(int y)const;//Mat m; m.row(i);
Mat col(int x)const;//m.col(j);
Mat rowRange(int startrow,int endrow)const;//m.rowRange(i0,i1);
Mat rowRange(const Range& r)const;//
Mat colRange(int startcol,int endcol)const;
Mat colRange(const Range& r)const;
Mat diag(int d=0)const;};