dtype对象的图像数据无法转换为float

问题描述

基本上,我在第二列中有一个带有图像URL的数据框。因此,我一直在使用下面的代码从URL下载图像:

# downloading the images from url
for i in range(0,len(table.index)):
  # This is the column with the image urls.
  image_url = refined_data.iloc[i,1]
  # Open the url image,set stream to True,this will return the stream content.
  resp = requests.get(image_url,stream=True)
  # Open a local file with wb ( write binary ) permission.
  local_file = open('local_image' + str(i),'wb')
  # Set decode_content value to True,otherwise the downloaded image file's size will be zero.
  resp.raw.decode_content = True
  # copy the response stream raw data to local image file.
  shutil.copyfileobj(resp.raw,local_file)
  # Remove the image url response object.
  del resp

但是,尽管可以读取和显示所有下载的图像,但是由于“ TypeError:dtype对象的图像数据无法转换为float”问题而无法读取最后一张图像。我不确定这是由于从URL检索图像的代码错误还是下游的问题。这是我用来显示图像的代码示例。

#displaying the images to check
%pylab inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img=mpimg.imread('local_image114')
imgplot = plt.imshow(img)
plt.show()

在这种情况下,local_image114是要检索的最后一个图像,因此python给出了错误

TypeError                                 Traceback (most recent call last)
<ipython-input-24-ad17d3d6531e> in <module>()
      4 import matplotlib.image as mpimg
      5 img=mpimg.imread('local_image114')
----> 6 imgplot = plt.imshow(img)
      7 plt.show()

5 frames
/usr/local/lib/python3.6/dist-packages/matplotlib/image.py in set_data(self,A)
    692                 not np.can_cast(self._A.dtype,float,"same_kind")):
    693             raise TypeError("Image data of dtype {} cannot be converted to "
--> 694                             "float".format(self._A.dtype))
    695 
    696         if not (self._A.ndim == 2

TypeError: Image data of dtype object cannot be converted to float

有人知道如何解决此问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...