0

Me and some classmates are working on a project for school. Quick description of our current problem:

We have build a vehicle and equipped it with a Raspberry Pi and a camera. When a QR-code is placed in front of the camera, we can order the camera to take a picture of it. With the use of an external Python module (qr-tools), the Raspberry Pi can automatically decode the QR-code.

When only a (small) part of the QR-code is visible to the camera, the decoding process fails (as is expected). We'd like to know if there's an easy way to detect parts of a QR-code in an image. That way, the Raspberry Pi could reposition the vehicle so that the whole QR-code can be captured on camera.

The keyword here is 'easy'. We have a few days left to improve our current vehicle, and a solution to this problem would be a nice feature to add.

Edit: I mistakenly linked the wrong module.

jvanheesch
  • 61
  • 2
  • 5

1 Answers1

1

I'm going to assume you're trying to identify QR codes that overlap the edge of the camera view. In this case you could check the four edges of the image for regions of high contrast (alternating between black and white), and turn in the corresponding direction if you find any.

Here's an example, using a random image from Flickr (with the edge pixels repeated):

QR Code on classroom window, source allanah_k@flickr

I'd suggest differentiating the grayscale values along all four edges and calculating a rolling average of the absolute difference values. The side with the highest peak value is your best bet.

For reference, here are the brightness values I calculated from the above images (shown in grey), together with the results of averaging the absolute differences over a ±20 pixel window:

Brightness of edge pixels and averaged difference values

As you can see, the skylight (or whatever it is) at the top of the image would be problematic, but the QR code in the foreground still produces the highest peak value.

r3mainer
  • 23,981
  • 3
  • 51
  • 88
  • Thank you for your answer - it looks like it shouldn't be too hard to make that work. However, for the time being, I'm looking into Digital Image Correlation and Tracking (DIC/DDIT) using opencv. This is the technique used for measuring the motion of an optical mouse. If we could apply this to our vehicle, it might be able to travel accurately and then the QR-code would be right in front of the camera (which would eliminate the need to recognize a piece of QR-code). However, if this approach won't work, we'll probably implement your solution, assuming it can be done in a day or two. – jvanheesch Nov 30 '13 at 18:24