【问题标题】:"AttributeError: module 'cv2' has no attribute 'imread'" using jupyter notebook“AttributeError:模块'cv2'没有属性'imread'”使用jupyter笔记本
【发布时间】:2021-05-14 04:46:59
【问题描述】:

我正在使用 Jupyter 笔记本,但出现此错误

AttributeError: 模块 'cv2' 没有属性 'imread'

成功运行命令后

import cv2
import matplotlib.pyplot as plt
dir(cv2)

输出为

['doc',
'file',
'loader',
'name',
'package',
'path',
'spec']

如何在 Jupyter notebook 中读取图像?

【问题讨论】:

  • 你能发布完整的错误堆栈吗?
  • 我猜你已经创建了自己的文件cv2.py。这将首先加载。
  • @sociopath 这里是完整的错误堆栈 AttributeError Traceback(最近一次调用最后一次) in 2 import matplotlib.pyplot as plt 3 img1path=r"C: \Users\DELL\Downloads\Image034" ----> 4 img1 = cv2.imread(img1path) 5 plt.imshow(img1) AttributeError: module 'cv2' has no attribute 'imread'
  • @TimRoberts 我没有创建任何这样的文件
  • import cv2 / print(cv2.__file__) / print(cv2.__version__)

标签: python jupyter-notebook


【解决方案1】:

这是使用 cv2 读取图像并显示在 python notebook 中的简单代码 sn-p

import cv2
%matplotlib inline
import matplotlib.pyplot as plt
image = cv2.imread('/home/venkatesh/Pictures/my_image.jpg')
rgb_img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.imshow(rgb_img)
plt.show()

【讨论】:

  • 我的代码和你的类似...我找不到我做错的地方 import cv2 import matplotlib.pyplot as plt img1path=r"C:\Users\DELL\Downloads\Image034" img1 = cv2.imread(img1path) plt.imshow(img1)
猜你喜欢
  • 2018-05-31
  • 1970-01-01
  • 2017-11-22
  • 2019-07-25
  • 2017-11-21
  • 2021-02-17
  • 2019-11-13
  • 2018-11-13
  • 2019-05-28
相关资源
最近更新 更多