Saving BMP image in QR code

I am trying to create (or, if I somehow missed this in my research, find) an algorithm for encoding / decoding a BMP image to / from a QR code format. I used the manual ( Thonky ) to try to understand the basics of QR codes, and I'm still not sure how to go about this issue, in particular:

  • Should I encode data as binary or numeric to be more reasonable (assuming each pixel has a maximum value of 255)?

  • I searched for information about the structured possibilities of adding QR codes, but did not find many details, except that it was supported by QR codes - how could I implement / use this functionality?

And, of course, if there are any tips / suggestions to better store the image as binary data, I am very open to suggestions!

Thank you for your time,

Sean

+8
bmp data-storage qr-code
source share
3 answers

Iโ€™m not sure that you can achieve this, since the amount of information that a QR code can store is quite limited.

First of all, you probably want to save your image as raw bytes, as other formats (numeric and alphanumeric) are designed to store text / numbers and provide less space for image storage. Suppose you select the largest possible QR code (version 40) with the lowest level of error correction, which can contain up to 2953 bytes of binary information (see here) .

The first option, as you think, will save the image as a bitmap. This format does not allow any compression at all and requires (in the case of an RGB image without an alpha channel) 3 bytes per pixel. If we take into account the size of the file header (from 14 to 54 bytes) and ignore the filling (each line of image data must be supplemented by a length multiple of 4), which allows us to store approximately 2900/3 = 966 pixels. If we look at a square image, this is a 31x31 bitmap, which is small even for a thumbnail image (for example, my avatar at the end of this post is 32x32 pixels).

The second option, you use JPEG to encode the image. The advantage of this format is the use of a compression algorithm that can reduce file size. This time there is no exact formula to get an image size of 2.9 kB, but I tried to use several square images and reduced them until they fit in that size, preserving a good (93) quality factor: this gives an average value about 60x60 pixels. (In such small images, it is usually not possible to see an incredible compression ratio between jpeg and bmp, since the file header in the jpeg file is much larger than in the bmp file: about 500 bytes). This is better than a bitmap, but it remains quite small.

Finally, even if you manage to encode your image in this QR code, you will run into another problem: the QR code, this large one, is very, very difficult to scan. In essence, this QR code will have a size of 177x177 modules (the โ€œmoduleโ€ is a small white or black square). Assuming that you scan it using a smartphone that provides the so-called "HD" frames (1280x720 pixels), each module will have a maximum frame size of about 4 pixels. If you take into account camera noise, overlap and blur due to the fact that the user is never inactive during scanning, the quality of the input frames will make it very difficult for any QR code decoding algorithm to successfully receive a QR code Code (do not forget to set the level of bug fixes is low at the beginning of this!).

Although this is not good news, I hope this helps you!

+9
source share

There is really a way to encode information on several (up to 16) QR codes using a special header in your QR codes called "Structured append". The best source of information you can use is the QR code norm (ISO 18004: 2006); it is possible (but not necessarily easy) to find it for free on the Internet.

The relevant part (section 9) of this rule reads:

"In a structured format, up to 16 characters of a QR code can be added. If a character is part of a structured application message, it is indicated by a header block in the first three character positions of the character. Indicator 0011" Structured Addition Indicator "is placed in the four most significant bit positions in the first character This is immediately followed by two Structured Append codewords, spreading over the four least significant bits of the first character of the character, the second character of the character and the four most significant bits of the character of the character. The first code word is an indicator of the sequence of characters. The second code word is the parity data and is identical to all characters in the message, which allows you to verify that all the characters read are part of the same message structured application. This header is immediately followed by code data words for a character starting with the first mode indicator.

However, I'm not sure that most QR code scanners can handle this, as it is a pretty advanced feature.

+2
source share

You can determine the size of a fixed image, reduce the parts of the jpg header, and use only vital information about it so that you can save up to 480 bytes of a regular 500 byte header.

I used this method to store photos of people for IDs with a small club, images about 64x64 pixels in size.

+1
source share

All Articles