-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
List displayBoxesAround(Size screen, {required bool isPotrait}) {
if (yoloResults.isEmpty) return [];
// Calculate scaling factors based on image orientation
double factorX, factorY, imgRatio, newWidth, newHeight;
if (isPotrait) {
factorX = screen.height / (imageHeight);
imgRatio = imageWidth / imageHeight;
newWidth = imageWidth * factorX;
newHeight = newWidth / imgRatio;
factorY = newHeight / (imageHeight);
} else {
// Handle landscape image
factorX = screen.width / (imageWidth);
imgRatio = imageWidth / imageHeight;
newWidth = imageWidth * factorX;
newHeight = newWidth / imgRatio;
factorY = newHeight / (imageHeight);
}
// Calculate padding for centered positioning
double paddingX = (screen.width - factorX * imageWidth) / 2;
double paddingY = (screen.height - factorY * imageHeight) / 2;
Color colorPick = const Color.fromARGB(255, 50, 233, 30);
return yoloResults.map((result) {
return Positioned(
left: paddingX + result["box"][0] * factorX,
top: paddingY + result["box"][1] * factorY,
width: (result["box"][2] - result["box"][0]) * factorX,
height: (result["box"][3] - result["box"][1]) * factorY,
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10.0)),
border: Border.all(color: Colors.pink, width: 2.0),
),
child: Text(
"${result['tag']} ${(result['box'][4] * 100).toStringAsFixed(0)}%",
style: TextStyle(
background: Paint()..color = colorPick,
color: Colors.white,
fontSize: 18.0,
),
),
),
);
}).toList();
}
Metadata
Metadata
Assignees
Labels
No labels