how to detect a small qr in an image which is blurry

i tried all the methods including pyzbar and cv2.Qrdetection but none of them worked please help

i just want to locate the qr in the provided image and read it.

best logic that have is given below

import cv2
import numpy as np

def locate_small_blur_qr_code(image_path):
    image = cv2.imread(r"C:\Users\siddh\OneDrive\Desktop\1Image.png")
    
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  
    blurred = cv2.GaussianBlur(gray, (5, 5), 0)
    _, thresh = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    for contour in contours:
        # approximate the contour to polygon
        epsilon = 0.02 * cv2.arcLength(contour, True)
        approx = cv2.approxPolyDP(contour, epsilon, True)

        # check if the formed polygon has four vertices
        if len(approx) == 4:
            # Draw the contour on the original image
            cv2.drawContours(image, [approx], -1, (0, 255, 0), 2)

            # Extract roi around the QR code
            rect = cv2.minAreaRect(contour)
            box = cv2.boxPoints(rect)
            box = np.intp(box)  # Change from np.int0 to np.intp
            roi = image[min(box[:, 1]):max(box[:, 1]), min(box[:, 0]):max(box[:, 0])]

            # Resize the displayed window
            cv2.namedWindow("Detected QR Code", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("Detected QR Code", 800, 800)

            # Show the ROI
            cv2.imshow("Detected QR Code", roi)
            cv2.waitKey(0)

    cv2.destroyAllWindows()

image_path = r"C:\Users\siddh\OneDrive\Desktop\1Image.png"
locate_small_blur_qr_code(image_path)

  • 3

    share a sample image

    – 

Leave a Comment