Adding GUI window to python opencv2 program with pygtk3

I finished the program using Python and Opencv2. Now I want to add a GUI window to my program.

I have experience with PyGtk3. So, I modified my code for use with PyGtk3. But I got errors. So, I tried a simple program to find out the actual error.

My test code is:

import pygtk
pygtk.require('2.0')
import gtk
import numpy as np
import cv2

builder = gtk.Builder()
builder.add_from_file("GUI.glade")
window = builder.get_object("window1")
window.set_title("Single Object Tracking")
window.connect("delete-event", gtk.main_quit)
window.show_all()    
img = cv2.imread('Birds.jpg')
cv2.imwrite('abcdefgh.png',img)
cv2.imshow('image',img)
cv2.waitKey(10000)
cv2.destroyAllWindows()
gtk.main()

In fact, the program does not show a compile-time error. But after executing this program, when the thread reaches this program cv2.imshow('image',img), the program automatically terminates.

If I comment cv2.imshow('image',img"), it means that this program is working fine. But I need to insert the code cv2.imshow('image',img).

Could you help me solve this problem ...

Thanks in advance ...



Tkinter. , .

import numpy as np
import cv2

import Tkinter
top = Tkinter.Tk()
top.mainloop()

cam = cv2.VideoCapture('dove1.mp4')
# Structuring element
es = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (9,4))

t_minus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)

i = 1 
while True:
    flag,frame = cam.read()
    rgb_image = frame
    if(flag==False):
        break
    print i
    i = i + 1
    cv2.imshow('RGB Image',frame);

, GUI . 4 . . GUI - . - ?

+3

All Articles