使用zbar-python的条形码检测不适用于所有文档
我正在尝试使用识别/检测以下文档中的条形码。下面是我从a中使用的代码,用于根据我拥有的数据测试库使用zbar-python的条形码检测不适用于所有文档,python,barcode,barcode-scanner,zbar,Python,Barcode,Barcode Scanner,Zbar,我正在尝试使用识别/检测以下文档中的条形码。下面是我从a中使用的代码,用于根据我拥有的数据测试库 from __future__ import print_function import pyzbar.pyzbar as pyzbar import numpy as np import cv2 import imutils import argparse def decode(im): # Find barcodes and QR codes decodedObjects =
from __future__ import print_function
import pyzbar.pyzbar as pyzbar
import numpy as np
import cv2
import imutils
import argparse
def decode(im):
# Find barcodes and QR codes
decodedObjects = pyzbar.decode(im)
# Print results
for obj in decodedObjects:
print('Type : ', obj.type)
print('Data : ', obj.data, '\n')
return decodedObjects # Display barcode and QR code location
def display(im, decodedObjects):
# Loop over all decoded objects
for decodedObject in decodedObjects:
points = decodedObject.polygon
# If the points do not form a quad, find convex hull
if len(points) > 4:
hull = cv2.convexHull(np.array([point for point in points], dtype=np.float32))
hull = list(map(tuple, np.squeeze(hull)))
else:
hull = points
# Number of points in the convex hull
n = len(hull)
# Draw the convext hull
for j in range(0, n):
cv2.line(im, hull[j], hull[(j + 1) % n], (0, 255, 0), 50) # Display results
cv2.imshow("Results", imutils.resize(im, 500))
cv2.waitKey(0) # Main
def display_ppn(im, decoded_objects, draw='rect'):
if draw == 'rect':
all_barcodes = []
for decoded_object in decoded_objects:
points = [[x, y] for x, y in (decoded_object.polygon)]
all_barcodes.append(points)
print(all_barcodes)
else:
all_barcodes = []
for decoded_object in decoded_objects:
points = [[x, y] for x, y in (decoded_object.polygon)]
all_barcodes.append(points)
print(all_barcodes)
for barcode in all_barcodes:
cv2.polylines(im, [np.array(barcode)], True, (0, 255, 0), 3)
cv2.imshow("Results", imutils.resize(im, 500))
cv2.waitKey(0)
if __name__ == '__main__':
# Creates parser
parser = argparse.ArgumentParser()
# parser arguments:
parser.add_argument('image', type=str, help='Path to image of form')
args = parser.parse_args()
# Read image
im = cv2.imread(args.image)
decodedObjects = decode(im)
display_ppn(im, decodedObjects)
虽然有些文件运行良好,但大多数文件并非如此。有人能帮我理解为什么会发生这种情况,以及我如何能得到100%的检测吗?增加条形码大小或类型是否有帮助?我拥有的输入图像将始终进行二值化
工作样本
失败的样本
矫直可能有助于识别软件找到条形码,但由于存在别名,许多条形码的条形码和空格变窄或加厚。我不希望阅读每一段代码都能100%成功。我建议您使用软件将条形码标签与条形码周围的空白隔开,并对下面的字符执行OCR。如果您想查看图片,您必须始终以正确的角度查看。否则,将丢失深度的大小。清晰度在分色中非常重要。@dsgdfg您是否建议我旋转图像以使条形码笔直?