analyzeFrame static method
One-call live-frame analysis: quad detection + luma + focus, with a
single downscale and a single buffer copy across the FFI boundary.
bytes is a tightly packed luma plane (isBgra=false) or a 4-byte-per-
pixel BGRA/RGBA buffer (isBgra=true), with stride bytes per row.
The three tuning knobs trade accuracy for time:
cannyPasses(1-2): a second Canny threshold pass rescues low-contrast documents the first misses.useHoughFallback: line-based detector for outlines that never close into a single contour. The most expensive stage.refineCorners: sub-pixel corner snapping.
Implementation
static FrameAnalysis analyzeFrame(
Uint8List bytes,
int width,
int height,
int stride, {
required bool isBgra,
int cannyPasses = 2,
bool useHoughFallback = true,
bool refineCorners = true,
}) {
final input = calloc<Uint8>(bytes.length);
final corners = calloc<Float>(8);
final luma = calloc<Float>(1);
final focus = calloc<Float>(1);
try {
input.asTypedList(bytes.length).setAll(0, bytes);
final found = _analyzeFrameEx(
input,
width,
height,
stride,
isBgra ? 1 : 0,
cannyPasses,
useHoughFallback ? 1 : 0,
refineCorners ? 1 : 0,
corners,
luma,
focus,
);
Quad? quad;
if (found != 0) {
final c = corners.asTypedList(8);
quad = Quad(
Offset(c[0], c[1]),
Offset(c[2], c[3]),
Offset(c[4], c[5]),
Offset(c[6], c[7]),
);
}
return FrameAnalysis(quad, luma.value, focus.value);
} finally {
calloc.free(input);
calloc.free(corners);
calloc.free(luma);
calloc.free(focus);
}
}