使用 Python 解码微型二维码



我使用"segno"用python创建Micro QR码:

import segno
segno.make_micro("1").save("1.png", scale=10)

输出图像

有谁知道用python解码这些的(简单)方法?我找不到图书馆,但我担心自己捐赠这个(也许使用 openCV)会付出很多努力。

与这篇文章相反(如何在(最好是纯)Python中解码QR码图像?我已经成功地安装了 PyQRCode 和 ZBar。不幸的是,这些图书馆不解码微型二维码。

PyBoof 刚刚更新,现在支持扫描/读取微型二维码并生成它们。请参阅 Github 上用于检测和创建的示例代码。以下是用于扫描/检测的代码副本:

import numpy as np
import pyboof as pb
# Detects all the QR Codes in the image and prints their message and location
data_path = "../data/example/fiducial/microqr/image01.jpg"
detector = pb.FactoryFiducial(np.uint8).microqr()
image = pb.load_single_band(data_path, np.uint8)
detector.detect(image)
print("Detected a total of {} QR Codes".format(len(detector.detections)))
for qr in detector.detections:
print("Message: " + qr.message)
print("     at: " + str(qr.bounds))

PyBoof是BoofCV的包装器,所以你可能也想检查一下。

由于显然使用微型二维码还没有变得足够普遍(还没有? )值得在我能找到的任何图书馆中添加对读取它们的支持,因此我正在寻找解决方法。在我的搜索中,我遇到了一两个支持解码微型二维码的在线二维码阅读器。由于我只是在学习Python的Playwright,我想,我会试一试。

下面的代码使用playwright打开在线二维码解码器网站,点击页面设置正确的选项,上传图像文件,然后从页面读取结果。

我知道这是一种完全复杂的方式,没有人会在生产代码中这样做,但它很有趣,而且确实有效:)虽然它不像 OP 要求的那样"简单",但恐怕

from playwright import sync_playwright
import segno
segno.make_micro("1").save("1.png", scale=10)
with sync_playwright() as p:
browser = p.firefox.launch(headless=False)
page = browser.newPage()
page.goto('https://www.datasymbol.com/barcode-reader-sdk/barcode-reader-sdk-for-windows/online-barcode-decoder.html')
page.querySelector('select[name="sr"]').selectOption([{'label': 'Text'}])
page.querySelector('img[alt="QRCode Decoder Scanner Settings"]').click()
page.querySelector('input[name="qrmicro"]').click()
page.querySelector('input[id="fupload1"]').setInputFiles('1.png')
page.querySelector('input[type="button"]').click()
iframe = page.querySelector('iframe[name="f2"]').contentFrame()
result = iframe.querySelector('css=pre').innerHTML().rstrip()
print(result)
browser.close()

指纹

1

一些注意事项:

  • 如果您不想在执行期间看到该页面,只需删除headless=False即可。
  • 显然,至少使用我选择的服务有一个非常令人不快的限制:如果您编码的文本长度超过两个字符,网站会将前两个字符更改为**,因此,如果您编码One Two Three您将检索**e Two Three。如果您不自己创建条形码,则这是一个限制。如果这样做,只需首先在内容的开头添加**即可。
  • 如果您确实想使用远程服务,但又不想通过 Web 界面进行复杂的方式,则有些服务可以提供直接 API,例如与requests一起使用。我上面选择的网站显然也提供了类似的东西,而且似乎有一个免费计划。但我从来没有用过它,所以我不能说什么。

最新更新