[Feature Request] Reading and scanning inverted Datamatrix code
mhilalsh opened this issue · 3 comments
I'm trying to read inverted datamatrix code (light on dark/white on black) but it's not detecting or scanning it at all.
Sorry, I'm not going to be able to do much to help you I'm afraid. You'd be better off asking the Google team for MLKit as this plugin just wraps around their library and uses it to do all of the scanning.
You could theoretically branch this repository, and put an intermediate step in between receiving the image frame and sending it to the library for processing where you invert the colours of each part of the image and then rewrite it back to the same format. That's pretty beyond the scope of this plugin though.
@rmtmckenzie can you just tell me where to find the function where I can add this step to invert the colors?
may I also know what Camera package are you using for the camera preview?
I'm not using any camera package - the code is written directly in the repository. That's why this won't be simple to do.
The place to do this would probably be in the QrDetector class for android and somewhere around here in QrReader.swift for ios.
You're going to have 3 major problems to deal with on Android. One is that all phones don't seem to give the data back in exactly the same format - and especially any older phones that fall back to the first Camera API. So unless you can completely ignore older phones, you're probably going to need to figure out which format the data is actually in (normally NV21 on older phones and ideally YUV_420_888 on newer, although that doesn't seem to always be the case).
Once you've figured out the format, your next problem will be actually inverting it. That shouldn't be all that difficult, and you might even be able to find a library to do it, but most likely you're going to have to write the code.
Unfortunately, unless you really know what you're doing, the code to invert the colour is going to be pretty slow - definitely not fast enough to do in real time in the same thread anyways. So you'll want to defer processing to another thread at the very least, or ideally the GPU. And then once you've done that, you can finally pass it off to the detector, while being concious of memory management and dropped frames.
If you want to attempt this, good luck... but it's definitely an undertaking. It might be a lot more realistic in this situation to get your users to take a picture using the camera package, and then invert the colours in a dart isolate, and then pass it to the google_ml_kit plugin. It definitely won't be able to process streaming photos, and will likely be a bit slow (but you should be able to show an animation during processing if you use isolates properly), but it should be a lot more doable...