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

时间:2019-08-31 09:30:29

标签: python opencv face-recognition

我正在尝试使用opencv识别人脸。下面是我的代码。

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

在少数情况下,这给了我所需的o / p。但是在少数情况下 抛出以下错误。

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

I am not getting o/p for this pic.

任何人都可以帮助我。我已附上以下O / P屏幕截图。 Output of 2 images

1 个答案:

答案 0 :(得分:0)

对于某些图像,router.post('/messages', requireToken, (req, res, next) => { // grab the id from the request const socketId = req.body.message.socketId // get the io object ref const io = req.app.get('socketio') // create a ref to the client socket const senderSocket = io.sockets.connected[socketId] Message.create(req.body.message) .then(message => { // in case the client was disconnected after the request was sent // and there's no longer a socket with that id if (senderSocket) { // use broadcast.emit to message everyone except the original // sender of the request !!! senderSocket.broadcast.emit('message broadcast', { message }) } res.status(201).json({ message: message.toObject() }) }) .catch(next) }) 可能是face_img。您可以检查(打印)检测到的人脸,以确保None不是face_img