Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle potrait image? #41

Open
fadrial1 opened this issue May 7, 2024 · 0 comments
Open

How to handle potrait image? #41

fadrial1 opened this issue May 7, 2024 · 0 comments

Comments

@fadrial1
Copy link

fadrial1 commented May 7, 2024

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();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant