简体   繁体   English

使用matplotlib和set_data()显示实时位图太慢。 如何使用位图进行咬合?

[英]Displaying real-time bitmap with matplotlib and set_data() is too slow. How to perform bitting with bitmaps?

Below is my Code. 下面是我的代码。 It is a server program that receives stream of bitmaps from the client and I want to display the bitmap in real time. 这是一个服务器程序,它从客户端接收位图流,我想实时显示位图。 However, the "frame.set_data(im)" is the bottle neck of my code and I only get 5 FPS. 但是,“ frame.set_data(im)”是我的代码的瓶颈,我只能得到5 FPS。 Disabling that line, I get aroung 15fps for receiving images. 禁用该行,接收图像的速度为15fps。 (the display is disabled ofcourse without set_data()). (没有set_data()的显示将被禁用)。

I looked for other answers, and I know I have to perform blitting to fast things up with MatPlotLib. 我在寻找其他答案,并且我知道我必须通过使用MatPlotLib来加快速度。 However, I have no idea how to perform blitting with bitmaps. 但是,我不知道如何使用位图执行blitting。 Could someone help me fast things up? 有人可以帮我加快步伐吗?

import matplotlib
matplotlib.use('TKAgg')
import matplotlib.pyplot as plt

while 1:
    # Decode and Save Image 
    imgdata = base64.b64decode(data)
    stream = io.BytesIO(imgdata)

    # Display realtime gameplay
    im = plt.imread(stream,"bmp")
    if frame is None:
        print "Start Rendering.."
        frame = plt.imshow(im)
        plt.show()
    else:
        frame.set_data(im)
    plt.pause(0.00000001)

Thanks @kazemakase I was able to achieve desired speed with pygame. 谢谢@kazemakase,我能够用pygame达到期望的速度。 Below is my code. 下面是我的代码。

import pygame

pygame.init()
screen = pygame.display.set_mode(size) 

while 1:
    # Decode and Save Image 
    imgdata = base64.b64decode(data)
    stream = io.BytesIO(imgdata)

    pygame.event.get()
    img=pygame.image.load(stream,'bmp') 
    screen.blit(img,(0,0))
    pygame.display.flip() # update the display

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM