微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过dlib人脸检测程序打印/存储点坐标

如何解决通过dlib人脸检测程序打印/存储点坐标

我尝试使用此thread解决我的python问题,但进展不远。

我目前正在做什么: 我正在练习面部界标检测。 我遵循了一些教程,并成功地将face landmark positions标识为选择的图像。

Obama

我要解决的问题:我试图找到每个面部界标位置的确切坐标,如排名最高的答案here中所示。我假设我的终端已经朝着正确的方向指点我。

Coodrinates

请在下面查看我的脚本。

脚本

# construct the argument parser and parse the arguments

ap = argparse.ArgumentParser()
ap.add_argument("-p","--shape-predictor",required=True,help="path to facial landmark predictor")
ap.add_argument("-i","--image",help="path to input image")
args = vars(ap.parse_args())

# initialize dlib's face detector (HOG-based) and then create
# the facial landmark predictor

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(args["shape_predictor"])

# load the input image,resize it,and convert it to grayscale

image = cv2.imread(args["image"])
image = imutils.resize(image,width=500)
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

# detect faces in the grayscale image
rects = detector(gray,1)

# loop over the face detections

for (i,rect) in enumerate(rects):
    # determine the facial landmarks for the face region,then
    # convert the facial landmark (x,y)-coordinates to a NumPy
    # array

    shape = predictor(gray,rect)
    shape = face_utils.shape_to_np(shape)

    # convert dlib's rectangle to a OpenCV-style bounding Box
    # [i.e.,(x,y,w,h)],then draw the face bounding Box

    (x,h) = face_utils.rect_to_bb(rect)
    cv2.rectangle(image,y),(x + w,y + h),(0,255,0),2)

    # show the face number
    cv2.putText(image,"Face #{}".format(i + 1),(x - 10,y - 10),cv2.FONT_HERShey_SIMPLEX,0.5,2)

    # loop over the (x,y)-coordinates for the facial landmarks
    # and draw them on the image

    for (x,y) in shape:
        cv2.circle(image,1,255),-1)


# show the output image with the face detections + facial landmarks

cv2.imshow("Output",image)
cv2.waitKey(0)

我遵循的教程构造了参数和解析器,这意味着我需要在终端中运行此脚本以获得我的输出图像:

python facial_landmarks.py --shape-predictor shape_predictor_68_face_landmarks.dat \
--image images/picofchoice.png

我希望您能如何帮助我

  1. 一种打印68个界标位置及其坐标(x / y)的完整列表的方法
  2. 有关如何更好地理解参数解析器的文档/帮助
  3. 文档/文档帮助,我需要在终端中运行才能在1中打印坐标。

非常感谢。祝你有美好的一天。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。