我想在python中使用USB条形码阅读器阅读条形码。我搜索了支持条形码阅读的库,也支持python 2.7,但我没有找到任何东西。 有没有可以帮助我的图书馆? 另外,如果你知道关于条形码阅读的任何教程,请告诉我在哪里可以找到它(因为我是条形码新手:) :)。
答案 0 :(得分:2)
您应该尝试使用zbar和PyUSB,扫描“USB Serial”模式条形码,然后“保存”条形码以使此设置永久化。现在您的3310g处于serail仿真模式,请注意新的/ dev / ttyACM0或/ dev / ttyUSB0设备。使用python中的简单文件操作读取串口:
f = open('/dev/ttyACM0')
print f.read(13)
答案 1 :(得分:0)
(迟到总比没有好...): Pyzbar和OpenCV应该做您想要的事。
这是我在Python 3中使用的代码。
#!/usr/bin/python3
# -*- coding: Utf-8 -*-
from __future__ import print_function
import pyzbar.pyzbar as pyzbar
import numpy as np
import cv2
def decode(im) :
# Find barcodes and QR codes
decodedObjects = pyzbar.decode(im)
# Print results
for obj in decodedObjects:
print('Type : ', obj.type)
print('Data : ', obj.data,'\n')
return decodedObjects
# Display barcode and QR code location
def display(im, decodedObjects):
# Loop over all decoded objects
for decodedObject in decodedObjects:
points = decodedObject.polygon
# If the points do not form a quad, find convex hull
if len(points) > 4 :
hull = cv2.convexHull(np.array([point for point in points], dtype=np.float32))
hull = list(map(tuple, np.squeeze(hull)))
else :
hull = points;
# Number of points in the convex hull
n = len(hull)
# Draw the convext hull
for j in range(0,n):
cv2.line(im, hull[j], hull[ (j+1) % n], (255,0,0), 3)
# Display results
cv2.imshow("Results", im);
cv2.waitKey(0);
# Main
if __name__ == '__main__':
# Read image
im = cv2.imread('zbar-test.jpg')
decodedObjects = decode(im)
display(im, decodedObjects)
您可以在这里找到此代码:https://www.learnopencv.com,并附有说明。
答案 2 :(得分:0)
我通过 USB 连接的条码扫描仪在 Windows 10 中的作用类似于标准输入设备(如键盘)。当在记事本中打开的文本文件上扫描条码时,扫描仪输出的数字直接出现在文本文件中,就像在键盘上打字一样。< /p>
因此,为了在 Windows 10 中读入 Python39 shell 或文件,我使用了 python 代码 'input("scan Barcode: ")' 并扫描了代码,这成功地给了我由设备/扫描仪生成的条形码数字。
C:\Project\Python39>python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>>
>>>
>>> input("scan Barcode: ")
scan Barcode: 88H-1010UB-0TV
'88H-1010UB-0TV'
>>>
>>> myBarCodeId = input("Scan barCode please ...")
Scan barCode please ...TARNLK002563
>>>
>>> print(myBarCodeId)
TARNLK002563
>>>
>>> mibar=input("scan me please \n")
scan me please
88H-1010UB-0TV
>>>
>>> print(mibar)
88H-1010UB-0TV
>>>