Mat.from2DList constructor

Mat.from2DList(
  1. Iterable<Iterable<num>> data,
  2. MatType type
)

Create a Mat from a 2D list

data should be a 2D list of numbers with a shape of (rows, cols). type specifies the Mat type.

Implementation

factory Mat.from2DList(Iterable<Iterable<num>> data, MatType type) {
  final rows = data.length;
  final cols = data.first.length;
  final flatData = <num>[];
  cvAssert(rows > 0, "The input data must not be empty.");
  cvAssert(
    cols > 0 &&
        data.every((r) {
          flatData.addAll(r);
          return r.length == cols;
        }),
    "All rows must have the same number of columns.",
  );
  return Mat.fromList(rows, cols, type, flatData);
}