detectionSize function
Size
detectionSize({
- required int width,
- required int height,
- required CameraFrameRotation? rotation,
- required int maxDim,
Compute the final detection-image size used by overlay painters to map detector coordinates back onto the widget coord space.
Deterministic from the same inputs the detection isolate receives: the
pre-rotation width / height, the optional rotation (swaps dims when
90/270), and an optional maxDim downscale (preserves aspect ratio).
Returns the post-rotation, post-downscale size in pixels. Pass this as the source size of your overlay painter's coordinate mapping.
Implementation
Size detectionSize({
required int width,
required int height,
required CameraFrameRotation? rotation,
required int maxDim,
}) {
int w = width;
int h = height;
if (rotation == CameraFrameRotation.cw90 ||
rotation == CameraFrameRotation.cw270) {
final int t = w;
w = h;
h = t;
}
if (w > maxDim || h > maxDim) {
final double scale = maxDim / (w > h ? w : h);
w = (w * scale).toInt();
h = (h * scale).toInt();
}
return Size(w.toDouble(), h.toDouble());
}