def passzbar(image):
# convert to bmp binary so that zbar can handle it
retval, buf = cv2.imencode('.bmp', image)
if retval == False:
raise ValueError('The Given image could not be converted to BMP binary data')
# convert buf from numpy.ndarray to bytes
binbmp = buf.tostring()
optionargs = []
args = [
ZBARIMG,
':-', '-q'
] + optionargs
p = subprocess.Popen(
args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False
)
stdout, stderr = p.communicate(input=binbmp)
if len(stderr) == 0:
bindata = stdout
else:
raise RuntimeError('ZBar threw error:\n' + stderr.decode('utf-8'))
t = bindata.split(b":", 1)
#print(t)
type = None
data = None
if len(t) == 2:
type, data = t
return type, data
评论列表
文章目录