【问题标题】:TypeError: Image data cannot be converted to float // When importing .png imagesTypeError: 图片数据不能转换为浮点数 // 导入.png图片时
【发布时间】:2020-08-06 13:10:37
【问题描述】:

在从表格中提取行为 png 后,我保存了倒置的二值化图像(使用 opencv 完成)。现在,当我尝试使用 opencv 或 matplotlib 加载它们时,它会在标题中显示 NoneType 或错误。我检查了许多具有相同错误的不同帖子。我想这与图像数据有关。

import cv2
import matplotlib.pyplot as plt


imgs = cv2.imread('Users/marius/Desktop/PDF/imgvh/1.png')
cv2.imshow('Users/marius/Desktop/PDF/imgvh/1.png', imgs)

使用cv2时出现的错误:

cv2.error: OpenCV(4.2.0) /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

这样使用matplotlib:

imgs = plt.imshow('Users/marius/Desktop/PDF/imgvh/1.png')
plt.show()

导致以下错误:

TypeError: Image data of dtype <U49 cannot be converted to float

【问题讨论】:

  • 我认为 Stack Overflow 服务器更改了您的共享文件。请问您也可以通过其他方法分享吗?保管箱?谷歌云端硬盘?
  • @Mark Setchell 我刚刚又上传了!

标签: python opencv image-processing png typeerror


【解决方案1】:

OpenCV 部分不起作用,因为您省略了Users/marius... 前面路径开头的斜线。应该是:

imgs = cv2.imread('/Users/marius/Desktop/PDF/imgvh/1.png')

ma​​tplotlib 部分不起作用,因为它应该是:

imgs = cv2.imread('/Users/marius...')

plt.imshow(imgs)
plt.show()  

【讨论】:

  • 不敢相信我没有看到。我搜索了几个小时。非常感谢。有时你只见树木不见森林......
猜你喜欢
  • 1970-01-01
  • 2019-11-04
  • 1970-01-01
  • 2015-11-24
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 2023-03-14
相关资源
最近更新 更多