Skip to content

Instantly share code, notes, and snippets.

@ravindu9701
Last active February 5, 2021 09:46
Show Gist options
  • Save ravindu9701/79abf09de14b2afad037109b0cb72913 to your computer and use it in GitHub Desktop.
Save ravindu9701/79abf09de14b2afad037109b0cb72913 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
import 'package:tflite/tflite.dart';
import 'dart:math' as math;
import 'camera.dart';
import 'bndbox.dart';
import 'models.dart';
class HomePage extends StatefulWidget {
final List<CameraDescription> cameras;
HomePage(this.cameras);
@override
_HomePageState createState() => new _HomePageState();
}
class _HomePageState extends State<HomePage> {
List<dynamic> _recognitions;
int _imageHeight = 0;
int _imageWidth = 0;
String _model = "";
@override
void initState() {
super.initState();
}
loadModel() async {
String res;
res = await Tflite.loadModel(
model: "assets/ssd_mobilenet.tflite",
labels: "assets/ssd_mobilenet.txt");
print(res);
}
onSelect(model) {
setState(() {
_model = model;
});
loadModel();
}
setRecognitions(recognitions, imageHeight, imageWidth) {
setState(() {
_recognitions = recognitions;
_imageHeight = imageHeight;
_imageWidth = imageWidth;
});
}
@override
Widget build(BuildContext context) {
Size screen = MediaQuery.of(context).size;
return Scaffold(
body: _model == ""
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: const Text(ssd),
onPressed: () => onSelect(ssd),
),
],
),
)
: Stack(
children: [
Camera(
widget.cameras,
_model,
setRecognitions,
),
BndBox(
_recognitions == null ? [] : _recognitions,
math.max(_imageHeight, _imageWidth),
math.min(_imageHeight, _imageWidth),
screen.height,
screen.width,
_model),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment