pyzbar包未返回期望的结果

时间:2019-05-07 10:09:51

标签: python opencv image-processing barcode-scanner

我尝试使用zbar软件包,并且也阅读了文档。

我要求在EAN13格式的图像中有3个条形码(所有三个条形码中的代码都相同)。

当我在图像上运行以下代码时,我得到的结果仅为一个条形码:

def detectBarCode(image):
# find the barcodes in the image and decode each of the barcodes
barcodes = pyzbar.decode(image)

# loop over the detected barcodes
for barcode in barcodes:
    if barcode.type == 'EAN13':
        # extract the bounding box location of the barcode and draw the
        # bounding box surrounding the barcode on the image
        (x, y, w, h) = barcode.rect
        cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)

        # the barcode data is a bytes object so if we want to draw it on
        # our output image we need to convert it to a string first
        barcodeData = barcode.data.decode("utf-8")
        barcodeType = barcode.type

        # draw the barcode data and barcode type on the image
        text = "{} ({})".format(barcodeData, barcodeType)
        cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
                    0.5, (0, 0, 255), 2)

        # print the barcode type and data to the terminal
        print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))

根据我的用例,我需要输出为相同条形码的3倍。我尝试调整逻辑,但没有成功。 请让我知道是否有人建议达到预期的结果。

0 个答案:

没有答案