我想将 OpenCV 图像转换为 PyCairo,进行一些操作(绘图等)并将其转换回 OpenCV。你知道该怎么做吗?简单的例子就足够了。谢谢。
正如 PyCairo 中所指定的测试代码 https://github.com/dalembertian/pycairo/blob/master/test/isurface_get_data.py,转换一个cairo.ImageSurface
反对numpy array
:
import cairo
import numpy as np
w = 300
h = 300
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, w, h)
ctx = cairo.Context (surface)
# Draw out the triangle using absolute coordinates
ctx.move_to (w/2, h/3)
ctx.line_to (2*w/3, 2*h/3)
ctx.rel_line_to (-1*w/3, 0)
ctx.close_path()
ctx.set_source_rgb (0, 0, 0) # black
ctx.set_line_width(15)
ctx.stroke()
buf = surface.get_data()
array = np.ndarray (shape=(h, w, 4), dtype=np.uint8, buffer=buf)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)