python - 使用 matplotlib 显示图像序列

标签 python opencv matplotlib

我有这个简单的 python 脚本,它使用 OpenCV 从文件夹加载图像并循环显示它们。我想使用 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 窗口变得没有响应。

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()

我在谷歌上搜索了很多,但找不到任何解决方案。我该怎么做呢?我在 Windows 8 上使用 Anaconda 1.6 32 位。

最佳答案

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()

关于python - 使用 matplotlib 显示图像序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17888593/

相关文章:

python - 如何通过Django中的表单向整数字段添加值?

python - 如何将千位分隔符添加到已在 python 中转换为字符串的数字?

python - knn 在 python 中使用 opencv 进行搜索

python - matplotlib 不生成 PS 输出

python - 仅在 matplotlib 上移除底部错误上限

python - pylab : plotting points with colors and labels (IDs, 不是类别)

python - 查询 panda df 以过滤列不是 Nan 的行

python - python中的LDAP查询

python - 识别数组中的数字组(图像的组像素)

c - OpenCV 2.3 中的 cvaux230d.lib 在哪里?