Skip to content

How to handle potrait image? #41

@fadrial1

Description

@fadrial1

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions