I need to decode this QR Code using python3, opencv and pyzbar, but I'm not able to get any good result: the script is not able to detect/decode the QR Code.
Here is the code I've used. Is there any good way to improve the recognition?
import cv2
from pyzbar import pyzbar
# Image load
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to input image")
args = vars(ap.parse_args())
image = cv2.imread(args["image"])
# Read QR
qr_code = pyzbar.decode(image)
print(qr_code)
Before applying the QR decoder I also tried to:
Change brightness/contrast:
# Change brightness/contrast
image = cv2.convertScaleAbs(image, alpha=6, beta=0)
Make a binary image:
# Make binary image
image[image > 19] = 255
image[image <= 19] = 0
Rotate image (using this function):
def rotate_image(image, angle):
image_center = tuple(np.array(image.shape[1::-1]) / 2)
rot_mat = cv2.getRotationMatrix2D(image_center, angle, 1.0)
result = cv2.warpAffine(image, rot_mat, image.shape[1::-1], flags=cv2.INTER_LINEAR)
return result
image = rotate_image(image, 7)