zbar icon indicating copy to clipboard operation
zbar copied to clipboard

Return different results after image was trimmed

Open mlove4u opened this issue 2 years ago • 0 comments

I build a Python library(zbar.cpython-37m-darwin.so) with: python setup.py install And here is my code:

import zbar
from PIL import Image


def get_codes(image_path):
    # create a reader
    scanner = zbar.ImageScanner()
    # configure the reader
    scanner.parse_config('enable')
    # obtain image data
    pil = Image.open(image_path).convert('L')
    width, height = pil.size
    raw = pil.tobytes()
    # wrap image data
    image = zbar.Image(width, height, 'Y800', raw)
    # scan the image for barcodes
    scanner.scan(image)
    # extract results
    for symbol in image:
        # do something useful with results
        print('decoded', symbol.type,
              'symbol', symbol.data)  # ,"rect", symbol.location)
    # clean up
    del(image)


files = ("test_original.jpeg",
         "test_trimming_1.jpeg",
         "test_trimming_2.jpeg",
         "test_trimming_3.jpeg")
for file in files:
    print("\n----------" + file)
    get_codes(file)

Output:

----------test_original.jpeg
decoded EAN13 symbol 9923231052789
decoded EAN13 symbol 4984831052789

----------test_trimming_1.jpeg
decoded EAN13 symbol 4984831052789

----------test_trimming_2.jpeg
decoded EAN13 symbol 9923231052789
decoded EAN13 symbol 4984831052789

----------test_trimming_3.jpeg
decoded EAN13 symbol 5987251052789
decoded EAN13 symbol 1901831052789
decoded EAN13 symbol 4984831052789

The results are quiet different if a image was trimmed in different area. I attach the original files(.jpeg) and files with color(.png) in each barcode detected. Thanks very much.

test_original.jpeg: 2 barcodes found

test_original test_original

test_trimming_1.jpeg: 1 barcode found

test_trimming_1 test_trimming_1

test_trimming_2.jpeg : 2 barcodes found

test_trimming_2 test_trimming_2

test_trimming_3.jpeg: 3 barcodes found

test_trimming_3 test_trimming_3

mlove4u avatar Oct 20 '21 01:10 mlove4u