[英]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
Could anyone please help me. 谁能帮我。 I have attached the below screenshot of my o/p. 我已附上以下O / P屏幕截图。
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.