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
评论列表
文章目录