ihabunek / pdf417-py

PDF417 barcode generator for Python
Other
84 stars 28 forks source link

Wrong encoder for mixed type (with byte) #6

Closed kalloc closed 5 years ago

kalloc commented 7 years ago

Hi.

I save bytes to pdf417

hex_buf = '011b0000f829a358e1610100000001000000dfee82de5b9607c5186ce75de352648cfde9a15114305ebe39ed1db4940f3aa3cd89086ea5eb8db01fbe8255b0b0a5fbebca7a123859fc86f2ddfcb1abfd71e5' buf = bytes.fromhex(hex_buf) print(len(buf))

82

codes = encode(buf) img = render_image(codes) img.save('1.jpeg')

produced this image 230112158_11982600991711161154

When I check image on https://www.dynamsoft.com/Demo/DBR/BarcodeReaderDemo.aspx I got 011b0000f829a358e1610100000001005b9607c5186ce77de352648cfde9a15114305ebe39ed1db4940f3aa3cd89086ea5eb8db01fbe8255b0b0a5fbebca7a123859fc86f2ddfcb1abfd71e5

new_hex_buf = '011b0000f829a358e1610100000001005b9607c5186ce77de352648cfde9a15114305ebe39ed1db4940f3aa3cd89086ea5eb8db01fbe8255b0b0a5fbebca7a123859fc86f2ddfcb1abfd71e5' new_buf = bytes.fromhex(new_hex_buf) print(len(new_buf))

76

6 bytes missed :(

ihabunek commented 7 years ago

I will look into it, probably over the weekend.

kalloc commented 7 years ago

Did you have free time?

ihabunek commented 7 years ago

Sorry, I have been traveling and had other work. Before fixing, I'd like to find another another decoder to make sure the issue is with my encoding and not with their decoding. The one had time to try out (https://sourceforge.net/projects/pdf417decode/) did not work on my machine for some reason, would not recognize the barcode image format.

I'll try to find time to work on this soon, but can't promise you anything.

ihabunek commented 7 years ago

BTW, this reader gives a different decoding result, also different from input :/ https://online-barcode-reader.inliteresearch.com/

ihabunek commented 7 years ago

Not really. Working. See the issue.

-- Ivan

On Mon, 27 Feb 2017, at 14:57, kalloc wrote:

Did you have free time?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub[1], or mute the thread[2].

Links:

  1. https://github.com/ihabunek/pdf417-py/issues/6#issuecomment-282726574
  2. https://github.com/notifications/unsubscribe-auth/AAdbWnTPLMsANkATnTS3Po2ZFsj7lp7Qks5rgtZlgaJpZM4MAq-O
kalloc commented 7 years ago

I did use bcgen for generate image with test example from this ticket (82 bytes). Then I uploaded this image into dynamsoft decoder and got only 77 bytes instead of 82

kalloc commented 7 years ago

1) we need working generator 2) as I understand, dynamsoft decoder works well

kalloc commented 7 years ago

This 82byte_pdf417_example file was successfully decoded in dynamsoft.com

kalloc commented 7 years ago

I found valid coder.

def encode(data: bytes)-> bytes:
        import zint
        from ctypes import create_string_buffer, memmove
        import PIL
        import io

        input = zint.instr(data)
        symbol = zint.ZBarcode_Create()
        symbol.contents.symbology = zint.BARCODE_PDF417
        symbol.contents.option_1 = 4
        symbol.contents.option_2 = 4
        zint.ZBarcode_Encode_and_Buffer(symbol, input, len(input) - 1, 0)
        BITMAP_SIZE = symbol.contents.bitmap_height * symbol.contents.bitmap_width * 3
        buf = create_string_buffer(BITMAP_SIZE)
        memmove(buf, symbol.contents.bitmap, BITMAP_SIZE)
        im = PIL.Image.frombytes('RGB', (symbol.contents.bitmap_width, symbol.contents.bitmap_height), bytes(buf))
        b = io.BytesIO()
        im.save(b, format='PNG')
        image = b.getvalue()
        zint.ZBarcode_Delete(symbol)
        return image