This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<String> _classifyDog(imglib.Image img) async { | |
| Uint8List png = imglib.encodePng(img); | |
| List<VisionLabel> _cloudLabels = | |
| await labelDetector.detectFromBinary(png, true); | |
| for (int i = 0; i < _cloudLabels.length; i++) { | |
| String foundLabel = _cloudLabels[i].label; | |
| print(foundLabel); | |
| if (isBreed(foundLabel)) { | |
| String conf = (_cloudLabels[i].confidence * 100).toStringAsFixed(0); | |
| print(foundLabel + ' ' + conf); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<Rect> _findDog(CameraImage image) async { | |
| imglib.Image img = _convertCameraImage(image); | |
| Uint8List png = imglib.encodePng(img); | |
| List<VisionLabel> _onDeviceLabels = | |
| await labelDetector.detectFromBinary(png, false); | |
| bool foundDog = false; | |
| for (int i = 0; i < _onDeviceLabels.length; i++) { | |
| if (_onDeviceLabels[i].label == "Dog") foundDog = true; | |
| } | |
| if (foundDog) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package se.ndssoft.mini_ml; | |
| import android.graphics.Bitmap; | |
| import android.graphics.BitmapFactory; | |
| import android.graphics.Matrix; | |
| import androidx.annotation.NonNull; | |
| import com.google.android.gms.tasks.OnFailureListener; | |
| import com.google.android.gms.tasks.OnSuccessListener; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:async'; | |
| import 'dart:typed_data'; | |
| import 'dart:ui'; | |
| import 'package:flutter/services.dart'; | |
| class MiniMl { | |
| static const MethodChannel _channel = | |
| const MethodChannel('plugins.flutter.io/mini_ml'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:flutter/services.dart'; | |
| import 'package:camera/camera.dart'; | |
| import 'package:soundpool/soundpool.dart'; | |
| import 'dart:ui' as ui; | |
| import 'dart:typed_data'; | |
| import 'package:image/image.dart' as imglib; | |
| import 'package:flutter/foundation.dart'; | |
| import 'package:tflite/tflite.dart'; | |
| import 'breedinfo.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:webview_flutter/webview_flutter.dart'; | |
| class BreedInfo extends StatelessWidget { | |
| final String breed; | |
| BreedInfo({Key key, @required this.breed}); | |
| @override | |
| Widget build(BuildContext context) { | |
| String url = 'https://en.wikipedia.org/wiki/' + breed; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<String> _classifyDog(imglib.Image croppedImage) async { | |
| while (_tfliteBusy) await Future.delayed(Duration(milliseconds: 100)); | |
| _tfliteBusy = true; | |
| Uint8List croppedPng = imglib.encodePng(croppedImage); | |
| try { | |
| File(_tempPath).deleteSync(); | |
| } catch (e) { | |
| print(e); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RectPainter extends CustomPainter { | |
| Map rect; | |
| RectPainter(this.rect); | |
| @override | |
| void paint(Canvas canvas, Size size) { | |
| if (rect != null) { | |
| final paint = Paint(); | |
| paint.color = Colors.yellow; | |
| paint.style = PaintingStyle.stroke; | |
| paint.strokeWidth = 2.0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<Map> _findDog(CameraImage image) async { | |
| List resultList = await Tflite.detectObjectOnFrame( | |
| bytesList: image.planes.map((plane) { | |
| return plane.bytes; | |
| }).toList(), | |
| model: "SSDMobileNet", | |
| imageHeight: image.height, | |
| imageWidth: image.width, | |
| imageMean: 127.5, | |
| imageStd: 127.5, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static imglib.Image _convertCameraImage(CameraImage image) { | |
| int width = image.width; | |
| int height = image.height; | |
| // imglib -> Image package from https://pub.dartlang.org/packages/image | |
| var img = imglib.Image(width, height); // Create Image buffer | |
| const int hexFF = 0xFF000000; | |
| final int uvyButtonStride = image.planes[1].bytesPerRow; | |
| final int uvPixelStride = image.planes[1].bytesPerPixel; | |
| for (int x = 0; x < width; x++) { | |
| for (int y = 0; y < height; y++) { |