版本
问题
程序最初执行非常平稳,但是大约5分钟后,fps急剧下降。根据每条代码行的执行时间,它似乎在更新映像中消失了。
请帮助我修复此错误
from tkinter import *
from random import *
import PIL.Image, PIL.ImageTk
import time
import cv2
import threading
camera = cv2.VideoCapture(0)
speed = ""
def clear():
global exit
while True:
success, photo = camera.read()
cv2.waitKey(250)
if(exit):
break
window = Tk()
imageFrame = Frame(window, width=600, height=500)
imageFrame.grid(row=0, column=0, padx=10, pady=2)
lmain = Label(imageFrame)
lmain.grid(row=0, column=0)
start = 0
while True:
lmain.configure(image='')
lmain.image = ''
speed = ""
start = time.time()
success ,photo = camera.read()
speed = speed + (str)((int)((time.time()-start)*1000))
speed = speed + "ms "
cv2image = cv2.cvtColor(photo, cv2.COLOR_BGR2RGB)
speed = speed + (str)((int)((time.time()-start)*1000))
speed = speed + "ms "
img = PIL.Image.fromarray(cv2image)
speed = speed + (str)((int)((time.time()-start)*1000))
speed = speed + "ms "
imgtk = PIL.ImageTk.PhotoImage(image=img)
speed = speed + (str)((int)((time.time()-start)*1000))
speed = speed + "ms "
lmain.configure(image=imgtk)
lmain.image = imgtk
speed = speed + (str)((int)((time.time()-start)*1000))
speed = speed + "ms "
window.update()
speed = speed + (str)((int)((time.time()-start)*1000))
speed = speed + "ms "
print("Result: " + (str)(speed))
fps = (int)((1000/(time.time()-start))/1000)
print("FPS: " + str(fps))