Skip to content

Instantly share code, notes, and snippets.

@BoHellgren
Created March 2, 2020 12:44
Show Gist options
  • Save BoHellgren/35bee04414c769449dc9587345f1d419 to your computer and use it in GitHub Desktop.
Save BoHellgren/35bee04414c769449dc9587345f1d419 to your computer and use it in GitHub Desktop.
_findDog MLKit version
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) {
List<VisionObject> _foundObjects =
await objectDetector.detectFromBinary(png);
if (_foundObjects.length > 0)
return _foundObjects[0].bounds;
else
return Rect.fromLTRB(50.0, 25.0, img.height - 50.0, img.width - 25.0);
} else
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment