Python 将PyGame网络摄像头流到Glade界面
我目前正在为望远镜开发GUI。Python 将PyGame网络摄像头流到Glade界面,python,gtk,pygame,pygtk,glade,Python,Gtk,Pygame,Pygtk,Glade,我目前正在为望远镜开发GUI。 我有一个摄像头通过USB连接到一个树莓圆周率。 一个小python脚本正在将imageData读取为字符串,并通过套接字将其发送到我的pc。现在我想在GTK图像中显示这个imageString def updateWebCamPic(self, imageString): print "update" img = Image.open(StringIO(imageString)) self.image.set_from_pixbuf(sel
我有一个摄像头通过USB连接到一个树莓圆周率。 一个小python脚本正在将imageData读取为字符串,并通过套接字将其发送到我的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
但我得到了以下错误:
raise IOError("cannot identify image file")
IOError: cannot identify image file
[编辑]:
if str(received[0]).startswith("<|Image|>"):
image=received[0][9:]
self.parrent.updateWebCamPic(image)
如果str(已收到[0])。开始使用(“”):
图像=收到[0][9:]
self.parrent.updateWebCamPic(图像)
始终显示完整的错误消息。代码中的哪一行生成此错误?可能是Image.open()
Image.open()
expect数据格式为PNG、JPG、GIF等。请参阅:string
可与其他Python模块中的fromstring()
一起使用Image.open()中的但是如何将pygame图像转换为png?或者如何显示曲面?您可能会使用PIL
或pill
然后选中PIL.Image.fromstring()
,或者始终放置完整的错误消息。代码中的哪一行生成此错误?可能是Image.open()
Image.open()
expect数据格式为PNG、JPG、GIF等。请参阅:string
可与其他Python模块中的fromstring()
一起使用Image.open()中的但是如何将pygame图像转换为png?或者如何显示曲面?您可能会使用PIL
或Pillow
然后选中PIL.Image.fromstring()
或者更确切地说