流式PyGame网络摄像头

2024-04-20 06:51:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在为望远镜开发图形用户界面。
我有一个摄像头通过USB连接到一个树莓派。 一个小的python脚本正在读取imageData到String,并通过socket将其发送到我的pc。现在我想在GTK图像中显示这个imageString。在

def updateWebCamPic(self, imageString):
    print "update"
    img = Image.open(StringIO(imageString))
    self.image.set_from_pixbuf(self.image2pixbuf(img))
    print "updatet"

def getPixBufRGB8Bit(self, im):
    arr = numpy.array(im)
    return GdkPixbuf.Pixbuf.new_from_data((arr, Gdk.COLORSPACE_RGB, 8))

def image2pixbuf(im):
    """Convert Pillow image to GdkPixbuf"""
    data = im.tobytes()
    w, h = im.size
    data = GLib.Bytes.new(data)
    pix = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
            False, 8, w, h, w * 3)
    return pix

但我得到了以下错误:

^{pr2}$

[编辑]:

^{3}$

Tags: fromimageselfimgnewdatareturndef