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

2024-10-04 01:23:05 发布

您现在位置:Python中文网/ 问答频道 /正文

在从表中提取行后,我将倒置的二值化图像保存为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

Tags: 图像importpdfpngmatplotlib错误pltcv2