I have been trying to read some barcodes from images uzing Python and pyzbar. Unfortunately, the images are taken from several feet away under several constraints and I cannot move or zoom the camera any closer. Is it possible to read barcodes this blurry using any existing Python libraries?
So far I've tried some preprocessing including thresholding, sharpening, applying a vertical closing filter, and Wiener filtering, but none seem to help. I am probably asking for a miracle, but if you have any suggestions I would really appreciate it.
Code (commented sections are preprocessing methods I have tried with no success):
import numpy as np
import cv2 as cv
from pyzbar import pyzbar
barcode_img = cv.imread('barcode_example.jpg', cv.IMREAD_GRAYSCALE)
# threshold
# (_, barcode_img) = cv.threshold(barcode_img, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
# close
# barcode_img = cv.morphologyEx(barcode_img, cv.MORPH_CLOSE,
# cv.getStructuringElement(cv.MORPH_RECT, (1, 21)))
# sharpen
# barcode_img_blur = cv.GaussianBlur(barcode_img, (15, 1), 3)
# barcode_img = cv.addWeighted(barcode_img, 1.5, barcode_img_blur, -0.5, 0)
# wiener filter
# from skimage import img_as_float
# from skimage.restoration import wiener, unsupervised_wiener
# dim = 3
# psf = np.ones((dim, dim)) / dim ** 2
# barcode_img = wiener(barcode_img, psf, 1.0, clip=False)
barcodes = pyzbar.decode(barcode_img)
print(barcodes)