【问题标题】:How to get type of Encoding Style of QR/bar-code with python-qrtools/ZBar?如何使用 python-qrtools/ZBar 获取 QR/条码的编码样式类型?
【发布时间】:2015-11-06 07:15:09
【问题描述】:

在我的 Ubuntu 服务器上,我使用sudo apt-get install python-qrtools 安装了python-qrtools package(使用zbar)来解码Python 中的二维码和条形码图像,如下所示:

>>> qr = qrtools.QR()
>>> qr.decode('the_qrcode_or_barcode_image.jpg')
True
>>> print qr.data
Hello! :)

这很好用。

我现在想存储这些数据并在以后的时间点重新生成图像。但问题是我不知道原始图像是二维码还是某种类型的条形码。我检查了qr 对象的所有属性,但似乎都没有给我编码样式的类型(QR/bar/other)。

this SO thread 中描述了 ZBar 确实返回了编码样式的类型,但它只给出了 Objective-C 中的一个示例,另外我不确定这是否真的是我正在寻找的答案.

有谁知道我如何在 Python 中找出编码样式的类型(例如 QR-code/BAR-code/other)(最好使用 python-qrtools 包)?如果不是在 Python 中,是否有任何 Linux 命令行工具可以找到它?欢迎所有提示!

【问题讨论】:

    标签: python objective-c qr-code zbar


    【解决方案1】:

    查看 qrtools 的来源,我看不到任何获取类型的方法,但是有一个基于 scan_image examplezbar python lib,下面的代码似乎可以满足您的要求:

    import zbar
    import Image
    
    scanner = zbar.ImageScanner()
    
    scanner.parse_config('enable')
    
    img = Image.open("br.png").convert('L')
    width, height = img.size
    stream = zbar.Image(width, height, 'Y800', img.tostring())
    
    scanner.scan(stream)
    
    for symbol in stream:
        print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
    

    使用我从net 抓取的随机条形码:

    decoded UPCA symbol "123456789012"
    

    使用这个qr code 输出:

     decoded QRCODE symbol "http://www.reichmann-racing.de"
    

    【讨论】:

    • 嗨帕德莱克。感谢一百万的代码!奇迹般有效。只是最后一个问题;你知道'Y800' 指的是什么吗?
    • @Kramer,不客气。第三个参数是图片格式四字符代码,对于zbar,图片必须是"Y800"(greyscale)"GRAY"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2018-10-27
    • 2018-10-30
    相关资源
    最近更新 更多