如何提高OpenCV、tkinter和pillow的FPS

2024-09-27 21:28:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图在带有树莓pi(3b+)和RPI相机模块(v2)的tkinter窗口中显示我相机的相机馈送

当我保持默认设置(如imutils库中所设置)时,一切正常。但当我将相机分辨率更改为显示器的大小(1280x800)时,帧速率会显著下降

是否可以以30+fps的速度显示完整的相机分辨率?或者保持原始分辨率,但拉伸tkinter中显示的图像

我对RPI和OpenCV的开发相当陌生,所以我希望FPS可以用代码修复

我的代码如下:

from tkinter import Tk, Frame, Label
from PIL import Image, ImageTk
import imutils
import cv2

from imutils.video.pivideostream import PiVideoStream
import time

window = Tk()
window.attributes('-fullscreen', True)

cameraLabel = Label(window)
cameraLabel.pack()

vs = PiVideoStream(resolution=(1280, 800)).start()
time.sleep(2.0)


def show_pi_video():
    while True:
        frame = vs.read()
        frame = imutils.resize(frame)
        cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
        img = Image.fromarray(cv2image)
        imgtk = ImageTk.PhotoImage(image=img)
        cameraLabel.config(image=imgtk)
        window.update()
    cv2.destroyAllWindows()
    vs.stop()

show_pi_video()
window.mainloop()

Tags: 代码fromimporttkintervideopi分辨率window

热门问题