Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlatformException(InputImageConverterError, java.lang.IllegalArgumentException, null, null) #713

Open
wantroba opened this issue Oct 31, 2024 · 13 comments
Labels
InputImage Issues related to InputImage

Comments

@wantroba
Copy link

Describe your issue. If applicable, add screenshots to help explain your problem.

The error occurs whenever I call the processImage(InputImage inputImage) function.

The last time it worked was May 27, 2024 with these plugin versions:
camera: ^0.11.0
google_mlkit_text_recognition: ^0.13.0

After I updated to these versions:
camera: ^0.11.0+2
google_mlkit_text_recognition: ^0.14.0

Then I tried to revert back to previous versions and the problem still persists.

Steps to reproduce.

The error occurs whenever I call the processImage(InputImage inputImage) function.

What is the expected result?

processImage(InputImage inputImage) function should work

Did you try our example app?

No

Is it reproducible in the example app?

No

Reproducible in which OS?

Android

Flutter/Dart Version?

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.4, on Microsoft Windows [versÆo 10.0.22631.4317], locale pt-BR)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Ferramentas de Build do Visual Studio 2019 16.11.29)
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.94.2)
[✓] Connected device (4 available)
[✓] Network resources

Plugin Version?

camera: ^0.11.0+2
google_mlkit_text_recognition: ^0.14.0

@wantroba
Copy link
Author

Could be related to #684

@simeonangelov94
Copy link

Same here, after updating to
camera: ^0.11.0+2
google_mlkit_text_recognition: ^0.14.0

Same dependencies. No issue running on Apple devices.

@cagrialta
Copy link

Related to #700 . You can use my solution as temporarily.

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Dec 11, 2024
@wantroba
Copy link
Author

Any update?

@github-actions github-actions bot removed the stale label Dec 18, 2024
@wantroba
Copy link
Author

Related to #700 . You can use my solution as temporarily.

Your solution did not work for me :(

@simeonangelov94
Copy link

Related to #700 . You can use my solution as temporarily.

Your solution did not work for me :(

update your controller to use yuv420, that was the issue for me. Use camera package 0.10.6 for android.

controller = CameraController(
  cameras.first,
  ResolutionPreset.high,
  imageFormatGroup: Platform.isAndroid
      ? ImageFormatGroup.yuv420
      : ImageFormatGroup.bgra8888,
);


try {
  await controller.initialize();
  if (!mounted) return;

  controller.startImageStream((image) {
    if (!isBusy) {
      isBusy = true;
      img = image;
      addImageTree();
      doObjectDetectionOnFrame();
    }
  });
} catch (e) {
  // Handle initialization error
  print('Camera initialization failed: $e');
}

doObjectDetectionOnFrame() async {
InputImage? frameImg;

frameImg = cameraImageToInputImage(
    img!, cameras[0], controller!.value.deviceOrientation);

// getInputImage();
if (frameImg != null) {
  List<DetectedObject> objects =
      await objectDetector.processImage(frameImg);
  // print("len= ${objects.length}");
  setState(() {
    _scanResults = objects;
  });
}
isBusy = false;

}

@RossHS
Copy link

RossHS commented Dec 21, 2024

Bump, I have the same problem. Rolled back for now.

@coder-arkkan
Copy link

coder-arkkan commented Dec 29, 2024

`
InputImage? _inputImageFromCameraImage(CameraImage cameraImage) {
if (_controller == null) return null;
final camera = _cameras[_cameraIndex];
final sensorOrientation = camera.sensorOrientation;
InputImageRotation? rotation;
if (Platform.isIOS) {
rotation = InputImageRotationValue.fromRawValue(sensorOrientation);
} else if (Platform.isAndroid) {
var rotationCompensation =
_orientations[_controller!.value.deviceOrientation];
if (rotationCompensation == null) return null;
if (camera.lensDirection == CameraLensDirection.front) {
rotationCompensation = (sensorOrientation + rotationCompensation) % 360;
} else {
rotationCompensation =
(sensorOrientation - rotationCompensation + 360) % 360;
}
rotation = InputImageRotationValue.fromRawValue(rotationCompensation);
}
if (rotation == null) return null;
const format = InputImageFormat.nv21;
final plane = cameraImage.planes.first;

final WriteBuffer allBytes = WriteBuffer();
for (final Plane plane in cameraImage.planes) {
  allBytes.putUint8List(plane.bytes);
}

return InputImage.fromBytes(
  bytes: allBytes.done().buffer.asUint8List(),
  metadata: InputImageMetadata(
    size: Size(cameraImage.width.toDouble(), cameraImage.height.toDouble()),
    rotation: rotation, // used only in Android
    format: format, // used only in iOS
    bytesPerRow: plane.bytesPerRow, // used only in iOS
  ),
);

}
`

@coder-arkkan
Copy link

`const format = InputImageFormat.nv21;
final plane = cameraImage.planes.first;

final WriteBuffer allBytes = WriteBuffer();
for (final Plane plane in cameraImage.planes) {
  allBytes.putUint8List(plane.bytes);
}

return InputImage.fromBytes(
  bytes: allBytes.done().buffer.asUint8List(),
  metadata: InputImageMetadata(
    size: Size(cameraImage.width.toDouble(), cameraImage.height.toDouble()),
    rotation: rotation, // used only in Android
    format: format, // used only in iOS
    bytesPerRow: plane.bytesPerRow, // used only in iOS
  ),
);`

@coder-arkkan
Copy link

Try this. Most important thing is

final WriteBuffer allBytes = WriteBuffer(); for (final Plane plane in cameraImage.planes) { allBytes.putUint8List(plane.bytes); }

@tiees288
Copy link

tiees288 commented Jan 2, 2025

Still has the same problem on facegoogle_mlkit_face_detection

google_mlkit_face_detection ^0.12
camera: ^0.11.0+2

@M-Farjad
Copy link

M-Farjad commented Jan 6, 2025

Use this InputImageFormat while converting camera frame to face detector input image, it is working for me but the faces are still returned empty:
`
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');
`

@fbernaly fbernaly added the InputImage Issues related to InputImage label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
InputImage Issues related to InputImage
Projects
None yet
Development

No branches or pull requests

8 participants