Mat.from3DList constructor
Create a Mat from a 3D list
data
should be a 3D list of numbers with a shape of (rows, cols, channels).
type
specifies the Mat type.
Implementation
factory Mat.from3DList(Iterable<Iterable<Iterable<num>>> data, MatType type) {
final rows = data.length;
final cols = data.first.length;
final channels = data.first.first.length;
final flatData = <num>[];
cvAssert(rows > 0, "The input data must not be empty.");
cvAssert(
cols > 0 &&
channels > 0 &&
data.every(
(r) =>
r.length == cols &&
r.every((c) {
flatData.addAll(c);
return c.length == channels;
}),
),
"All rows must have the same number of columns.",
);
return Mat.fromList(rows, cols, type, flatData);
}