我正在尝试使用 Python PyQt5 运行一个程序,在该程序中我获取 2 个摄像头的 ip 并将它们实时流式传输到我的屏幕上,但是流就像给定图片中的一样(查看第一张图片),两个流都来了在前半部分,但我真正想要的是将它们分成两半(查看第二张图片以便更好地理解)水平布局的代码顶部布局,而不是仅在屏幕的第一半部分(我也是正在获取这些黑色边框,如果有人知道如何将其删除,我将无法删除它们,请告诉)
在视频流位于底部布局的顶部布局之后,我试图获取一个图表和一个空的小部件我可以编辑以备后用。
提前致谢
#this is my main window code#
import sys
import vlc
import subprocess
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import*
from PyQt5.QtWebEngineWidgets import*
from PyQt5.QtPrintSupport import*
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Final App")
self.setGeometry(350,150,400,400)
self.UI()
#calling the UI fucntion which contains the layouts
def UI(self):
self.mainLayout=QVBoxLayout()#main layout is in Vertical Layout
self.topLayout=QHBoxLayout()#top layout is in Horizontal layout
self.bottomLayout=QHBoxLayout()#btm layout is in also in horizontal layout
self.topLayout.setContentsMargins(0, 0, 0, 0)
#self.topLayout.setSpacing(0)
#adding the top and bottom layout inside main layout
self.mainLayout.addLayout(self.topLayout)
self.mainLayout.addLayout(self.bottomLayout)
#assigning variables to different widgets that can be added later
self.videoFrame1 = QFrame()
self.videoFrame2 = QFrame()
#code here to add graph#
#graphcode=graph#
self.text=QLabel("A widget that I can Edit LATER ")
########################################################video player 1###################################################################################
self.videoFrame1 = QFrame()
#QWidget.setGeometry (self,100, 200, 1000, 500)
self.videoFrame1.setGeometry(QtCore.QRect(100, 100, 100, 200))
self.topLayout.addWidget(self.videoFrame1)
self.vlcInstance = vlc.Instance(['--video-on-top'])
self.videoPlayer = self.vlcInstance.media_player_new()
self.videoPlayer = self.vlcInstance.media_player_new()
self.videoPlayer.video_set_mouse_input(False)
self.videoPlayer.video_set_key_input(False)
#self.videoPlayer.set_mrl("rtsp://admin:admin123@192.168.1.250:554/cam/realmonitor?channel=1&subtype=0", "network-caching=300")
self.videoPlayer.set_mrl("rtsp://admin:admin123@192.168.1.251:554/cam/realmonitor?channel=1&subtype=0", "network-caching=200")
self.videoPlayer.audio_set_mute(True)
if sys.platform.startswith('linux'): # for Linux using the X Server
self.videoPlayer.set_xwindow(self.videoFrame1.winId())
elif sys.platform == "win32": # for Windows
self.videoPlayer.set_hwnd(self.videoFrame1.winId())
elif sys.platform == "darwin": # for MacOS
self.videoPlayer.set_nsobject(int(self.videoFrame1.winId()))
self.videoPlayer.play()
#########################################video player 2############################################################################################
#frame2
self.videoFrame2 = QFrame()
self.topLayout.addWidget(self.videoFrame2)
self.vlcInstance1 = vlc.Instance(['--video-on-top'])
self.videoPlayer1 = self.vlcInstance1.media_player_new()
self.videoPlayer1 = self.vlcInstance1.media_player_new()
self.videoPlayer1.video_set_mouse_input(False)
self.videoPlayer1.video_set_key_input(False)
#self.videoPlayer1.set_mrl("rtsp://admin:admin123@192.168.1.251:554/cam/realmonitor?channel=1&subtype=0", "network-caching=300")
self.videoPlayer1.set_mrl("rtsp://admin:admin123@192.168.1.250:554/cam/realmonitor?channel=1&subtype=0", "network-caching=200")
self.videoPlayer1.audio_set_mute(True)
if sys.platform.startswith('linux'): # for Linux using the X Server
self.videoPlayer1.set_xwindow(self.videoFrame2.winId())
elif sys.platform == "win32": # for Windows
self.videoPlayer1.set_hwnd(self.videoFrame2.winId())
elif sys.platform == "darwin": # for MacOS
self.videoPlayer1.set_nsobject(int(self.videoFrame2.winId()))
self.videoPlayer1.play()
###########################################################################################################
#calling top layout
self.toplayout()
#calling bottom layout
self.bottomlayout()
#setting main layout
self.setLayout(self.mainLayout)
self.show()
def toplayout(self):
self.topLayout.setContentsMargins(10,10,20,20)
self.topLayout.addWidget(self.
videoFrame1)
self.topLayout.addWidget(self.videoFrame2)
def bottomlayout(self):
self.bottomLayout.setContentsMargins(150,40,100,80)
self.bottomLayout.addWidget(self.raddar)
self.bottomLayout.addWidget(self.button2)
def main():
App= QApplication(sys.argv)
window=Window()
sys.exit(App.exec())
if __name__ == '__main__':
main()
这是我的另一个具有 matplotlib 代码的文件夹:---
#this is another folder having my garph which i want to call in my main window#
import matplotlib.pyplot as plt
def UI():
plt.figure()
# Set x-axis range
plt.xlim((-4,4))
# Set y-axis range
plt.ylim((0,8))
#setting background color
ax = plt.axes()
ax.set_facecolor('black')
# Draw lines to split quadrants
plt.plot([0,0],[0,8], linewidth=3, color='blue' )
plt.plot([-4,4],[4,4], linewidth=3, color='blue' )
plt.title('Quadrant plot')
plt.show()
UI()