在Qt Designer GUI中嵌入PyQtGraph

时间:2019-03-29 15:50:29

标签: python qt-designer pyqtgraph

我有一个QtGraph图,我想在Qt Designer中制作的GUI中的QLabel,Qwidget或Graphicsview中显示它,但是我找不到直接的方式来显示该图。我正在从摄像机流式传输视频,可以在GUI中轻松显示它,但是我为此感到吃力。

问题出在显示上。

#These are the libraries which have been used in the app.
import sys
import numpy as np
import cv2
import pyqtgraph as pg
import datetime

from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication , QMainWindow
from PyQt5.uic import loadUi
from PyQt5 import QtGui

#this is the main class for this app and get the visual GUI from QtDesigner
class VideoStream(QMainWindow):

    def __init__(self):
        super(VideoStream , self).__init__()
        loadUi('VideoStream.ui',self)
        self.image= None
        #self.l_values is the place that we collect the intensity values for each frame
        self.l_values = []
        #This is a button to set the geometry of our mask for the specific zone of lightness
        self.Apply_Button.clicked.connect(self.Geometry)
        #this  button save the maximum values of the specific zone in a text file
        #self.Save_Button.clicked.connect(self.save_data)
        self.startButton.clicked.connect(self.start_webcam)
        self.stopButton.clicked.connect(self.stop_webcam)
        #these two variables are the height and width of our camera. 
        #With different cameras this part should be changed.
        self.cameraHeight=480
        self.cameraWidth=640

    #This function shows the stream in the GUI we created by qtdesigner     
    def displayImage(self,img,window=1):
        qformat=QtGui.QImage.Format_Grayscale8
        outImage=QtGui.QImage(img, img.shape[1],img.shape[0],qformat)
        self.imgLabel.setPixmap(QtGui.QPixmap.fromImage(outImage))
        self.imgLabel.setScaledContents(True)

    #for the seperate canvas you should click on the move button in that window once
    def displayHist(self,img, window=1):
        self.avr = int(np.average(self.image)*25)
        self.avrage=np.array([self.avr])
        if self.l<=self.bufferSize:
            self.plt.setRange(xRange=[max(self.l- 100, 0), self.l])    
            self.data[self.l:self.l+self.n] = self.avrage
            self.curve.setData(self.data)
            print(self.l)
            self.l = (self.l+self.n) 
            if self.l%100==0:
                if self.l>=100:
                    print("y  ",self.k,np.max(self.data[self.l-100:self.l]))
                    self.k=self.k+1
                elif self.l==0:
                    print("- ",self.k,np.max(self.data[-(100-self.l):]))
                else:
                    print("n  ",self.k,max(np.max(self.data[-(100-self.l):]),np.max(self.data[:self.l])))
                    self.k=self.k+1
            self.line.setValue(self.l)
        if self.l>self.bufferSize:
            self.plt.setRange(xRange=[max(self.bufferSize- 100, 0), self.bufferSize])
            for j in range(self.bufferSize-1):
                self.data[j]=self.data[j+1]
            self.data[-1]=self.avrage
            self.curve.setData(self.data)
            self.l = (self.l+self.n)
            self.line.setValue(self.bufferSize)

    #this is the place that I don't have any idea what to do

0 个答案:

没有答案