【问题标题】:python: Unexpected version found while deserializing dlib::shape_predictorpython:反序列化 dlib::shape_predictor 时发现意外版本
【发布时间】:2018-09-11 20:35:54
【问题描述】:

我正在尝试使用 python27 (IDLE) 从图像中获取面部标志。当我运行下面的代码时,我得到了输出:

Traceback(最近一次调用最后一次): 文件“C:\Users\matth\Desktop\testmctest.py”,第 11 行,在 预测器 = dlib.shape_predictor(PREDICTOR_PATH) RuntimeError: 反序列化 dlib::shape_predictor 时发现意外版本。

使用 dlib 版本 19.10(存储在我的桌面上) 使用来自http://dlib.net/files/ 的 shape_predictor_68_face_landmarks.dat.bz2 文件(存储在我的 python 文件夹内的 c 驱动器上)

import numpy 
import cv2
import dlib

 PREDICTOR_PATH = "C:/Python27/shape_predictor_68_face_landmarks.dat.bz2"
 predictor = dlib.shape_predictor(PREDICTOR_PATH)
 cascade_path='haarcascade_frontalface_default.xml'
 cascade = cv2.CascadeClassifier(cascade_path)


def get_landmarks(im):
  rects = cascade.detectMultiScale(im, 1.3,5)
 x,y,w,h =rects[0]
 rect=dlib.rectangle(x,y,x+w,y+h)
return numpy.matrix([[p.x, p.y] for p in predictor(im, rect).parts()])

def annotate_landmarks(im, landmarks):
im = im.copy()
for idx, point in enumerate(landmarks):
    pos = (point[0, 0], point[0, 1])
    cv2.putText(im, str(idx), pos,
                fontFace=cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
                fontScale=0.4,
                color=(0, 0, 255))
    cv2.circle(im, pos, 3, color=(0, 255, 255))
return im

im=cv2.imread('face_leo1.jpg')
cv2.imshow('Result',annotate_landmarks(im,get_landmarks(im)))
cv2.waitKey(0)
cv2.destroyAllWindows()

【问题讨论】:

    标签: python face-recognition dlib


    【解决方案1】:

    dlib 和 shape_predictor_68_face_landmarks.dat.bz2 不“同步” 通过使用 The github page 修复

    【讨论】:

    【解决方案2】:

    要解决此问题,请先提取 bz2 存档并使用 .dat 文件作为输入创建 dlib.shape_predictor

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-15
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 2011-09-20
      • 2011-11-22
      相关资源
      最近更新 更多