Upgrade camera image packages#2
Conversation
…lement abstract member public abstract fun onRequestPermissionsResult(p0: Int, p1: Array<(out) String!>, p2: IntArray): Boolean defined in io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListene
- Update camera package to version 0.10.5 - Update image package to version 4.0.17 -Upgrade ffi package to version 2.0.1
… image has 3 channels
|
Hello, there. Thanks for your commitment. It is a fantastic work. But I met some problems after trying to pub add your tflite_helper. My previous tflite_helper is 0.3.1, and yours is 0.3.0(It is ok). The problem is after I switch the camera to 0.10.5, my tflite_flutter^0.9.0 will be forced to 0.9.5. But 0.9.5 has a TensorflowSwift problem, which means it cannot be used currently. I checked I could only make it back to 0.9.0 until I switched the camera to 0.9.8+1. Is there any modification I can do for my tflite_helper? Such as changing the code to the one you committed? I really hope to install camera^0.10.5 works because it solved a problem of using nv21 format in mlkit for android devices. Thank you so much. |
Update status. The tflite_flutter was upgraded to 0.10.0 already. But your commit looks like you need it to be 0.9.0. Is this conflict can be solved? |
|
Hello, Thank you for your kind words regarding my work, and for bringing this compatibility issue to my attention. I, too, have identified the issues with TensorflowSwift in tflite_flutter 0.9.5. In my own project, I've been using tflite_flutter at 0.90 and camera at 0.10.5, by downgrading the ffi of tflite_flutter_helper to 1.0.0. Here is the branch where I downgraded ffi to 1.0.0: https://github.com/pnyompen/tflite_flutter_helper/commits/downgrade-ffi You can use this by adding the following changes to your pubspec.yaml: tflite_flutter_helper:
git:
url: https://github.com/pnyompen/tflite_flutter_helper.git
ref: d058bac556019546ff308c3df63ded02ed760ee2It seems tflite_flutter 0.10.0 was released just recently, but I haven't had a chance to review the changes yet. As this is my first time contributing to an open-source project, I would greatly appreciate if you could modify my code and submit another pull request. Also, I have the impression that this repository is not being maintained anymore, so I'm not sure whether it is appropriate to send a pull request to it. If you have any advice on this, it would be very welcome. Thanks again for your feedback and please do not hesitate to contact me if you have further questions. Best, |
Thank you for your replying. Actually, I am a newbie to Flutter, don't understand the mechanism of Flutter and its plugin well. So hard for me to help you to modify the code and send a pull request. Below is the message I got when I do Running "flutter pub get" in testdemo... Looks like Google is preparing a new package to replace the tflite_helper, but it is not done yet. |
|
Hello, Thank you for reaching out and explaining the issue you're encountering. I've checked the code for tflite_flutter 0.10.0 and it seems there have been significant changes. Because of these alterations, it's challenging to immediately modify the tflite_flutter_helper. I would recommend either waiting for Google to release a new version of tflite_flutter_helper or considering using tflite_flutter 0.9.0 in the meantime. Thank you for your understanding and patience with this. Please don't hesitate to contact me if you have any other questions or concerns. Best regards, |
Thank you so much. I want to stay at tflite_flutter^0.9.0 at this moment. But the camera package version is limited to 0.9.8, and I need the latest 0.10.5 to be installed because it fixed a bug for android camera. I tried the new git link you mentioned above. Looks like after the image update from 3.1 to 4.0.17, some of my functions that convert cameraImage to image.image does not work any more. /// Converts a [CameraImage] in BGRA888 format to [imageLib.Image] in RGB format
static imageLib.Image convertBGRA8888ToImage(CameraImage cameraImage) {
// image ^4.0.17 error here
imageLib.Image img = imageLib.Image.fromBytes(cameraImage.planes[0].width!,
cameraImage.planes[0].height!, bytes: cameraImage.planes[0].bytes,
format: imageLib.Format.bgra);
return img;
}
/// Converts a [CameraImage] in YUV420 format to [imageLib.Image] in RGB format
static imageLib.Image convertYUV420ToImage(CameraImage cameraImage) {
final int width = cameraImage.width;
final int height = cameraImage.height;
final int uvRowStride = cameraImage.planes[1].bytesPerRow;
final int? uvPixelStride = cameraImage.planes[1].bytesPerPixel;
// image ^4.0.17 error here, I add parameters
final image = imageLib.Image(width: width, height: height);
for (int w = 0; w < width; w++) {
for (int h = 0; h < height; h++) {
final int uvIndex =
uvPixelStride! * (w / 2).floor() + uvRowStride * (h / 2).floor();
final int index = h * width + w;
final y = cameraImage.planes[0].bytes[index];
final u = cameraImage.planes[1].bytes[uvIndex];
final v = cameraImage.planes[2].bytes[uvIndex];
image.data[index] = ImageUtils.yuv2rgb(y, u, v);
}
}
return image;
}
/// Convert a single YUV pixel to RGB
static int yuv2rgb(int y, int u, int v) {
// Convert yuv pixel to rgb
int r = (y + v * 1436 / 1024 - 179).round();
int g = (y - u * 46549 / 131072 + 44 - v * 93604 / 131072 + 91).round();
int b = (y + u * 1814 / 1024 - 227).round();
// Clipping RGB values to be inside boundaries [ 0 , 255 ]
r = r.clamp(0, 255);
g = g.clamp(0, 255);
b = b.clamp(0, 255);
return 0xff000000 |
((b << 16) & 0xff0000) |
((g << 8) & 0xff00) |
(r & 0xff);
}
static void saveImage(imageLib.Image image, [int i = 0]) async {
// image ^4.0.17 error here
List<int> jpeg = imageLib.JpegEncoder().encodeImage(image);
final appDir = await getTemporaryDirectory();
final appPath = appDir.path;
final fileOnDevice = File('$appPath/out$i.jpg');
await fileOnDevice.writeAsBytes(jpeg, flush: true);
// print('Saved $appPath/out$i.jpg');
}
}
imageLib.Image? processCameraImage(CameraImage cameraImage) {
imageLib.Image? image = ImageUtils.convertCameraImage(cameraImage);
if (Platform.isIOS) {
// ios, default camera image is portrait view
// rotate 270 to the view that top is on the left, bottom is on the right
// image ^4.0.17 error here
image = imageLib.copyRotate(image!, 270);
}
return image;
// processImage(inputImage);
}I am trying to figure it out, but I would appreciate it if you have the answer. Thank you so much. |
|
Update. I found a solution in this link |
|
Do you have any version of camera^0.10.5 but Image^3.3.0? I noticed that 4.0.17 has a runtime issue with converting image, but Android 13 needs camera^0.10.5. |
I just change the camera version in original package's pubspec.yaml and then works |
|
This is extremely helpful, and I hope that the owner can merge this even though it is "deprecated". Furthermore, since you've clearly gained some exposure to the codebase through this upgrade, what you think about addressing this issue. I am doing a version overhaul on my app, and tried to bump tflite_flutter from 0.9.0 to 0.10.0. this is the response I got:
|
|
Hi @pnyompen After doing all the required Gradle upgrades and other stuff I got stuck with this helper package. I spent close to 2 days finding a solution until I stumbled upon your comment. While your version works, to some extent, the build now fails with the Kotlin version.
Is there a way you could help out? |
|
Hello @ykiran, I apologize for the delay in my response. In order to address the issue you pointed out, I have updated the versions of Kotlin and tflite_flutter. You can see the specific changes in the following commit: I hope that with this update, the errors occurring with the build on Flutter 3.13 will be resolved. If there are any issues or further support is needed, please feel free to let me know. I am here to help. Thank you for your cooperation. |
|
Hi @pnyompen , In the next two days, I'll once again try to do the upgrade and report back. Thank you, once again. |
Hi @pnyompen I'm really glad to report back that this change is working as expected and thank you so much for this help. I'm yet to test for IOS. That'll take a few more days; I'll try to get it done earlier if possible and report back. Again , thank you @pnyompen for your efforts. |
|
Hi @ykiran ! |
Title: Upgrade camera and image packages to latest versions
Body:
This pull request updates the
cameraandimagepackages to their latest versions (0.10.5 and 4.0.17 respectively).Changes:
camerapackage to version 0.10.5imagepackage to version 4.0.17Motivation:
Updating these packages ensures that our project benefits from the latest features, enhancements, and bug fixes provided by these versions.
Testing:
All unit and integration tests pass with these updates. Please note that the example has not been updated, but the changes should not affect its functionality.
Impact:
This change should not impact any existing functionalities but should improve the overall performance and stability of the application.
Please review these changes and let me know if there are any concerns or questions. Thank you!