图像数据不能转换为浮点错误?



我正在尝试检测人脸并在人脸对齐后返回img相应的地标。这是我的代码:

def getIthFrame(self, i):
img = self.data.get_data(i)
raw_img = Image.fromarray(img)
w, h = raw_img.size
if self.pos == "center":
img, landmarks = self.detectLandmarks(raw_img)
elif self.pos == "left": 
img, landmarks = self.detectLandmarks(raw_img.crop(box=(0,0, w//2, h)))
elif self.pos == "right":
img, landmarks = self.detectLandmarks(raw_img.crop(box=(w//2,0, w, h)))
elif self.pos == "90": # face oriented to right
img, landmarks = self.detectLandmarks(raw_img.rotate(90)) # rotate anticlockwise 90
elif self.pos == "180": # face oriented to down
img, landmarks = self.detectLandmarks(raw_img.rotate(180))
elif self.pos == "270": # face oriented to left
img, landmarks = self.detectLandmarks(raw_img.rotate(270))
if landmarks is None: return None, None #  landmark detection fail
img, landmarks = normalize(img, landmarks)
return img, landmarks
def showImgLandmarks(self, img, landmarks=None, ax=None):
"""
visualize i-th frame with landmarks
"""
if ax is None:
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.imshow(img)
if landmarks is not None:
ax.scatter(landmarks[:,0], landmarks[...,1])
for i in range(landmarks.shape[0]):
ax.text(landmarks[i,0], landmarks[i,1], i)
plt.show()
face_detector = dlib.get_frontal_face_detector()
landmark_detector = dlib.shape_predictor('./shape_predictor_68_face_landmarks.dat')
extractor = FrameExtract(face_detector, landmark_detector)
extractor.showImgLandmarks(*extractor.getIthFrame(0))

然而,当我试图查看我的数据集中的图像时,我得到TypeError: dtype对象的图像数据不能转换为float。我得到以下错误信息:

extractor.showImgLandmarks(*extractor.getIthFrame(0))

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-3429da19673c> in <module>
----> 1 extractor.showImgLandmarks(*extractor.getIthFrame(0))
<ipython-input-3-6cc47ac83d27> in showImgLandmarks(self, img, landmarks, ax)
62             fig = plt.figure()
63             ax = fig.add_subplot(1,1,1)
---> 64         ax.imshow(img)
65         if landmarks is not None:
66             ax.scatter(landmarks[:,0], landmarks[...,1])
C:ProgramDataAnaconda3libsite-packagesmatplotlib__init__.py in inner(ax, data, *args, **kwargs)
1563     def inner(ax, *args, data=None, **kwargs):
1564         if data is None:
-> 1565             return func(ax, *map(sanitize_sequence, args), **kwargs)
1566 
1567         bound = new_sig.bind(ax, *args, **kwargs)
C:ProgramDataAnaconda3libsite-packagesmatplotlibcbookdeprecation.py in wrapper(*args, **kwargs)
356                 f"%(removal)s.  If any parameter follows {name!r}, they "
357                 f"should be pass as keyword, not positionally.")
--> 358         return func(*args, **kwargs)
359 
360     return wrapper
C:ProgramDataAnaconda3libsite-packagesmatplotlibcbookdeprecation.py in wrapper(*args, **kwargs)
356                 f"%(removal)s.  If any parameter follows {name!r}, they "
357                 f"should be pass as keyword, not positionally.")
--> 358         return func(*args, **kwargs)
359 
360     return wrapper
C:ProgramDataAnaconda3libsite-packagesmatplotlibaxes_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
5624                               resample=resample, **kwargs)
5625 
-> 5626         im.set_data(X)
5627         im.set_alpha(alpha)
5628         if im.get_clip_path() is None:
C:ProgramDataAnaconda3libsite-packagesmatplotlibimage.py in set_data(self, A)
691         if (self._A.dtype != np.uint8 and
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 
TypeError: Image data of dtype object cannot be converted to float

我正在尝试从视频中提取顶点帧和中性帧。(我的输入数据是一个视频)。

video_path = './videos/mmi-facial-expression-database_download_2019-05 13_03_06_41/Sessions/2/S001-002.avi'
video_ID = 1
save_path = './onset_apex_pairs/0002'

相关内容

  • 没有找到相关文章

最新更新