Skip to content

Commit

Permalink
Fix: update InputImageRotation parameter in example app for InputImag…
Browse files Browse the repository at this point in the history
…e using camera plugin
  • Loading branch information
fbernaly committed Jun 28, 2023
1 parent 6d7e82c commit 7b473d6
Show file tree
Hide file tree
Showing 27 changed files with 1,072 additions and 518 deletions.
5 changes: 0 additions & 5 deletions packages/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

import 'nlp_detector_views/entity_extraction_view.dart';
Expand All @@ -14,13 +13,9 @@ import 'vision_detector_views/pose_detector_view.dart';
import 'vision_detector_views/selfie_segmenter_view.dart';
import 'vision_detector_views/text_detector_view.dart';

List<CameraDescription> cameras = [];

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

cameras = await availableCameras();

runApp(MyApp());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:google_mlkit_barcode_scanning/google_mlkit_barcode_scanning.dart';

import 'camera_view.dart';
import 'detector_view.dart';
import 'painters/barcode_detector_painter.dart';

class BarcodeScannerView extends StatefulWidget {
Expand All @@ -15,6 +16,7 @@ class _BarcodeScannerViewState extends State<BarcodeScannerView> {
bool _isBusy = false;
CustomPaint? _customPaint;
String? _text;
var _cameraLensDirection = CameraLensDirection.back;

@override
void dispose() {
Expand All @@ -25,17 +27,17 @@ class _BarcodeScannerViewState extends State<BarcodeScannerView> {

@override
Widget build(BuildContext context) {
return CameraView(
return DetectorView(
title: 'Barcode Scanner',
customPaint: _customPaint,
text: _text,
onImage: (inputImage) {
processImage(inputImage);
},
onImage: _processImage,
initialCameraLensDirection: _cameraLensDirection,
onCameraLensDirectionChanged: (value) => _cameraLensDirection = value,
);
}

Future<void> processImage(InputImage inputImage) async {
Future<void> _processImage(InputImage inputImage) async {
if (!_canProcess) return;
if (_isBusy) return;
_isBusy = true;
Expand All @@ -46,7 +48,11 @@ class _BarcodeScannerViewState extends State<BarcodeScannerView> {
if (inputImage.metadata?.size != null &&
inputImage.metadata?.rotation != null) {
final painter = BarcodeDetectorPainter(
barcodes, inputImage.metadata!.size, inputImage.metadata!.rotation);
barcodes,
inputImage.metadata!.size,
inputImage.metadata!.rotation,
_cameraLensDirection,
);
_customPaint = CustomPaint(painter: painter);
} else {
String text = 'Barcodes found: ${barcodes.length}\n\n';
Expand Down
Loading

0 comments on commit 7b473d6

Please sign in to comment.