简体   繁体   English

TypeError:图像数据无法转换为少量图像浮动

[英]TypeError: Image data cannot be converted to float for few images

I am trying to recognize face using opencv. 我正在尝试使用opencv识别人脸。 Below is my code. 下面是我的代码。

img = cv2.imread('C:/Users/user/Desktop/az5.jpg')
img1 = cv2.imread('C:/Users/user/Desktop/az5.jpg')
 def detect_face(img):
 face_img = img.copy()
 face_rects = face_cascade.detectMultiScale(face_img)

for (x,y,w,h) in face_rects:
    cv2.rectangle(face_img,(x,y),(x+w,y+h),(255,255,255),5)
    return face_img

Here in few cases it is giving me desired o/p . 在少数情况下,它给我所需的o / p。 But in few cases it is throwing below error. 但在少数情况下,它抛出的错误低于错误。

TypeError                                 Traceback (most recent call 
last)
 <ipython-input-267-1c156f77ac76> in <module>
  1 result1 = detect_face(img1)
 ----> 2 plt.imshow((result1))

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in 
 imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, 
extent, shape, filternorm, filterrad, imlim, resample, url, data, 
**kwargs)
   2697         filternorm=filternorm, filterrad=filterrad, imlim=imlim,
 2698         resample=resample, url=url, **({"data": data} if data is 
 not
    -> 2699         None else {}), **kwargs)
  2700     sci(__ret)
 2701     return __ret

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in 
   inner(ax, data, *args, **kwargs)
  1808                         "the Matplotlib list!)" % (label_namer, 
    func.__name__),
   1809                         RuntimeWarning, stacklevel=2)
   -> 1810             return func(ax, *args, **kwargs)
 1811 
 1812         inner.__doc__ = _add_data_doc(inner.__doc__,

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in 
imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, 
origin, extent, shape, filternorm, filterrad, imlim, resample, url, 
**kwargs)
  5492                               resample=resample, **kwargs)
 5493 
-> 5494         im.set_data(X)
  5495         im.set_alpha(alpha)
  5496         if im.get_clip_path() is None:

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\image.py in 
set_data(self, A)
    632         if (self._A.dtype != np.uint8 and
  633                 not np.can_cast(self._A.dtype, float, 
 "same_kind")):
 --> 634             raise TypeError("Image data cannot be converted to 
float")
  635 
  636         if not (self._A.ndim == 2

 TypeError: Image data cannot be converted to float

我没有得到这张照片的o / p。

Could anyone please help me. 谁能帮我。 I have attached the below screenshot of my o/p. 我已附上以下O / P屏幕截图。 输出2张图像

Probably face_img is None for some images. 对于某些图像, face_img可能为“ None ”。 you can check(print) nimber of detected faces to ensure that face_img is not None . 您可以检查(打印)检测到的面孔的木材号,以确保face_img不是None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError: 图片数据不能转换为float // 导入.png图片时 - TypeError: Image data cannot be converted to float // When importing .png images 类型错误:图像数据无法转换为浮点数 - TypeError: Image data cannot be converted to float 类型错误:无法将图像数据转换为浮点数 无法将图像数据转换为浮点数 - TypeError: Image data cannot be converted to float Image data cannot be converted to float matplotlib.image.imsave TypeError:无法将图像数据转换为float - matplotlib.image.imsave TypeError: Image data cannot be converted to float Python OpenCV 错误:“类型错误:图像数据无法转换为浮点数” - Python OpenCV Error: “TypeError: Image data cannot be converted to float” plt.imshow()给出TypeError(“图像数据无法转换为浮点数”) - plt.imshow() giving TypeError(“Image data cannot be converted to float”) TypeError:加载.npy文件时,图像数据无法转换为float - TypeError: Image data cannot be converted to float while loading .npy file TypeError: dtype object 的图像数据无法转换为浮点数修复 - TypeError: Image data of dtype object cannot be converted to float Fix 类型错误:dtype 对象的图像数据无法转换为浮点数 - TypeError: Image data of dtype object cannot be converted to float TypeError:图像数据无法在 wordcloud 项目上转换为浮点数 - TypeError: Image data cannot be converted to float on wordcloud project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM