passzbar.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:handfontgen 作者: nixeneko 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号