atPixel method

List<num> atPixel(
  1. int row,
  2. int col
)

Get pixel value via row, col, returns a view of native data

Note: No bound check under release mode

Implementation

List<num> atPixel(int row, int col) {
  assert(0 <= row && row < rows, "row must be less than $rows");
  assert(0 <= col && col < cols, "col must be less than $cols");

  switch (type.depth) {
    case MatType.CV_8U:
      return ptrAt<U8>(row, col).asTypedList(channels);
    case MatType.CV_8S:
      return ptrAt<I8>(row, col).asTypedList(channels);
    case MatType.CV_16U:
      return ptrAt<U16>(row, col).asTypedList(channels);
    case MatType.CV_16S:
      return ptrAt<I16>(row, col).asTypedList(channels);
    case MatType.CV_32S:
      return ptrAt<I32>(row, col).asTypedList(channels);
    case MatType.CV_32F:
      return ptrAt<F32>(row, col).asTypedList(channels);
    case MatType.CV_64F:
      return ptrAt<F64>(row, col).asTypedList(channels);
    // TODO: waiting for official impl
    case MatType.CV_16F:
      return Float16P(ptrAt<U16>(row, col)).asTypedList(channels);
    case _:
      throw UnsupportedError("Unsupported type: ${type.asString()}");
  }
}