python - TypeError:图像数据无法转换为float//导入.png图像时

标签 python opencv image-processing png typeerror

我从表格中提取行作为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)

enter image description here

使用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

最佳答案

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

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

matplotlib 部分不起作用,因为它应该是:
imgs = cv2.imread('/Users/marius...')

plt.imshow(imgs)
plt.show()  

关于python - TypeError:图像数据无法转换为float//导入.png图像时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61383339/

相关文章:

image - 8 位彩色图像矩阵表示

matlab - 隐马尔可夫模型工具箱/库

python - 自定义对象训练 Tensor-flow 错误

Android NDK 构建以支持所有可用设备

python - 使用 jpg 格式将 numpy 数组保存为 io.BytesIO

python - 如何从数据框中删除任何行中包含特定值的列

Silverlight 图像编辑器控件

python - 在Raspberry Pi上通过OpenCV编写的视频未运行

python - 给定词典索引查找多集排列的算法

python - 获取 pandas.read_csv 将空字段读取为 NaN,将空字符串读取为空字符串