-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.6Found to occur in 3.6Found to occur in 3.6has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginThe camera pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Description
Description
ImageStream returns old imageData when imageStream is started after stopImageStream call.
This is causing barcode scanner to find the same barcode twice even though user is not pointing the camera towards the barcode for the second time.
Minimal Code Example
// ignore_for_file: avoid_print
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
late List<CameraDescription> _cameras;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
_cameras = await availableCameras();
runApp(const CameraApp());
}
/// CameraApp is the Main Application.
class CameraApp extends StatefulWidget {
/// Default Constructor
const CameraApp({Key? key}) : super(key: key);
@override
State<CameraApp> createState() => _CameraAppState();
}
class _CameraAppState extends State<CameraApp> {
late CameraController controller;
void _processImageFromStream(CameraImage image) {
print(image.planes[0].bytes[0]);
}
@override
void initState() {
super.initState();
controller = CameraController(_cameras[0], ResolutionPreset.low, enableAudio: false);
controller.initialize().then((_) {
if (!mounted) {
return;
}
setState(() {});
}).catchError((Object e) {
if (e is CameraException) {
switch (e.code) {
case 'CameraAccessDenied':
print('User denied camera access.');
break;
default:
print('Handle other errors.');
break;
}
}
});
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!controller.value.isInitialized) {
return Container();
}
return MaterialApp(
home: Column(children: [
Expanded(child: CameraPreview(controller)),
GestureDetector(
onTap: () {
if (controller.value.isStreamingImages) {
print('Stopping image stream');
controller.stopImageStream();
} else {
print('Starting new image stream');
controller.startImageStream(_processImageFromStream);
}
},
child: Container(color: Colors.green, child: const Text('Start or stop image stream')))
]));
}
}
Affected Camera Plugin Version
camera: 0.10.0+4, also reproducible on older versions
Flutter Doctor Output
[✓] Flutter (Channel stable, 3.3.8, on macOS 13.0.1 22A400 darwin-arm, locale en-IS)
• Flutter version 3.3.8 on channel stable at /Users/a/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 52b3dc25f6 (2 weeks ago), 2022-11-09 12:09:26 +0800
• Engine revision 857bd6b74c
• Dart version 2.18.4
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at /Users/a/Library/Android/sdk
• Platform android-33, build-tools 32.1.0-rc1
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode-14.1.0.app/Contents/Developer
• Build 14B47b
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
[✓] VS Code (version 1.73.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.52.0
[✓] Connected device (3 available)
• SM S901B (mobile) • RFCT8032PHN • android-arm64 • Android 13 (API 33)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.0.1 22A400 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.110
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Steps To Reproduce
- Point the camera towards light object
- Start image stream
- Stop the image stream
- point camera towards dark object
- Start the image stream again
- Look at console output
Results
I/flutter (19192): Starting new image stream
I/flutter (19192): 152
I/flutter (19192): 134
I/flutter (19192): 132
I/flutter (19192): 137
I/flutter (19192): 146
I/flutter (19192): 146
I/flutter (19192): 141
I/flutter (19192): 144
I/flutter (19192): Stopping image stream
I/flutter (19192): Starting new image stream
I/flutter (19192): 142
I/flutter (19192): 5
I/flutter (19192): 2
I/flutter (19192): 2
I/flutter (19192): 5
I/flutter (19192): 3
I/flutter (19192): 4
I/flutter (19192): 3
I/flutter (19192): 2
I/flutter (19192): 4
I/flutter (19192): 3
I/flutter (19192): 5
I/flutter (19192): Stopping image stream
Expected Results
I/flutter (19192): Starting new image stream
I/flutter (19192): 152
I/flutter (19192): 134
I/flutter (19192): 132
I/flutter (19192): 137
I/flutter (19192): 146
I/flutter (19192): 146
I/flutter (19192): 141
I/flutter (19192): 144
I/flutter (19192): Stopping image stream
I/flutter (19192): Starting new image stream
I/flutter (19192): 5
I/flutter (19192): 2
I/flutter (19192): 2
I/flutter (19192): 5
I/flutter (19192): 3
I/flutter (19192): 4
I/flutter (19192): 3
I/flutter (19192): 2
I/flutter (19192): 4
I/flutter (19192): 3
I/flutter (19192): 5
I/flutter (19192): Stopping image stream
Device Information
S22(SM-S901B/DS) was used for example above - Android 13 (API 33) - Build number TP1A.220624.014.S901BXXU2BVKB
Reproducible on at least all Android phones I tested, Samsung S22, OnePlus 6, LG K40s, Samsung A12.
Have not been able to produce on IOS.
sveinn19, punkeroso and CodePlayAdmin
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.6Found to occur in 3.6Found to occur in 3.6has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginThe camera pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Type
Projects
Status
[PENDING] camera_android issues solved by camera_android_camerax