1
0
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:
Addison Elliott
2016-12-15 09:16:40 -06:00
parent c038d1be60
commit eb04b2bfa9
5 changed files with 118 additions and 0 deletions
+25
View File
@@ -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 );