faceDetectionToRoi function
Converts a face detection bounding box to a square region of interest (ROI).
This function takes a face bounding box and generates a square ROI suitable for face mesh alignment. The process involves:
- Expanding the bounding box by
expandFraction(default 0.6 = 60% larger) - Finding the center of the expanded box
- Creating a square ROI centered on that point
The boundingBox parameter is the face bounding box in normalized coordinates (0.0 to 1.0).
The expandFraction controls how much to expand the bounding box before
computing the square ROI. Default is 0.6 (60% expansion).
Returns a square RectF in normalized coordinates centered on the face, with dimensions based on the larger of the expanded width or height.
This is typically used to prepare face regions for mesh landmark detection, which requires a square input with some padding around the face.
Implementation
RectF faceDetectionToRoi(RectF boundingBox, {double expandFraction = 0.6}) {
final RectF e = boundingBox.expand(expandFraction);
final double cx = (e.xmin + e.xmax) * 0.5;
final double cy = (e.ymin + e.ymax) * 0.5;
final double s = math.max(e.w, e.h) * 0.5;
return RectF(cx - s, cy - s, cx + s, cy + s);
}