transform.dart 1.0 KB

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