我想在tkinter的1帧中显示2个视频源,但是当我运行代码时,它仅指示网络摄像头处于打开状态,并且该帧不会出现。 我是python编程的新手,所以请您帮忙
这是我的简单代码:
import cv2
import tkinter as tk
from PIL import Image,ImageTk
root = tk.Tk()
root.wm_title("Programmer is Life <3")
root.config(background="blue")
imageFrame = tk.Frame(root, width=600, height=500)
imageFrame.grid(row=0, column=0, padx=10, pady=2)
lmain = tk.Label(imageFrame)
lmain.grid(row=0, column=0)
sliderFrame = tk.Frame(root, width=252, height=225)
sliderFrame.grid(row=0, column=1, padx=10, pady=2)
lmain1 = tk.Label(sliderFrame)
lmain1.grid(row=0, column=0)
cap = cv2.VideoCapture(0)
def show_frame():
_, frame = cap.read()
frame = cv2.flip(frame, 1)
cv2image = cv2.rectangle(frame, (590, 10), (350, 225), (0, 255, 255), 2)
cv2image = cv2.cvtColor(cv2image, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(10, show_frame)
cv2image1 = cv2.cvtColor(cv2image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(cv2image1, (11, 11), 0)
blur = cv2.medianBlur(blur, 15)
thresh = cv2.threshold(blur, 210, 255, cv2.THRESH_BINARY
+cv2.THRESH_OTSU)[1]
thresh = cv2.bitwise_not(thresh)
img1 = Image.fromarray(thresh)
imgtk1 = ImageTk.PhotoImage(image=img1)
lmain1.imgtk = imgtk1
lmain1.configure(image=imgtk1)
lmain.after(10, show_frame)
show_frame()
root.mainloop()