python 人脸轮廓提取_深度学习(PYTORCH)-2.python调用dlib提取人脸68个特征点
在看官方教程时,无意中发现别人写的一个脚本,非常简洁。官方教程地址:http://pytorch.org/tutorials/beginner/data_loading_tutorial.html#sphx-glr-beginner-data-loading-tutorial-py使用的是dlib自带的特征点检测库,初期用来测试还是不错的1 from __future__ import print
在看官方教程时,无意中发现别人写的一个脚本,非常简洁。
官方教程地址:http://pytorch.org/tutorials/beginner/data_loading_tutorial.html#sphx-glr-beginner-data-loading-tutorial-py
使用的是dlib自带的特征点检测库,初期用来测试还是不错的
1 from __future__ import print_function, division
2 import os
3 import torch
4 import pandas as pd
5 from skimage import io, transform
6 import numpy as np
7 import matplotlib.pyplot as plt
8 from torch.utils.data import Dataset, DataLoader
9 from torchvision import transforms, utils
10
11 # Ignore warnings
12 import warnings
13 warnings.filterwarnings("ignore")
14
15 plt.ion() # interactive mode
16
17 landmarks_frame = pd.read_csv('faces/face_landmarks.csv')
18
19 n = 5
20 img_name = landmarks_frame.iloc[n, 0]
21 landmarks = landmarks_frame.iloc[n, 1:].as_matrix()
22 landmarks = landmarks.astype('float').reshape(-1, 2)
23
24 print('Image name: {}'.format(img_name))
25 print('Landmarks shape: {}'.format(landmarks.shape))
26 print('First 4 Landmarks: {}'.format(landmarks[:4]))
27
28 def show_landmarks(image, landmarks):
29 """Show image with landmarks"""
30 plt.imshow(image)
31 plt.scatter(landmarks[:, 0], landmarks[:, 1], s=10, marker='.', c='r')
32 plt.pause(0.001) # pause a bit so that plots are updated
33
34 plt.figure()
35 show_landmarks(io.imread(os.path.join('faces/', img_name)),
36 landmarks)
37 plt.show()
View Code
效果图:

更多推荐
所有评论(0)