Background
I need to detect and decode a relatively small QR code (110x110 pixels) in a large image (2500x2000) on a Raspberry Pi. The QR code can be at any location in the frame, but the orientation is expected to be normal, i.e. top-up. We are using high quality industrial cameras and lenses, so images are generally good quality and in focus.
Currently, I am able to detect and decode the image reliably with pyzbar
when I crop the image around the QR code using a window of aprox 600x500. If I attempt to decode the full image, the symbol is not detected/decoded.
What I Have Tried
I have written a loop that slides a crop window over the image, and attempts to decode each cropped frame separately. I move the window by 50% each iteration to ensure I don't miss any symbols at the edge of the window.
I have also tried using OpenCV for detection/decoding but the performance was no better than with pyzbar
Problems With My Solution
Problems which affect my current project:
The sliding window approach is difficult to tune, inefficient and slow b/c:
- it causes the entire area to be analyzed nearly 4 times; a side effect of shifting the window by 50%,
- the most reliable window sizes tend to be small and require many iterations,
- the symbol size may vary due to being closer/further from the camera.
Problems that may affect other projects where I would use this approach:
- The sliding window may catch a symbol more than once, making it difficult to determine if the symbol was present more than once.
The Question
How can I find the approximate location of the QR code(s) so I can crop the image accordingly?
I am interested in any solutions to improve the detection/decoding performance, but prefer ones that (a) use machine learning techniques (I'm a ML newbie but willing to learn), (b) use OpenCV image pre-processing or (c) make improvements to my basic cropping algorithm.
Sample Image
Here is one of the sample images that I'm using for testing. It's purposely poor lighting quality to approximate the worst case scenario, however the individual codes still detect and decode correctly when cropped.