-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
Crop image programatically before scanning #1177
Comments
@M123-dev I've quickly had a look at
final WriteBuffer allBytes = WriteBuffer();
for (final Plane plane in image.planes) {
allBytes.putUint8List(plane.bytes);
}
final Uint8List bytes = allBytes.done().buffer.asUint8List();
|
Yes @monsieurtanuki this is right. I'd rather choose to only use the upper part of the image, this is probably easier to do and doesn't restrict as much. |
@M123-dev Let me have a look at that crop part. /// A single color plane of image data.
///
/// The number and meaning of the planes in an image are determined by the
/// format of the Image.
class Plane {
Plane._fromPlatformData(Map<dynamic, dynamic> data)
: bytes = data['bytes'],
bytesPerPixel = data['bytesPerPixel'],
bytesPerRow = data['bytesPerRow'],
height = data['height'],
width = data['width'];
/// Bytes representing this plane.
final Uint8List bytes;
/// The distance between adjacent pixel samples on Android, in bytes.
///
/// Will be `null` on iOS.
final int? bytesPerPixel;
/// The row stride for this color plane, in bytes.
final int bytesPerRow;
/// Height of the pixel buffer on iOS.
///
/// Will be `null` on Android
final int? height;
/// Width of the pixel buffer on iOS.
///
/// Will be `null` on Android.
final int? width;
} |
I confirm that cropping looks easy from what I read in wikipedia. |
If you say so @monsieurtanuki , I've only skimmed the article, but I have to say for me with physics major it doesn't look exactly easy. I'm really look forward to the PR |
New files: * `abstract_camera_image_getter.dart`: Abstract getter of Camera Image, for barcode scan. * `camera_image_cropper.dart`: Camera Image Cropper, in order to limit the barcode scan computations. * `camera_image_full_getter.dart`: Camera Image helper where we get the full image. Impacted file: * `ml_kit_scan_page.dart`: now using new `CameraImageFullGetter` class - same full screen camera image capture as before for the moment.
@M123-dev Actually we don't even know why exactly the phones heat up. Possible reasons:
I'm about to improve my PR (#1184) in order to have clearer minds. And this is going to be a new parameter in the dev mode where we can decide:
I suspect the barcode scan method to be the problem (full image or top half). @teolemon IRW means "in real world" ;) |
Sounds like a good plan @monsieurtanuki, just ping me when you are done and I'll have a look |
Impacted files: * `ml_kit_scan_page.dart`: added optional scan / no scan options according to dev mode * `user_preferences.dart`: added methods for dev mode int values * `user_preferences_dev_mode.dart`: added a "scan mode" option on dev mode
…#1184) New files: * `abstract_camera_image_getter.dart`: Abstract getter of Camera Image, for barcode scan. * `camera_image_cropper.dart`: Camera Image Cropper, in order to limit the barcode scan computations. * `camera_image_full_getter.dart`: Camera Image helper where we get the full image. Impacted file: * `ml_kit_scan_page.dart`: added optional scan / no scan options according to dev mode * `user_preferences.dart`: added methods for dev mode int values * `user_preferences_dev_mode.dart`: added a "scan mode" option on dev mode
@M123-dev Had a chance to run 2-minute tests with each configuration to check when the smartphone is heating up? |
Not yet @monsieurtanuki , I'll try tomorrow. Do you have any experience on how to measure performance, besides "It felt okay". Does the profiler or logcat have any features for that |
I think we are fortunate enough to have a feature that heats up the smartphone rather quickly, therefore the "it feels okay" could be good enough in a first approach, for like 3-minute tests on each configuration.
Again, the profiler suggests that you run flutter "in profile mode" (something like |
Ok I'll have a look at it tomorrow |
Sorry for the late response, I did some excessive testing on friday.
I first tried it on my own pretty new phone and the performance / temperature was great. The tests went all without a problem (and I even learned that the Samsung stock camera automatically closes itself after two minutes without interaction), the phone got minimal warm over time but it stayed that way and when switching to other apps there was no stutter at all. So I did the same test on my mother's phone. It's a midclass phone from 2019 (3 Years old) and interestingly, the results remained the same. No performance or temperature problems at all, so I did an extended 30 minute test in half picture scannning mode directly after that and I noticed NO change, This means that the test unfortunately did not provide any information about what takes the most power from the process, but it did show that the performance is generally quite good. Maybe the changes that we only scan every tenth image has had a direct effect |
@M123-dev I guess you were not the right person to test it as you've never experienced the heating up of your smartphone, even with the current full screen scan. |
@jasmeet0817 initially raised the issue, can you maybe test again. But as long as you are able to run the app why not, you don't need to scan any product, this isn't the target audience, but it would still be great if we have decent performance there aswell |
@M123-dev In addition to the fact that I cannot access OFF API, the USB connection to my old smartphone is a bit loose, therefore I often cannot test beyond an approximate 2-minute threshold. Then I get the "Lost connection to device" message. Then most of the time I have to switch off my smartphone (because it's not recognized anymore for some reason), switch it on again, in the meanwhile I lose my internet connection because my smartphone is currently my wifi access. Ok, technically I can test. But it's rather painful. And probably pointless, because the device where the problem appeared has different characteristics. And if ever I tested and told you: "the problem is that we run the barcode scan in an endless loop (that's a fact): we need to change the UX with a 'scan now' button", you'd probably say "it does not look that way in the mocks, and btw we should test on the device where the problem appeared". Therefore I suggest tests to be run on the device where the problem appeared. |
|
What
mk_kit_scan_page,dart -> _processCameraImage()
, to only scan the upper partPart of
The text was updated successfully, but these errors were encountered: