使用matplotlib显示图像序列 [英] Display sequence of images using matplotlib

查看:138
本文介绍了使用matplotlib显示图像序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个使用OpenCV的简单python脚本,用于从文件夹加载图像并循环显示它们.我想使用matplotlib重现这种效果.

I have this simple python script using OpenCV to load images from a folder and display them in a loop. I want to reproduce this effect using matplotlib.

import cv2 as cv
import os

im_files = [for f in os.listdir('.') if f[-3:] == 'png']

for f in im_files:
    im = cv.imread(f, 0) #read image in greyscale
    cv.imshow('display', im)
    cv.waitKey(1)

cv.destroyAllWindows()

我尝试了以下脚本,但是打开以显示图的pyplot窗口没有响应.

I tried the following script but the pyplot window which opens to display the plots becomes un responsive.

import pylab as pl
import os

files = [f for f in os.listdir('.') if f[-3:] == 'png']
pl.ion()
for f in files:
    im=pl.imread(f)
    pl.imshow(im)
    pl.draw()

我在Google上搜索了很多,但是找不到任何解决方案.我该怎么做呢?我正在Windows 8上使用Anaconda 1.6 32bit.

I have googled a lot but couldn't find any solution. How do I go about doing this? I am using Anaconda 1.6 32bit on Windows 8.

推荐答案

img = None
for f in files:
    im=pl.imread(f)
    if img is None:
        img = pl.imshow(im)
    else:
        img.set_data(im)
    pl.pause(.1)
    pl.draw()

这篇关于使用matplotlib显示图像序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆