将截图快速加载到内存中以进行CV模板匹配的方法
在Ubuntu 11.10系统中,使用Python快速截屏并把截图转换成适合关于图像模板匹配的这个问题的格式,最简单的方法是什么?
1 个回答
4
xpresser 是一个可以在 Ubuntu 系统上运行的项目,它还使用了 opencv 这个库。在 xutils 模块 中,有一个可以截屏的函数,具体代码如下:
def take_screenshot(x=0, y=0, width=None, height=None):
window = gtk.gdk.get_default_root_window()
if not (width and height):
size = window.get_size()
if not width:
width = size[0]
if not height:
height = size[1]
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
pixbuf = pixbuf.get_from_drawable(window, window.get_colormap(),
x, y, 0, 0, width, height)
array = pixbuf.get_pixels_array()
return Image("screenshot", array=array,
width=array.shape[1], height=array.shape[0])
希望这对你有帮助。