Last active
January 29, 2020 10:41
-
-
Save ashishrawat2911/b721a8e2312644767ac64be92e2f0796 to your computer and use it in GitHub Desktop.
This file contains 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
bool _isDetecting = false; | |
VisionText _textScanResults; | |
CameraLensDirection _direction = CameraLensDirection.back; | |
CameraController _camera; | |
final TextRecognizer _textRecognizer = | |
FirebaseVision.instance.textRecognizer(); | |
@override | |
void initState() { | |
super.initState(); | |
_initializeCamera(); | |
} | |
void _initializeCamera() async { | |
final CameraDescription description = | |
await ScannerUtils.getCamera(_direction); | |
_camera = CameraController( | |
description, | |
ResolutionPreset.high, | |
); | |
await _camera.initialize(); | |
_camera.startImageStream((CameraImage image) { | |
if (_isDetecting) return; | |
setState(() { | |
_isDetecting = true; | |
}); | |
ScannerUtils.detect( | |
image: image, | |
detectInImage: _getDetectionMethod(), | |
imageRotation: description.sensorOrientation, | |
).then( | |
(results) { | |
setState(() { | |
if (results != null) { | |
setState(() { | |
_textScanResults = results; | |
}); | |
} | |
}); | |
}, | |
).whenComplete(() => _isDetecting = false); | |
}); | |
} | |
Future<VisionText> Function(FirebaseVisionImage image) _getDetectionMethod() { | |
return _textRecognizer.processImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment