在python中闪烁多个图像



我是新的python和我正在闪烁(显示)像516个图像在一个去工作。以前有很多这样的问题,但没有一个能帮助我。下面是代码

import cv2
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
for i in range(1,516,1):
    #a=cv2.imread('test01001.tif')
    abb=cv2.imread('This PCG:TRAINING1test0100%d.tif'%(i))
    cv2.imshow('test0100%d.tif'%(i),abb)
plt.show()

显示的错误是

Using matplotlib backend: Qt4Agg
Populating the interactive namespace from numpy and matplotlib
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-10-709418c86b86> in <module>()
      7     #a=cv2.imread('test01001.tif')
      8     abb=cv2.imread('This PCG:TRAINING1test0100%d.png'%(i))
----> 9     cv2.imshow('test0100%d.tif'%(i),abb)
     10 
     11 plt.show()
error: ........opencvmoduleshighguisrcwindow.cpp:266: error: (-215) size.width>0 && size.height>0 in function cv::imshow

请帮帮我。我一直试图纠正这个错误从许多天,但没有帮助我。如果代码也张贴在答案,我会很感激谢谢你。

调试代码
Using matplotlib backend: Qt4Agg
Populating the interactive namespace from numpy and matplotlib
> <ipython-input-2-d89d3a2017ad>(11)<module>()
-> cv2.imshow('test0100%d.tif'%(i),abb)
(Pdb) n
error: '..\..\..\..\opencv\modules\highgui\src\window.cpp:266: error: (-215) size.width>0 && size.height>0 in function cv::imshown'
> <ipython-input-2-d89d3a2017ad>(11)<module>()
-> cv2.imshow('test0100%d.tif'%(i),abb)
(Pdb) n
--Return--
> <ipython-input-2-d89d3a2017ad>(11)<module>()->None
-> cv2.imshow('test0100%d.tif'%(i),abb)
(Pdb) n
error: '..\..\..\..\opencv\modules\highgui\src\window.cpp:266: error: (-215) size.width>0 && size.height>0 in function cv::imshown'
> c:anaconda2libsite-packagesipythoncoreinteractiveshell.py(3066)run_code()
-> exec(code_obj, self.user_global_ns, self.user_ns)
(Pdb) n
> c:anaconda2libsite-packagesipythoncoreinteractiveshell.py(3069)run_code()
-> sys.excepthook = old_excepthook
(Pdb) n
> c:anaconda2libsite-packagesipythoncoreinteractiveshell.py(3070)run_code()
-> except SystemExit as e:
(Pdb) n
> c:anaconda2libsite-packagesipythoncoreinteractiveshell.py(3075)run_code()
-> except self.custom_exceptions:
(Pdb) n
> c:anaconda2libsite-packagesipythoncoreinteractiveshell.py(3080)run_code()
-> except:
(Pdb) n
> c:anaconda2libsite-packagesipythoncoreinteractiveshell.py(3081)run_code()
-> if result is not None:
(Pdb) n
> c:anaconda2libsite-packagesipythoncoreinteractiveshell.py(3082)run_code()
-> result.error_in_exec = sys.exc_info()[1]
(Pdb) n
> c:anaconda2libsite-packagesipythoncoreinteractiveshell.py(3083)run_code()
-> self.showtraceback()

您的imread的文件路径很可能无效,因此您无法在abb中获得适当的图像,然后当然无法显示,因此您得到有关图像大小的错误。

你可以使用python os模块来导航目录,而且你不需要绘制flash图像。

import cv2
import os         # import os module
path = r"G:TRAINING1"
img_names = os.listdir(path) # return all image names in given path
for name in img_names:
    im = cv2.imread( os.path.join(path,name) )
    cv2.imshow('image' ,im)
    cv2.waitKey(300)  # no of millisecond to wait for next image
cv2.destroyAllWindows()

相关内容

  • 没有找到相关文章