=====
Usage
=====

QRDecode usage (without an image)
=================================

QRDecode can be used to decode QR codes represented in a `numpy.array`_.

You can generate a QR code using the qrcode library:

.. code-block:: python

    qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4)
    qr.add_data('hello world')
    qr.make()

Now you can represent this QR code in a `numpy.array`_ using the `numpy.array`_ function:

.. code-block:: python
   
   qr_array = numpy.array(qr1.modules, dtype=np.int)
   
Which will allow you to use the QRMatrix class (contained in qrdecode.decoder.py) to decode it:

.. code-block:: python

   qrm = QRMatrix(qr_array)
   qrm.decode()

And that's it! You will now have your QR decoded.

QRDecode usage (with an image)
==============================

QRDecode can be used to decode QR codes found in images. The process used internally is similar to the previously explained. You can follow the next instructions to use it with an image:

Fist, you have to upload the image using the Scanner class:

.. code-block:: python
   
   FILE_PATH = os.path.dirname(os.path.abspath(__file__))
   scanner = Scanner(os.path.join(FILE_PATH, "../", "path/to/image"),
   threshold="some_threshold",
   output_size=some_size,
   output_border=some_border_size)

After this, you will be able to scan the codes present in the image using the QRProcessor class:

.. code-block:: python
   
   for code in scanner:
      assert isInstance(code, QRProcessor)
      data = code.decode()

And you will have the data of the QR.

.. _numpy.array: https://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html
