face detection error face image in only android
Describe your issue. If applicable, add screenshots to help explain your problem.
processImage function error only android packge version google_mlkit_face_detection: ^0.11.1 google_mlkit_commons: 0.8.1
but packge version
google_mlkit_face_detection: ^0.11.0
google_mlkit_commons: 0.7.1
works fine without any problems.
Everything goes well regardless of the ios.
Steps to reproduce.
E/ImageError( 9584): Getting Image failed
E/ImageError( 9584): java.lang.IllegalArgumentException
D/Camera2CameraImpl( 9584): {Camera@253ad19[id=1]} Use case androidx.camera.core.ImageAnalysis-4940151d-7719-4cfd-92ba-a8973df00dcd49725171 INACTIVE
D/UseCaseAttachState( 9584): Active and attached use case: [androidx.camera.core.ImageCapture-2bdca64f-a070-4134-b383-ac7893b44085251716653, androidx.camera.core.Preview-1bc41ef1-bfb2-4253-b08b-9f9048b183f1235416022] for camera: 1
E/flutter ( 9584): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(InputImageConverterError, java.lang.IllegalArgumentException, null, null)
E/flutter ( 9584): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
E/flutter ( 9584): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
E/flutter ( 9584):
What is the expected result?
Face detection should be done.
Did you try our example app?
Yes
Is it reproducible in the example app?
Yes
Reproducible in which OS?
Android
Flutter/Dart Version?
Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.24.3, on macOS 15.0 24A335 darwin-arm64, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 16.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2024.1) [✓] VS Code (version 1.93.1) [✓] Connected device (4 available)
[✓] Network resources
• No issues found!
Plugin Version?
Android
google_mlkit_face_detection: ^0.11.0
google_mlkit_commons: 0.7.1
IOS google_mlkit_face_detection: ^0.11.1 google_mlkit_commons: 0.8.1
It occurs with my code too. I even updated the google_mlkit_face_detection version to 0.11.1, but still no luck
@fbernaly @bharat-biradar
is same at google_mlkit_barcode_scanning package too. is there any solution??
@jihuncha since when you faced this issue?
@bilalali1 today. I fixed downgrade version 0.11.0 and downgrade camera plugin version to 0.10.6 and it works fine.
Similar problem here:
I/flutter ( 8867): PlatformException(InputImageConverterError, java.lang.IllegalArgumentException, null, null)
I/flutter ( 8867): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
I/flutter ( 8867): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
I/flutter ( 8867):
But I'm using Text Recognition: camera: ^0.11.0+2 google_mlkit_text_recognition: ^0.13.1
Working Configuration:
google_mlkit_face_detection: 0.11.0
camera: 0.11.0+2
camera_android_camerax: 0.6.7+2
Problem:
The issue arises when using google_mlkit_face_detection: ^0.11.0 or google_mlkit_face_detection: 0.12.0 without explicitly specifying the version camera_android_camerax: 0.6.7+2. This happens because camera: 0.11.0+2 uses camera_android_camerax: 0.6.8+2 under the hood, which causes build errors.
Solution:
By explicitly setting camera_android_camerax: 0.6.7+2 and google_mlkit_face_detection: 0.11.0. Using this config it is still the new camera_android_camerax under the hood in the camera package.
Unfortunately, because of this issue:
https://issuetracker.google.com/issues/362452861
Downgrading isn't an option, as ML Kit pre 0.12.0 no longer works on iOS with the latest Firebase packages
So the solution by @pvlKryu isn't an option for us
Could anyone please help with resolving the issue of face detection not working on Android?
camera_android_camerax 0.6.10 and google_mlkit_text_recognition 0.13.0 works for me but google_mlkit_text_recognition 0.13.1 / 0.14.0 fails again
This works for me on Android:
flutter 3.24.4 camera 0.11.0+2 google_mlkit_commons-0.7.1 google_mlkit_barcode_scanning 0.11.1
I do receive the following Note:
google_mlkit_commons-0.7.1\android\src\main\java\com\google_mlkit_commons\InputImageConverter.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
When using the following: flutter 3.24.4 camera 0.11.0+2 google_mlkit_commons 0.8.1 google_mlkit_barcode_scanning 0.12.1
or
flutter 3.24.4 camera 0.11.0+2 google_mlkit_commons 0.9.0 google_mlkit_barcode_scanning 0.13.0
You will receive when the camera is turned on. You do see the camera preview, though. Using the camera_view.dart from the provided examples.
E/ImageError( 4621): Getting Image failed
E/ImageError( 4621): java.lang.IllegalArgumentException
I/flutter ( 4621): PlatformException(InputImageConverterError, java.lang.IllegalArgumentException, null, null)
The moment you move to google_mlkit_text_recognition to 0.14 and try ObjectDetector objectDetector.processImage(InputImage); doesn't work on Android device.
I tried with camera_android_camerax 0.6.10 also not working.
E/ImageError(17308): Getting Image failed
E/ImageError(17308): java.lang.IllegalArgumentException
E/flutter (17308): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(InputImageConverterError, java.lang.IllegalArgumentException, null, null)
E/flutter (17308): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
E/flutter (17308): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
E/flutter (17308):
This issue is stale because it has been open for 30 days with no activity.
The problem wasn’t solved yet
same error
This issue is stale because it has been open for 30 days with no activity.
The problem wasn’t solved yet
Face is not being detected in Android 14.
packages: camera: 0.11.0+2 google_mlkit_face_detection: 0.11.0 google_mlkit_commons: ^0.7.1 camera_android_camerax: 0.6.7+2
Also same for packages: camera: ^0.11.0+2 google_mlkit_face_detection: ^0.12.0 google_mlkit_commons: ^0.9.0
Use this InputImageFormat while converting camera frame to face detector input image, it is working for me but the faces are still returned empty:
Issue:
E/ImageError(17308): Getting Image failed E/ImageError(17308): java.lang.IllegalArgumentException E/flutter (17308): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(InputImageConverterError, java.lang.IllegalArgumentException, null, null) E/flutter (17308): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7) E/flutter (17308): https://github.com/flutter-ml/google_ml_kit_flutter/pull/1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18) E/flutter (17308): E/flutter (17308): https://github.com/flutter-ml/google_ml_kit_flutter/issues/2 ObjectDetector.processImage (package:google_mlkit_object_detection/src/object_detector.dart:21:20) E/flutter (17308): E/flutter (17308): https://github.com/flutter-ml/google_ml_kit_flutter/pull/3 _ObjectDetectionFeedState.doObjectDetectionOnFrame E/flutter (17308):
Fix: ` if(Platform.isIOS){ InputImageFormat imageFormat = InputImageFormat.bgra8888 } if(Platform.isAndroid){ InputImageFormat imageFormat = InputImageFormat.nv21; }
final inputImage = InputImage.fromBytes( bytes: bytes, metadata: InputImageMetadata( size: Size(frame.width.toDouble(), frame.height.toDouble()), rotation: rotation, // Adjust as needed format: imageFormat, bytesPerRow: frame.planes[0].bytesPerRow, ), );
final List faces = await faceDetector.processImage(inputImage); log('Faces detected: $faces'); `
This Works only in the following configuration.
google_mlkit_face_detection: 0.11.0
camera: 0.11.0+2
camera_android_camerax: 0.6.7+2
If I change google_mlkit_face_detection to any of 0.11.1 or 0.12.0 it will log the following error continuously in the console.
E/ImageError(24620): Getting Image failed
E/ImageError(24620): java.lang.IllegalArgumentException
E/ImageError(24620): Getting Image failed
E/ImageError(24620): java.lang.IllegalArgumentException
working with following:
Flutter Version: 3.27.2
dependencies:
camera: ^0.11.0+2
google_mlkit_face_detection: ^0.11.0
dependency_overrides:
camera_android_camerax: 0.6.7+2
google_mlkit_commons: ^0.7.1
Hello guys, This is my configured
google_mlkit_face_detection: ^0.12.0
google_mlkit_commons: ^0.9.0
google_mlkit_barcode_scanning: ^0.13.0
camera: ^0.11.0+2
I am not getting any error on android these are the latest versions.
why can't you guys use the latest version?
same Error
E/ImageError(27709): Getting Image failed
E/ImageError(27709): java.lang.IllegalArgumentException
I/flutter (27709): error: PlatformException(InputImageConverterError, java.lang.IllegalArgumentException, null, null)
I/flutter (27709): inputImage.metadata: Instance of 'InputImageMetadata'
configuration:
google_mlkit_face_detection: ^0.11.0
camera: ^0.11.0+2
camera_android_camerax: 0.6.7+2
google_mlkit_commons: ^0.7.1
the error persists even while working with the latest versions
problem solved for me it was very simple as i wan converting to NV21 format on android but when passing the format property to the InputImage.fromBytes(format:format)
this caused the problem as the format was InputImageFormat.yuv_420_888 and the soloution was to specify the format as N21 for android and pass the bytes after converting them from a YUV to 1 plane format NV21
I’m experiencing the same issue. Are there any updates?
@kareem-01
converting them from a YUV to 1 plane format NV21
Can you share the code snippet?
Hello guys, This is my configured
google_mlkit_face_detection: ^0.12.0 google_mlkit_commons: ^0.9.0 google_mlkit_barcode_scanning: ^0.13.0 camera: ^0.11.0+2I am not getting any error on android these are the latest versions.
why can't you guys use the latest version?
This configuration also didn't work
I have tried all the above package versions, and upgraded to latest flutter and nothing worked, so came to a qucik fix after identifying a loophole which the Gallery & Camera picks are working fine.
so for android, the only issue is InputImage.fromBytes, but I cannot wait so long for a proper solution and decided to give it a try for below opration and got succed! ✅
- Take an image of the live camera controller
- Convert it to
jpeg/pngie viewable file formats other than the live raw formatnv21, - Save the image under a permanent name to avoid too much cache to the local disc
- Get the file path and create InputImage.fromFilePath
- Now the face got detected as similar to gallery & camera
For iOS, this approach is not required. here is the sample code:
Modify your code where you listen to the image stream as below:
❌ _controller?.startImageStream(_processCameraImage) ✅ _controller?.startImageStream(convertToInputImage)
📔 Note:
The _processCameraImage is the default function where the default InputImage.fromBytes operation happens (see here),
but as no proper solution found, we are handovering the conversion process into convertToInputImage
⛳ bool isConverting = false;//helps to hold the process until one image is saved
📸 Function which takes a photo and saves it to disc
Future<void> convertToInputImage(CameraImage _) async {
if (isConverting) return;
setState(() => isConverting = true);
final XFile? takenPhoto = await _controller?.takePicture();
Uint8List? jpegBytes = await takenPhoto?.readAsBytes();
if (jpegBytes != null) {
jpegBytes = flipImageBytes(jpegBytes);
final Directory dir = await getTemporaryDirectory();
final String path = '${dir.path}/cameraFace.jpg';
final File file = File(path);
await file.writeAsBytes(jpegBytes);
final InputImage inputImage = InputImage.fromFilePath(path);
await widget.onImage(inputImage);
} else {
// printt('jpegBytes is null');
}
setState(() => isConverting = false);
}
🪞 To flip the given image if required!
import 'package:image/image.dart' as imglib;
static Uint8List flipImageBytes(Uint8List inputBytes) {
if (inputBytes == null) {
print('flipping failed so returing as it is');
return inputBytes;
} else {
print('flipping started');
final imglib.Image? decoded = imglib.decodeImage(inputBytes);
if (decoded == null) {
print('decoding failed so flipping not done');
return inputBytes;
} else {
print('flipping done');
final imglib.Image flipped = imglib.flip(decoded, direction: imglib.FlipDirection.horizontal);
final Uint8List flippedBytes = Uint8List.fromList(imglib.encodeJpg(flipped));
return flippedBytes;
}
}
}
You don't need to implement this approach, if you are really having no time constrains and can wait for the real fix 👍🏻
Hello @irajeshh,
I think this solution might be okay, but it could take more time if we want to handle a live stream for verification.