@Namespace(value="cv") @NoOffset @Properties(inherit=opencv_core.class) public class NAryMatIterator extends Pointer
Use the class to implement unary, binary, and, generally, n-ary element-wise operations on
multi-dimensional arrays. Some of the arguments of an n-ary function may be continuous arrays, some
may be not. It is possible to use conventional MatIterator 's for each array but incrementing all of
the iterators after each small operations may be a big overhead. In this case consider using
NAryMatIterator to iterate through several matrices simultaneously as long as they have the same
geometry (dimensionality and all the dimension sizes are the same). On each iteration it.planes[0]
,
it.planes[1]
,... will be the slices of the corresponding matrices.
The example below illustrates how you can compute a normalized and threshold 3D color histogram:
void computeNormalizedColorHist(const Mat& image, Mat& hist, int N, double minProb)
{
const int histSize[] = {N, N, N};
// make sure that the histogram has a proper size and type
hist.create(3, histSize, CV_32F);
// and clear it
hist = Scalar(0);
// the loop below assumes that the image
// is a 8-bit 3-channel. check it.
CV_Assert(image.type() == CV_8UC3);
MatConstIterator_<Vec3b> it = image.begin<Vec3b>(),
it_end = image.end<Vec3b>();
for( ; it != it_end; ++it )
{
const Vec3b& pix = *it;
hist.at<float>(pix[0]*N/256, pix[1]*N/256, pix[2]*N/256) += 1.f;
}
minProb *= image.rows*image.cols;
// 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
// 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(itNAry.planes[0], itNAry.planes[0], minProb, 0, THRESH_TOZERO);
s += sum(itNAry.planes[0])[0];
}
s = 1./s;
itNAry = NAryMatIterator(arrays, planes, 1);
for(int p = 0; p < itNAry.nplanes; p++, ++itNAry)
itNAry.planes[0] *= s;
}
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
NAryMatIterator()
the default constructor
|
NAryMatIterator(long size)
Native array allocator.
|
NAryMatIterator(Mat arrays,
byte[] ptrs) |
NAryMatIterator(Mat arrays,
byte[] ptrs,
int narrays) |
NAryMatIterator(Mat arrays,
ByteBuffer ptrs) |
NAryMatIterator(Mat arrays,
ByteBuffer ptrs,
int narrays) |
NAryMatIterator(Mat arrays,
BytePointer ptrs) |
NAryMatIterator(Mat arrays,
BytePointer ptrs,
int narrays) |
NAryMatIterator(Mat arrays,
Mat planes) |
NAryMatIterator(Mat arrays,
Mat planes,
int narrays) |
NAryMatIterator(Pointer p)
Pointer cast constructor.
|
NAryMatIterator(PointerPointer arrays,
Mat planes,
int narrays)
the full constructor taking arbitrary number of n-dim matrices
|
NAryMatIterator(PointerPointer arrays,
PointerPointer ptrs,
int narrays)
the full constructor taking arbitrary number of n-dim matrices
|
Modifier and Type | Method and Description |
---|---|
PointerPointer |
arrays() |
Mat |
arrays(int i)
the iterated arrays
|
NAryMatIterator |
arrays(int i,
Mat setter) |
NAryMatIterator |
increment()
proceeds to the next plane of every iterated matrix
|
NAryMatIterator |
increment(int arg0)
proceeds to the next plane of every iterated matrix (postfix increment operator)
|
void |
init(Mat arrays,
Mat planes,
byte[] ptrs) |
void |
init(Mat arrays,
Mat planes,
byte[] ptrs,
int narrays) |
void |
init(Mat arrays,
Mat planes,
ByteBuffer ptrs) |
void |
init(Mat arrays,
Mat planes,
ByteBuffer ptrs,
int narrays) |
void |
init(Mat arrays,
Mat planes,
BytePointer ptrs) |
void |
init(Mat arrays,
Mat planes,
BytePointer ptrs,
int narrays) |
void |
init(PointerPointer arrays,
Mat planes,
PointerPointer ptrs,
int narrays)
the separate iterator initialization method
|
int |
narrays()
the number of arrays
|
NAryMatIterator |
narrays(int setter) |
long |
nplanes()
the number of hyper-planes that the iterator steps through
|
NAryMatIterator |
nplanes(long setter) |
Mat |
planes()
the current planes
|
NAryMatIterator |
planes(Mat setter) |
NAryMatIterator |
position(long position) |
PointerPointer |
ptrs() |
BytePointer |
ptrs(int i)
data pointers
|
NAryMatIterator |
ptrs(int i,
BytePointer setter) |
NAryMatIterator |
ptrs(PointerPointer setter) |
long |
size()
the size of each segment (in elements)
|
NAryMatIterator |
size(long setter) |
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, hashCode, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, parseBytes, physicalBytes, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, toString, totalBytes, totalPhysicalBytes, withDeallocator, zero
public NAryMatIterator(Pointer p)
Pointer.Pointer(Pointer)
.public NAryMatIterator(long size)
Pointer.position(long)
.public NAryMatIterator()
public NAryMatIterator(@Cast(value="const cv::Mat**") PointerPointer arrays, @Cast(value="uchar**") PointerPointer ptrs, int narrays)
public NAryMatIterator(@Const @ByPtrPtr Mat arrays, @Cast(value="uchar**") @ByPtrPtr BytePointer ptrs)
public NAryMatIterator(@Const @ByPtrPtr Mat arrays, @Cast(value="uchar**") @ByPtrPtr BytePointer ptrs, int narrays)
public NAryMatIterator(@Const @ByPtrPtr Mat arrays, @Cast(value="uchar**") @ByPtrPtr ByteBuffer ptrs, int narrays)
public NAryMatIterator(@Const @ByPtrPtr Mat arrays, @Cast(value="uchar**") @ByPtrPtr ByteBuffer ptrs)
public NAryMatIterator(@Const @ByPtrPtr Mat arrays, @Cast(value="uchar**") @ByPtrPtr byte[] ptrs, int narrays)
public NAryMatIterator(@Const @ByPtrPtr Mat arrays, @Cast(value="uchar**") @ByPtrPtr byte[] ptrs)
public NAryMatIterator(@Cast(value="const cv::Mat**") PointerPointer arrays, Mat planes, int narrays)
public NAryMatIterator position(long position)
public void init(@Cast(value="const cv::Mat**") PointerPointer arrays, Mat planes, @Cast(value="uchar**") PointerPointer ptrs, int narrays)
public void init(@Const @ByPtrPtr Mat arrays, Mat planes, @Cast(value="uchar**") @ByPtrPtr BytePointer ptrs)
public void init(@Const @ByPtrPtr Mat arrays, Mat planes, @Cast(value="uchar**") @ByPtrPtr BytePointer ptrs, int narrays)
public void init(@Const @ByPtrPtr Mat arrays, Mat planes, @Cast(value="uchar**") @ByPtrPtr ByteBuffer ptrs, int narrays)
public void init(@Const @ByPtrPtr Mat arrays, Mat planes, @Cast(value="uchar**") @ByPtrPtr ByteBuffer ptrs)
public void init(@Const @ByPtrPtr Mat arrays, Mat planes, @Cast(value="uchar**") @ByPtrPtr byte[] ptrs, int narrays)
public void init(@Const @ByPtrPtr Mat arrays, Mat planes, @Cast(value="uchar**") @ByPtrPtr byte[] ptrs)
@ByRef @Name(value="operator ++") public NAryMatIterator increment()
@ByVal @Name(value="operator ++") public NAryMatIterator increment(int arg0)
public NAryMatIterator arrays(int i, Mat setter)
@MemberGetter @Cast(value="const cv::Mat**") public PointerPointer arrays()
public Mat planes()
public NAryMatIterator planes(Mat setter)
@Cast(value="uchar*") public BytePointer ptrs(int i)
public NAryMatIterator ptrs(int i, BytePointer setter)
@Cast(value="uchar**") public PointerPointer ptrs()
public NAryMatIterator ptrs(PointerPointer setter)
public int narrays()
public NAryMatIterator narrays(int setter)
@Cast(value="size_t") public long nplanes()
public NAryMatIterator nplanes(long setter)
public NAryMatIterator size(long setter)
Copyright © 2020. All rights reserved.