|
| 1 | +# QR-Code-Generator |
| 2 | +You will learn how to create your own QR code and decode QR codes from an image by reading this repository. You should be able to include QR code capabilities into your own Python application at the conclusion of this. For this project, I'm utilising the python-qrcode package. |
| 3 | + |
| 4 | +## Content |
| 5 | +* [What is QR code?](#what-is-qr-code) |
| 6 | +* [What information QR code takes?](#what-information-qr-code-takes) |
| 7 | +* [Installation](#installation) |
| 8 | +* [QR Code generator](#qr-code-generator) |
| 9 | + - [Generating Procedure](#generating-procedure) |
| 10 | + - [Python code for basic example](#python-code-for-basic-example) |
| 11 | + - [Advanced usage](#advanced-usage) |
| 12 | + - [Qr code class](#qr-code-class) |
| 13 | + - [Error Correction constant](#error-correction-constant) |
| 14 | + |
| 15 | +## What is QR code? |
| 16 | +A QR code is a type of barcode that can be read easily by a digital device and which stores information as a series of pixels in a square-shaped grid, which can be read by any imaging device such as a camera, and processed to extract the required data from the patterns that are present in the horizontal components of the image. |
| 17 | + |
| 18 | +Standard barcodes can only be read in one direction – top to bottom. That means they can only store a small amount of information, usually in an alphanumeric format. But a QR code is read in two directions – top to bottom and right to left. This allows it to house significantly more data. |
| 19 | + |
| 20 | +The data stored in a QR code can include website URLs, phone numbers, or up to 4,000 characters of text. |
| 21 | + |
| 22 | +## What information QR code takes? |
| 23 | +QR code-generating software does not collect personally identifiable information. |
| 24 | + |
| 25 | +The data it does collect – and which is visible to the code’s creators – includes location, the number of times the code has been scanned and at what times, plus the operating system of the device which scanned the code (i.e., iPhone or Android). |
| 26 | + |
| 27 | +The QR codes themselves can’t be hacked – the security risks associated with QR codes derive from the destination of QR codes rather than the codes themselves. |
| 28 | + |
| 29 | +## Installation |
| 30 | +```python |
| 31 | +pip install qrcode |
| 32 | +``` |
| 33 | +```python |
| 34 | +pip instal opencv-Python |
| 35 | +``` |
| 36 | +The package will be installed in the system as the version of Python and pip. |
| 37 | + |
| 38 | +Once the installation is complete, create a new Python file and type the following syntax in it. |
| 39 | +```python |
| 40 | +# importing the required module |
| 41 | +import qrcode |
| 42 | +``` |
| 43 | +```python |
| 44 | +# importing the required module |
| 45 | +import cv2 |
| 46 | +``` |
| 47 | +# QR Code generator |
| 48 | + |
| 49 | +## Generating Procedure |
| 50 | +* Import module |
| 51 | +* Create Qrcode with qrcode.make() and it returns a PilImage object. |
| 52 | +* Save into image |
| 53 | + |
| 54 | +## Python code for basic example |
| 55 | +```python |
| 56 | +import qrcode |
| 57 | + |
| 58 | +# String which represent the QR code |
| 59 | +qrcode_generator = "QR code Generator" |
| 60 | + |
| 61 | +# Encoding data using make() function |
| 62 | +img = qrcode.make(qrcode_generator) |
| 63 | + |
| 64 | +# Create and save the image file by naming it |
| 65 | +img.save("Create_qr_code.png") |
| 66 | +``` |
| 67 | + |
| 68 | +## Advanced usage |
| 69 | +You can utilize the QRCode class, which comes with a lot more controls and properties. |
| 70 | + |
| 71 | +```python |
| 72 | +import qrcode |
| 73 | +# creating a QRCode object |
| 74 | +qr_object = qrcode.QRCode( |
| 75 | + version = 1, |
| 76 | + error_correction = qrcode.constants.ERROR_CORRECT_L, |
| 77 | + box_size = 10, |
| 78 | + border = 4, |
| 79 | +) |
| 80 | + |
| 81 | +# using the add_data() function |
| 82 | +qr_object.add_data("Advance use of QR code module") |
| 83 | + |
| 84 | +# using the make() function |
| 85 | +qr_object.make(fit = True) |
| 86 | + |
| 87 | +# using the make_image() function |
| 88 | +qr_img = qr_object.make_image(fill_color = "red", back_color = "black") |
| 89 | + |
| 90 | +# saving the QR code image |
| 91 | +qr_img.save("advancedusage.png") |
| 92 | +``` |
| 93 | + |
| 94 | +In the above snippet of code, we have imported the qrcode library. We have then created an instance of the QRCode class of the qrcode library. We have used different parameters in order to customize the QR code. We have then used the add_data() function to include the information for the QR code. We have also used the make() and make_image() functions to generate the QR code image. At last, we have saved the image file in the directory using the save() function. |
| 95 | + |
| 96 | +### QR code class |
| 97 | +* **version** — Accepts an integer from 1 to 40 which controls the size of the QR Code. The smallest version 1 has a dimension of 21 x 21. |
| 98 | + |
| 99 | +* **box_size** — Determines the number of pixels for each box of the QR code. |
| 100 | + |
| 101 | +* **border** — Determines the thickness of the border of the boxes. The default value is 4, which is the minimum size. |
| 102 | + |
| 103 | +* **error_correction** — Controls the error correction used. |
| 104 | + |
| 105 | +### Error Correction constant |
| 106 | +Error correction helps to improve the detection even when the image is disfigured or there is an overlay image on top of the QR Code. There are four constants available for error_correction: |
| 107 | + |
| 108 | +* **ERROR_CORRECT_L** — About 7% or fewer errors can be corrected. |
| 109 | + |
| 110 | +* **ERROR_CORRECT_M** — About 15% or fewer errors can be corrected. This is the default value. |
| 111 | + |
| 112 | +* **ERROR_CORRECT_Q** — About 25% or fewer errors can be corrected. |
| 113 | + |
| 114 | +* **ERROR_CORRECT_H** — About 30% or fewer errors can be corrected. |
| 115 | + |
| 116 | +## Conclusion |
| 117 | +A QR code is a matrix type 2D barcode (also known as checkerboard type 2D barcode), which has been frequently used on mobile devices in recent years. Compared with traditional barcodes, it can store more information. A two-dimensional code uses a certain geometric figure to record data symbol information in a black and white pattern distributed on a plane (two-dimensional direction) according to a certain rule. It can record numbers, English letters, Chinese characters, Japanese letters, special symbols (such as spaces, %, / etc.), binary information and other information into a square picture. In the position of the corresponding element of the matrix, the appearance of dots (square dots, dots or other shapes) is used to represent binary “1”, and the absence of dots represents binary “0”. The permutation and combination of points determine the meaning of the matrix two-dimensional bar code. |
0 commit comments