passpotrace.py 文件源码

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

项目:handfontgen 作者: nixeneko 项目源码 文件源码
def passpotrace(image, optionargs=[]): 
    # potrace supports only pnm (pbm, pgm, ppm), bmp
    # and cv2.imencode() supports all of them.

    # convert to bmp binary so that potrace 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 = [
        POTRACE,
        '-', '-o-', '--svg'
    ] + 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:
        binsvg = stdout
    else:
        raise RuntimeError('Potrace threw error:\n' + stderr.decode('utf-8'))

    return binsvg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号