将本地视频通过opencv在tkinter窗口中显示

import tkinter as tk
from tkinter.filedialog import askopenfilename, askdirectory
from tkinter.messagebox import askquestion
# from demo_neo import Extractor
from PIL import Image
from PIL import ImageTk
import os
import threading
import time
import numpy as np
import uuid
import cv2
import pdb
from GUI.widgets import *
class Extractor_GUI():
    def __init__(self):
        self.__init_gui()
        # self.__init_model()
    def __init_gui(self):
       
        self.window = tk.Tk()
        self.window.wm_title('VideoText')
        self.window.config(background = '#FFFFFF')

        self.canvas = ICanvas(self.window, width = 800, height = 800)
        self.canvas.grid(row = 0, column = 0)

        self.fm_control = tk.Frame(self.window, width=800, height=100, background = '#FFFFFF')
        self.fm_control.grid(row = 1, column=0, padx=10, pady=2)
        self.btn_prev_frame = tk.Button(self.fm_control, text='Start', command = self.__action_read_frame)
        self.btn_prev_frame.grid(row = 0, column=0, padx=10, pady=2)
        self.lb_current_frame = tk.Label(self.fm_control, background = '#FFFFFF')
        self.lb_current_frame.grid(row = 0, column=1, padx=10, pady=2)
        self.lb_current_frame['text'] = '----'
        self.btn_next_frame = tk.Button(self.fm_control, text='Next Frame', command = None)
        self.btn_next_frame.grid(row = 0, column=2, padx=10, pady=2)


        self.fm_status = tk.Frame(self.window, width = 100, height = 100, background = '#FFFFFF')
        self.fm_status.grid(row = 0, column=1, padx=10, pady=2)
 
        self.btn_prev_frame1 = tk.Button(self.fm_status, text='Start1', command = self.__action_read_frame)
        self.btn_prev_frame1.grid(row = 0, column=0, padx=10, pady=2)
        

        self.btn_next_frame3 = tk.Button(self.fm_status, text='Start2', command = None)
        self.btn_next_frame3.grid(row = 1, column=0, padx=10, pady=20)


    def __action_read_frame(self):
        self.from_video()

    def from_video(self):

        cap = cv2.VideoCapture(1)
        idx = 0
        while True:
            ret,frame = cap.read()
            # print(frame)
            img = cv2.transpose(frame)
            img = cv2.flip(img,1)
            print(img.shape)

            self.canvas.add(img)
            self.window.update_idletasks()
            self.window.update()

    def launch(self):
        self.window.mainloop()


if __name__ == '__main__':
    ext = Extractor_GUI()
    ext.launch()
    # ext.from_video()
 

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值