我打算流式传输两种视频流。一个是我的集成网络摄像头,另一个是外部网络摄像头。我已经看过一些代码,但是找不到任何暗示这种暗示的代码
我目前设法流式传输集成的网络摄像头并显示它。我的下一个挑战是将辅助流添加到一个GUI中,因为我需要它。
import cv2
import tkinter as tk
from tkinter import *
import ttk
from ttk import Frame
from PIL import Image, ImageTk
white = "#ffffff"
lightBlue2 = "#adc5ed"
font = "Constantia"
fontButtons = (font, 12)
maxWidth = 1920
maxHeight = 1280
#Graphics window
mainWindow = tk.Tk()
mainWindow.configure(bg=lightBlue2)
mainWindow.geometry('%dx%d+%d+%d' % (maxWidth,maxHeight,0,0))
mainWindow.resizable(0,0)
mainFrame = Frame(mainWindow)
mainFrame.place(x=20, y=20)
#Capture video frames
lmain = tk.Label(mainFrame)
lmain.grid(row=0, column=0)
cap = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture('test.mp4')
def show_frame():
ret, frame = cap.read()
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image).resize((760, 400))
imgtk = ImageTk.PhotoImage(image = img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(10, show_frame)
def show_frame2():
ret, frame = cap2.read()
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image).resize((760, 400))
imgtk = ImageTk.PhotoImage(image = img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(10, show_frame2)
show_frame() #Display
mainWindow.mainloop() #Starts GUI
答案 0 :(得分:0)
我会说,在不同的线程上运行每个视频流