mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 07:13:02 +04:00
Added N-dim submat selection with vectors
Currently, to select a submatrix of a N-dimensional matrix, it requires two lines of code while only one line of code is required if using a 2D array. I added functionality to be able to select an N-dim submatrix using a vector list instead of a Range pointer. This allows initializer lists to be used for a one-line selection.
This commit is contained in:
@@ -512,6 +512,31 @@ UMat::UMat(const UMat& m, const Range* ranges)
|
||||
updateContinuityFlag(*this);
|
||||
}
|
||||
|
||||
UMat::UMat(const UMat& m, const std::vector<Range>& ranges)
|
||||
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows)
|
||||
{
|
||||
int i, d = m.dims;
|
||||
|
||||
CV_Assert((int)ranges.size() == d);
|
||||
for (i = 0; i < d; i++)
|
||||
{
|
||||
Range r = ranges[i];
|
||||
CV_Assert(r == Range::all() || (0 <= r.start && r.start < r.end && r.end <= m.size[i]));
|
||||
}
|
||||
*this = m;
|
||||
for (i = 0; i < d; i++)
|
||||
{
|
||||
Range r = ranges[i];
|
||||
if (r != Range::all() && r != Range(0, size.p[i]))
|
||||
{
|
||||
size.p[i] = r.end - r.start;
|
||||
offset += r.start*step.p[i];
|
||||
flags |= SUBMATRIX_FLAG;
|
||||
}
|
||||
}
|
||||
updateContinuityFlag(*this);
|
||||
}
|
||||
|
||||
UMat UMat::diag(int d) const
|
||||
{
|
||||
CV_Assert( dims <= 2 );
|
||||
|
||||
Reference in New Issue
Block a user