1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-28 23:03:03 +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
@@ -583,6 +583,31 @@ Mat::Mat(const Mat& m, const Range* ranges)
updateContinuityFlag(*this);
}
Mat::Mat(const Mat& m, const std::vector<Range>& ranges)
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
datalimit(0), allocator(0), u(0), size(&rows)
{
int d = m.dims;
CV_Assert((int)ranges.size() == d);
for (int 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 (int 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;
data += r.start*step.p[i];
flags |= SUBMATRIX_FLAG;
}
}
updateContinuityFlag(*this);
}
static Mat cvMatNDToMat(const CvMatND* m, bool copyData)
{