Commit 5689a9bd authored by Dasun Madushanka's avatar Dasun Madushanka

Update main.dart

parent 8fe5de91
//import main packeges
//image picker package for take a picture from gallery and tflite package to detect the image and read the assest file
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:tflite/tflite.dart'; import 'package:tflite/tflite.dart';
//to run hotstart
void main() => runApp(MaterialApp( void main() => runApp(MaterialApp(
home: MyApp(), home: MyApp(),
)); ));
...@@ -13,6 +17,7 @@ class MyApp extends StatefulWidget { ...@@ -13,6 +17,7 @@ class MyApp extends StatefulWidget {
} }
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
//variables
List _outputs; List _outputs;
File _image; File _image;
bool _loading = false; bool _loading = false;
...@@ -70,6 +75,8 @@ class _MyAppState extends State<MyApp> { ...@@ -70,6 +75,8 @@ class _MyAppState extends State<MyApp> {
); );
} }
//function for image picker
pickImage() async { pickImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery); var image = await ImagePicker.pickImage(source: ImageSource.gallery);
if (image == null) return null; if (image == null) return null;
...@@ -80,6 +87,7 @@ class _MyAppState extends State<MyApp> { ...@@ -80,6 +87,7 @@ class _MyAppState extends State<MyApp> {
classifyImage(image); classifyImage(image);
} }
//detect the image and compare the image with the model
classifyImage(File image) async { classifyImage(File image) async {
var output = await Tflite.runModelOnImage( var output = await Tflite.runModelOnImage(
path: image.path, path: image.path,
...@@ -93,14 +101,14 @@ class _MyAppState extends State<MyApp> { ...@@ -93,14 +101,14 @@ class _MyAppState extends State<MyApp> {
_outputs = output; _outputs = output;
}); });
} }
//load the model from assest folder.
loadModel() async { loadModel() async {
await Tflite.loadModel( await Tflite.loadModel(
model: "assets/model_unquant.tflite", model: "assets/model_unquant.tflite",
labels: "assets/labels.txt", labels: "assets/labels.txt",
); );
} }
//dispose the model menu
@override @override
void dispose() { void dispose() {
Tflite.close(); Tflite.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment