Mat.fromVec constructor

Mat.fromVec(
  1. Vec<Struct, dynamic> vec, {
  2. int? rows,
  3. int? cols,
  4. MatType? type,
})

Create Mat from a vector Vec

vec can be an instance of VecPoint, VecPoint2f, VecPoint3f, VecPoint3i, VecU8, VecI8, VecU16, VecI16, VecI32, VecF32, VecF64, VecF16

data will be copied, if vec is large, remember to dispose it.

Implementation

factory Mat.fromVec(Vec vec, {int? rows, int? cols, MatType? type}) {
  final p = calloc<cvg.Mat>();
  switch (vec) {
    case VecPoint():
      cvRun(() => cffi.Mat_NewFromVecPoint(vec.ref, p));
    case VecPoint2f():
      cvRun(() => cffi.Mat_NewFromVecPoint2f(vec.ref, p));
    case VecPoint3f():
      cvRun(() => cffi.Mat_NewFromVecPoint3f(vec.ref, p));
    case VecPoint3i():
      cvRun(() => cffi.Mat_NewFromVecPoint3i(vec.ref, p));
    case VecU8() when rows != null && cols != null && type != null:
    case VecI8() when rows != null && cols != null && type != null:
    case VecU16() when rows != null && cols != null && type != null:
    case VecI16() when rows != null && cols != null && type != null:
    case VecI32() when rows != null && cols != null && type != null:
    case VecF32() when rows != null && cols != null && type != null:
    case VecF64() when rows != null && cols != null && type != null:
    case VecF16() when rows != null && cols != null && type != null:
      cvRun(() => cffi.Mat_NewFromBytes(rows, cols, type.value, vec.asVoid(), p));
    default:
      throw UnsupportedError("Unsupported Vec type ${vec.runtimeType}");
  }
  return Mat._(p);
}