detectDocument static method

Quad? detectDocument(
  1. RgbaImage src
)

Detect the document in a full-resolution RGBA still.

Detection runs on a small working image, then the corners are refined against a ~1024px gray image, so the returned quad tracks the real paper border rather than the downscale grid.

Implementation

static Quad? detectDocument(RgbaImage src) {
  final input = calloc<Uint8>(src.bytes.length);
  final out = calloc<Float>(8);
  try {
    input.asTypedList(src.bytes.length).setAll(0, src.bytes);
    final found = _detectDocument(input, src.width, src.height, out);
    if (found == 0) return null;
    final c = out.asTypedList(8);
    return Quad(
      Offset(c[0], c[1]),
      Offset(c[2], c[3]),
      Offset(c[4], c[5]),
      Offset(c[6], c[7]),
    );
  } finally {
    calloc.free(input);
    calloc.free(out);
  }
}