如何利用matplotlib提高显示速度

2024-10-02 22:23:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了两个文件,一个是.pyx文件,它包含一个名为androCamersSDK的类,该类有一个名为LiveAcquisition()的函数。第二个文件是一个.py文件,它包含一个类cameragui,它使用Tkinter创建一个GUI。这个类有函数LivePlot()和RepeatPlot()。在LiveAcquisition()中,我正在获取N个帧,在获取每个帧之后,我需要使用LivePlot()和RepeatPlot()显示它。如果没有显示器,仅仅获取和存储300帧就需要6.2来执行,这对我来说很好。但是当我开始显示100帧时,它需要54秒。我需要在6秒内采集并显示300帧。我该怎么解决这个问题?你知道吗

文件1:.pyx代码;存在于类和camerasdk中

def  LiveAcquisition(self):
    for i in range(no_of_frames): 
        data[i,:,:] = PyArray_NewFromDescr(<PyTypeObject *> np.ndarray, np.dtype('<H'), 2,dims, strides,pBuf, np.NPY_C_CONTIGUOUS, None)
        if (i==0):
            self.master.LivePlot(data[i,:,:])
        elif (i==2) or (i==15) or (i ==65) or (i ==96):
            self.master.RepeatPlot(data[i,:,:])
        else:
            pass

文件2:.py代码;以下函数存在于名为cameragui的类中

def LivePlot(self,image):
    self.count = 0
    self.fig = Figure(figsize = (4, 5))
    self.fig.patch.set_facecolor('xkcd:light grey') # When this is removed a white color is seen in the background of the figure
    self.a = self.fig.add_subplot(111)
    self.a.set_xlim([0, self.image_width/int(self.HBin)])
    self.a.set_ylim([0, self.image_height/int(self.VBin)])
    image = image.transpose()
    self.a.imshow(image,'gray')
    self.canvas = FigureCanvasTkAgg(self.fig,self.master)
    self.canvas.draw()
    self.canvas.get_tk_widget().pack(side =LEFT)
    self.toolbar = NavigationToolbar2TkAgg(self.canvas,self.master)
    self.toolbar.update()
    self.canvas._tkcanvas.pack(side = LEFT)# change this to TOP so thee the navigation toolbar on the left down

def RepeatPlot(self,image):
    image = image.transpose()
    self.a.imshow(image,'gray')
    self.canvas.draw()

Tags: or文件the函数imageselfmasterdata