serratus / quaggaJS

An advanced barcode-scanner written in JavaScript
https://serratus.github.io/quaggaJS/
MIT License
5.03k stars 977 forks source link

Scanner struggles with reflections #351

Open michaeltrollan opened 5 years ago

michaeltrollan commented 5 years ago

I have the ability for users to upload a photo image of the VIN barcode. I notice that if there's any sort of reflection at all, the scanner cannot find the barcode. Does anyone have ideas to improve performance in that area?

Here is what I'm using currently:

quagga.decodeSingle({
    decoder: {
        readers: ['code_39_vin_reader']
    },
    locate: true, // locate barcode in the image, regardless of barcode orientation
    src: URL.createObjectURL(e.target.files[0]) // pass local URL of uploaded image
})

You can see the issue in action by trying the attached images at this link: https://serratus.github.io/quaggaJS/examples/file_input.html

Doesn't work: reflection vin

Works: flat vin

ericblade commented 5 years ago

i'm no expert on image processing and vision, and such, but i'm noticing that if i take the image with the reflection and do a simple conversion to grayscale, that i can certainly understand why it's difficult to pick out the barcode completely from the rest of it. i know that doesn't point into any particularly good direction to go to, but some sort of adjustments to improve the contrast between the real area of the barcode, and the reflection on the black area above it seems like it could help there.

michaeltrollan commented 5 years ago

Thanks for the ideas @ericblade! Here's the grayscale conversion. Is there something about this that stands out to you as being harder than the color version?

I do see that the brightness of the blacks goes from about 25% to the left of the reflection to about 50% in the reflection. Maybe the algorithm has a certain threshold for brightness change and this exceeds it?

I'm also no expert on image processing, nor the how the algorithm looks for barcodes. Hopefully some possible ideas will come to light (pun not intended).

reflection-vin-grayscale

ericblade commented 5 years ago

yeah my guess is that it's possibly calculating all of that brighter area as "not part of the barcode" .. what the actual mechanism of that is, though, i don't know. i have literally never even looked at the reader code, only the interfaces to it. I wonder if either cutting out just the barcode and passing it in, or turning off autolocate and feeding a specific area would improve the detection ability.

ericblade commented 5 years ago

I've been playing with locate: false and it does seem to be quite a bit faster at scanning at much less battery consumption. I haven't noticed a significant increase in accuracy of it, or ability to read things that it couldn't read with locate: true, though, after a few hours of using it to scan books and things like that. I have noticed as I spent quite a bit of time scanning in weird lighting today, that significant differences in brightness across a barcode will fail to register, much like this. So it's not just the VIN reader, seems to probably be a problem with determining overall what is in the barcode.