Skip to content

Instantly share code, notes, and snippets.

@ashishrawat2911
Last active January 29, 2020 10:41
Show Gist options
  • Save ashishrawat2911/b721a8e2312644767ac64be92e2f0796 to your computer and use it in GitHub Desktop.
Save ashishrawat2911/b721a8e2312644767ac64be92e2f0796 to your computer and use it in GitHub Desktop.
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