如何使用Scikit-Image库在Python中显示jpg图像

时间:2016-07-22 13:59:08

标签: python opencv scikit-image

尝试完成一个简单的学校练习,但我一开始就陷入困境。 这是不起作用的代码:

from skimage import io

img = io.imread('mypic.jpg')
io.imshow(img)
io.show()

执行后我收到此错误:

Exception in Tkinter callback Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
return self.func(*args)
File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 283, in resize
self.show()
File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 355, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/usr/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 26, in blit
_tkagg.tkinit(tk.interpaddr(), 1)

OverflowError: Python int too large to convert to C long

我也尝试过与OpenCV库相同的东西,我得到了类似的结果: 代码

import numpy as np
import cv2

img = cv2.imread('mypic.jpg',0)
cv2.imshow('image',img)
waitKey(0)

错误:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /builddir/build/BUILD/opencv-2.4.12.3/modules/highgui/src/window.cpp, line 261
Traceback (most recent call last):
File "imagetry.py", line 6, in <module>
cv2.imshow('lasta',img)
cv2.error: /builddir/build/BUILD/opencv-2.4.12.3/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

我在32位Fedora 24和Python 2.7上运行它。 我将衷心感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

使用开放式CV在python中读取图像的基本方法如下

import cv2

img = cv2.imread('mypic.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

答案 1 :(得分:0)

使用cv2.waitKey(0)代替waitkey(0)