python tkinter 打开摄像头并解决闪烁问题(python基础教程)

网友投稿 795 2022-09-06


python tkinter 打开摄像头并解决闪烁问题(python基础教程)

from tkinter import *from PIL import Image,ImageTkfrom tkinter import ttkimport osimport platformimport cv2import threading capture = cv2.VideoCapture(0) def loopCapture(): global capture global imgCanvas global win # imgpath = "./" # image = "50618close.jpg" abc=None while(True): _,frame= capture.read() # cv2.imshow("org",frame) cov= cv2.cvtColor(frame,cv2.COLOR_RGB2BGR) #初始图像是RGB格式,转换成BGR即可正常显示了 img =Image.fromarray(cov) img =ImageTk.PhotoImage(img) imgCanvas.create_image(0,0,anchor='nw',image=img) abc = None abc = img # 解决摄像头图像闪烁的问题.. def toggle_fullscreen(self, event=None): win.attributes("-fullscreen", True) def end_fullscreen(self, event=None): win.attributes("-fullscreen", False) def createUI(): global imgCanvas global win global frame1 global tree global label_speed win = Tk() win.title("***系统") # win.geometry("1920x1080") sysstr = platform.system() w = win.winfo_screenwidth() h = win.winfo_screenheight() win.geometry("%dx%d" %(w,h)) # win.attributes("-topmost",True) # win.attributes('-fullscreen', True) win.configure(bg="#fff") win.bind("", toggle_fullscreen) win.bind("", end_fullscreen) imgCanvas = Canvas(win,height=int(h * 0.8),width=w ) imgCanvas.pack(side='top', fill='x') win.mainloop() t=threading.Thread(target=loopCapture)t.setDaemon(True)t.start()createUI()

解决摄像头图像闪烁的问题 主要起作用的就是 abc = img 这句话, 变量名其实无所谓的. 只要加这么一句话就可以了.

这句话的作用应该是起到了图片对象延迟销毁的作用.


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【图像去噪】基于最小二乘方滤波实现图像去噪含Matlab源码(基于matlab的图像去噪论文)
下一篇:基于Java接口回调详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~