transform.dart 994 B

123456789101112131415161718192021222324
  1. import 'dart:io';
  2. import 'dart:ui';
  3. import 'package:google_mlkit_object_detection/google_mlkit_object_detection.dart';
  4. double translateX(double x, InputImageRotation rotation, Size size, Size absoluteImageSize) {
  5. switch (rotation) {
  6. case InputImageRotation.rotation90deg:
  7. return x * size.width / (Platform.isIOS ? absoluteImageSize.width : absoluteImageSize.height);
  8. case InputImageRotation.rotation270deg:
  9. return size.width - x * size.width / (Platform.isIOS ? absoluteImageSize.width : absoluteImageSize.height);
  10. default:
  11. return x * size.width / absoluteImageSize.width;
  12. }
  13. }
  14. double translateY(double y, InputImageRotation rotation, Size size, Size absoluteImageSize) {
  15. switch (rotation) {
  16. case InputImageRotation.rotation90deg:
  17. case InputImageRotation.rotation270deg:
  18. return y * size.height / (Platform.isIOS ? absoluteImageSize.height : absoluteImageSize.width);
  19. default:
  20. return y * size.height / absoluteImageSize.height;
  21. }
  22. }