Ask Your Question

Revision history [back]

Adding a QR Code to an image?

Hi all,

I've got an inspection project that I'm working on. Here's what I'd like to do. (maybe there's a better way to do this, feel free to let me know)

  1. acquire the image from a camera. (Done)
  2. Inspect the image for for a PASS/FAIL condition. (Done)
  3. Create a QR Code containing Image date, filename, and inspection result. (Done)
  4. Add the QR Code in the upper left of the image acquired by the camera... (Can't figure that one out)

I'm using the Python qrcode module to create the qr code. I can save the qrcode to .png and then imread it with Opencv and do it that way, but I'd like to avoid unnecessarily writing to disk.

Any suggestions?

import cv2
import qrcode
import numpy
import scipy.misc

image = cv2.imread('0000001.bmp' ) # This is where I would be acquiring image from camera


qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,
)


# These strings will be written by the inspection process
i_result = 'Failed'
i_timestamp = 'This time yall'
i_filename = '00001.bmp'


# Add the strings to the QR Code
qr.add_data(i_result)
qr.add_data(i_timestamp)
qr.add_data(i_filename)

# Make the QR Code
qrcode = qr.make_image(fill_color="black", back_color="white")

# How to make the QR code an OpenCV object???

Adding a QR Code to an image?

Hi all,

I've got an inspection project that I'm working on. Here's what I'd like to do. (maybe there's a better way to do this, feel free to let me know)

  1. acquire the image from a camera. (Done)
  2. Inspect the image for for a PASS/FAIL condition. (Done)
  3. Create a QR Code containing Image date, filename, and inspection result. (Done)
  4. Add the QR Code in the upper left of the image acquired by the camera... (Can't figure that one out)

I'm using the Python qrcode module to create the qr code. I can save the qrcode to .png and then imread it with Opencv and do it that way, but I'd like to avoid unnecessarily writing to disk.

I should add that the reason I am doing this is so that I can later run a python script that will read these QR Codes. For example, sorting the image files by PASS/FAIL result.

If there's a more elegant way to add this data to the image (custom meta-data?) I'm totally open to try it.

Any suggestions?

import cv2
import qrcode
import numpy
import scipy.misc

image = cv2.imread('0000001.bmp' ) # This is where I would be acquiring image from camera


qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,
)


# These strings will be written by the inspection process
i_result = 'Failed'
i_timestamp = 'This time yall'
i_filename = '00001.bmp'


# Add the strings to the QR Code
qr.add_data(i_result)
qr.add_data(i_timestamp)
qr.add_data(i_filename)

# Make the QR Code
qrcode = qr.make_image(fill_color="black", back_color="white")

# How to make the QR code an OpenCV object???