Skip to content

Instantly share code, notes, and snippets.

@BoHellgren
Last active January 8, 2020 09:37
Show Gist options
  • Save BoHellgren/93f43d374526be4681e4fb200013ac9c to your computer and use it in GitHub Desktop.
Save BoHellgren/93f43d374526be4681e4fb200013ac9c to your computer and use it in GitHub Desktop.
_findDog
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,
threshold: 0.2,
);
List<String> possibleDog = ['dog', 'cat', 'bear', 'teddy bear', 'sheep'];
Map biggestRect;
double rectSize, rectMax = 0.0;
for (int i = 0; i < resultList.length; i++) {
if (possibleDog.contains(resultList[i]["detectedClass"])) {
Map aRect = resultList[i]["rect"];
rectSize = aRect["w"] * aRect["h"];
if (rectSize > rectMax) {
rectMax = rectSize;
biggestRect = aRect;
}
}
}
return biggestRect;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment