I am trying to display the camera feed for my camera in a Tkinter
window with a Raspberry pi (3b+) and the RPI camera module (v2).
Everything works fine when I keep the default settings (as set in the imutils lib). But when I change the camera resolution to the size of my display (1280x800) the framerate drops significantly.
Is it possible to show the full camera resolution at a 30+ fps? or keep the original resolution but stretch the image that is displayed in tkinter
?
I am fairly new to development with the RPI and OpenCV, so I hope that the FPS can be fixed with code.
My code is below:
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()