我从表格中提取行作为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
最佳答案
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/