Adding GUI Window to python opencv2 program with p

2019-05-07 01:47发布

I have completed a program using Python and Opencv2. Now, I wants to add a GUI Window to my program.

I am having some experience with PyGtk3. So, I modified my code to adopt with PyGtk3. But, I got errors. So, I tried a simple program to find out the actual mistake.

My testing 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()

Actually, program does not show any compile time error. But after execute this program, when the flow reach that code cv2.imshow('image',img) program automatically terminates.

If I comment cv2.imshow('image',img") only means this program works fine. But, I need to insert the code cv2.imshow('image',img).

Could you please help me to solve this problem...

Thanks in advance...

Update

I tried with Tkinter. I am able to show a Image but unable to show video. My testing code is

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);

Actually, I want to add a GUI window to my program. I am processing a input video file and displaying 4 levels of its output video. Its completed. GUI is problem. Can anyone help me to solve my problem please ?

0条回答
登录 后发表回答