skimage.color.rgb2gray导入麻烦

问题描述 投票:1回答:3

我在导入skimage.color模块时遇到问题。虽然我可以从python shell导入和调用skimage.color.rgb2gray,但我不能在我的应用程序中做同样的事情。

我在我的电脑上检查了skimage lib的位置。他们似乎都很好。但是当我试着打电话给skimage.color时。从我的代码,它总是给我这个

Traceback (most recent call last):
File "main-video2.py", line 44, in <module>
image = color.rgb2gray(image)

我检查了这个模块

username@ubuntu:~/dev/computer_vision$ python 
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> 
 KeyboardInterrupt
 >>> from skimage import color 
 >>> color 
 <module 'skimage.color' from '/usr/local/lib/python2.7/dist-packages/skimage/color/__init__.pyc'>

任何人都可以帮助我理解为什么我能够从shell调用它而不是从我的代码中调用它?

python image-processing computer-vision scikit-image
3个回答
3
投票

我认为您的PC上没有安装其他库。检查THIS PAGE并验证您是否具有运行时应用程序所需的库。

出现此错误的原因是因为尽管skimage包可能存在且可用(在python shell中),但如果没有其他提到的包的支持,您将无法运行任何应用程序:matplotlibscipypilnumpysix

访问链接以安装/更新所需的软件包。

如果您仍有问题,请发表评论。 :)


1
投票

我有另一种选择。您可以使用以下代码将rgb图像转换为灰色:

# libraries
import cv2
import Image

# reading an image
image = cv2.imread(path_to_image)

# converting into gray image
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# saving image
Image.fromarray(gray_image).save(save_path)

0
投票

如果您使用anaconda,重新启动内核有助于解决问题。该错误是由于skimage.color包本身内的循环导入。在常规代码中,尝试from skimage.io import imshow。救了我很多时间More on the subject

© www.soinside.com 2019 - 2024. All rights reserved.