12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import 'dart:io';
- import 'package:image/image.dart' as img;
- import 'package:flutter/services.dart';
- import 'package:path_provider/path_provider.dart';
- class NativeVisionHelper {
- static Future<String> getModelPath(String modelName) async {
- final tempDir = await getTemporaryDirectory();
- final modelCachePath = "${tempDir.path}/$modelName";
- final file = File(modelCachePath);
- final exists = await file.exists();
- if (!exists) {
- final modelData =
- await rootBundle.load("packages/native_vision/assets/$modelName");
- final buffer = modelData.buffer;
- final result = await file.writeAsBytes(
- buffer.asUint8List(modelData.offsetInBytes, modelData.lengthInBytes));
- }
- return file.path;
- }
- // static Future<File?> fixExifRotation(String imagePath) async {
- // final originalFile = File(imagePath);
- // List<int> imageBytes = await originalFile.readAsBytes();
- // final originalImage = img.decodeImage(imageBytes);
- // if (originalImage == null) return null;
- // final height = originalImage.height;
- // final width = originalImage.width;
- // // Let's check for the image size
- // if (height >= width) {
- // // I'm interested in portrait photos so
- // // I'll just return here
- // return originalFile;
- // }
- // // We'll use the exif package to read exif data
- // // This is map of several exif properties
- // // Let's check 'Image Orientation'
- // final exifData = await readExifFromBytes(imageBytes);
- // img.Image fixedImage;
- // final imgOrientation = exifData['Image Orientation'];
- // // rotate
- // if (imgOrientation != null &&
- // imgOrientation.printable.contains('Horizontal')) {
- // fixedImage = img.copyRotate(originalImage, 90);
- // } else if (imgOrientation != null &&
- // imgOrientation.printable.contains('180')) {
- // fixedImage = img.copyRotate(originalImage, -90);
- // } else {
- // fixedImage = img.copyRotate(originalImage, 0);
- // }
- // // Here you can select whether you'd like to save it as png
- // // or jpg with some compression
- // // I choose jpg with 100% quality
- // final fixedFile =
- // await originalFile.writeAsBytes(img.encodeJpg(fixedImage));
- // return fixedFile;
- // }
- }
|