简体   繁体   English

PyGtk gi在图像小部件中使用cv2显示图像

[英]PyGtk gi show image using cv2 in image widget

I tried this code to display images in a PyGtk image widget. 我尝试使用此代码在PyGtk图像小部件中显示图像。 But it shows blank lines. 但它显示空白行。

img_gtk = Gtk.Image()
# Do other things such as attaching the 'img_gtk' to a window/grid...

# Convert and display:
h, w, d = img.shape
pixbuf = GdkPixbuf.Pixbuf.new_from_data  (img.tostring(), GdkPixbuf.Colorspace.RGB, False, 8, w, h, w*3, None, None)
img_gtk.set_from_pixbuf (pixbuf)

How can i do this using pixbuf? 如何使用pixbuf执行此操作?

The problem is memory management - by the time Gtk.Image wants to display the image, the content of pixbuf is gone. 问题是内存管理-到Gtk.Image想要显示图像时,pixbuf的内容就消失了。 Simply make a copy with: img_gtk.set_from_pixbuf(pixbuf.copy()) 只需使用以下副本进行复制: img_gtk.set_from_pixbuf(pixbuf.copy())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM