How to Open Video using Dialog Box in OpenCV

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

from tkinter import*
import tkinter.messagebox as msg
import tkinter.filedialog as fd
import cv2
def clickmenu(choice):
    if(choice=='open'):
        filename = fd.askopenfilename(parent=myroot, title='open file window',
                                      filetypes=(("Video", "*.mp4"), ("All File", "*.*")))
        vdo = cv2.VideoCapture(filename)
        while True:
             ret,frame=vdo.read()
             frame=cv2.resize(frame,(800,800))
             cv2.imshow('My Video Frame',frame)
             if(cv2.waitKey(1) == ord('e')):
                 break
        vdo.release()
        cv2.destroyAllWindows()
    elif(choice=='exit'):
        ch=msg.askyesno('Exit', 'Are You sure want to exit')
        if (ch==True):
            myroot.destroy()

myroot=Tk()
myroot.geometry('600x600')
myroot.title("My Video Capture Application")

menubar=Menu(myroot)
myroot.config(menu=menubar)
myfilemenu=Menu(myroot,tearoff=0)
myfilemenu.add_command(label="Open",command=lambda :clickmenu('open'))
myfilemenu.add_separator()
myfilemenu.add_command(label="Exit",command=lambda :clickmenu('exit'))
menubar.add_cascade(label="File",menu=myfilemenu)

myroot.mainloop()

 

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses
Image

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *