Skip to content

Commit

Permalink
feat(WIP): limited web support camera
Browse files Browse the repository at this point in the history
  • Loading branch information
PiTrem committed Jul 17, 2024
1 parent 817082d commit e632b2c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/components/ocr_camera.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -31,10 +32,13 @@ class _OcrCameraState extends State<OcrCamera> {
@override
void initState() {
super.initState();

_cameraIndex =
// initialize the cameraIndex unless it's a web platform
if (!kIsWeb) {
_cameraIndex =
cameras.indexWhere((camera) => camera.lensDirection == widget.initialLensDirection);
}
_startLiveFeed();

}

@override
Expand All @@ -53,6 +57,8 @@ class _OcrCameraState extends State<OcrCamera> {

Future _startLiveFeed() async {
final camera = cameras[_cameraIndex];
// inspect the camera
print('Camera: $camera');
_controller = CameraController(
camera,
ResolutionPreset.low,
Expand All @@ -61,7 +67,10 @@ class _OcrCameraState extends State<OcrCamera> {
_controller?.initialize().then((_) async {
if (!mounted) return;

await _controller?.lockCaptureOrientation(DeviceOrientation.portraitUp);
// if web platform (kIsWeb) then do not set the orientation
if (!kIsWeb) {
await _controller?.lockCaptureOrientation(DeviceOrientation.portraitUp);
}

_controller?.startImageStream(_processCameraImage);
setState(() {});
Expand All @@ -86,8 +95,8 @@ class _OcrCameraState extends State<OcrCamera> {
final Size imageSize = Size(image.width.toDouble(), image.height.toDouble());

final camera = cameras[_cameraIndex];
final imageRotation = InputImageRotationValue.fromRawValue(camera.sensorOrientation) ??
InputImageRotation.rotation0deg;

final imageRotation = InputImageRotationValue.fromRawValue(camera.sensorOrientation) ?? InputImageRotation.rotation0deg;

final inputImageFormat =
InputImageFormatValue.fromRawValue(image.format.raw) ?? InputImageFormat.nv21;
Expand Down

0 comments on commit e632b2c

Please sign in to comment.