Search code examples
pythonimagegtksimplecv

How to convert python gtk pixbuf to simplecv image


I'm using simplecv to extract features from images. I use gtk to take a screenshot in python.

import gtk.gdk as g
w = g.get_default_root_window()
sz = [400,300]
pb = g.Pixbuf(g.COLORSPACE_RGB, False, 8,*sz)
cm = w.get_colormap()
pb = pb.get_from_drawable(w,cm,0,0,0,0,*sz)

How do I then convert that screenshot pixbuf to a SimpleCV Image instance?


Solution

  • I found the solution after some experimenting, given you have a pixbuf of an image named pb, then you can create a SimpleCV Image from pb like so

    im = Image(pb.get_pixels_array())