Created
March 2, 2020 12:44
-
-
Save BoHellgren/35bee04414c769449dc9587345f1d419 to your computer and use it in GitHub Desktop.
_findDog MLKit version
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) { | |
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