python - 使用 Zbar Python 检测多个条形码的问题
问题描述
我正在尝试将 pyzbar 用于自动条形码检查项目。目标是从具有多个条形码的艺术品表中检测每个条形码的信息和类型。
下面的代码适用于一个条形码或几个不同的条形码。但就我而言,总共有 20 个 4 个不同的条形码。结果只返回 4 个不同的代码和 4 个坐标。看起来 zbar 跳过了所有重复的条形码。标记框看起来也很奇怪。任何想法为什么?
2408 3468 2966 107
0690461219945EAN13
278 3468 2287 107
0690461219952EAN13
278 1529 2434 107
0990461219816EAN13
435 1529 4939 1939
0690461219990EAN13
from pyzbar import pyzbar
import cv2
image = cv2.imread("test-1.png")
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
t,bimage = cv2.threshold(gray,160,255,cv2.THRESH_BINARY)
barcodes = pyzbar.decode(bimage)
for barcode in barcodes:
(x, y, w, h) = barcode.rect
print(x,y,w,h)
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), thickness=2)
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
print (barcodeData+barcodeType)
text = "{} ({})".format(barcodeData, barcodeType)
cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv2.imwrite("test1_re.png", image)
cv2.waitKey(0)
解决方案
推荐阅读
- r - How to split strings for a tibble
- r - 如何创建按 ID 分组并按日期排列的滞后和领先列?
- typescript - 在 2 个不同堆栈中的屏幕之间导航
- javascript - React Native - 在 SVG 中实现橡皮擦功能
- python - 将文件夹拆分为训练集和测试集
- vscode-extensions - VSCode OPA 扩展无法在 Mac 上找到输入文件
- python - 知道起点和终点的生成纬度和经度的最快方法是什么
- tensorflow - tf 优化器 compute_gradients 错误维度大小
- scala - 声明从未使用过——但它是吗?
- fastapi - Fastapi 和 SQLModel:如何从 POST 中的请求负载中提取和创建多对多类