日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python dlib学习(七):人脸特征点对齐

發布時間:2025/3/21 python 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python dlib学习(七):人脸特征点对齐 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

前面的博客介紹過人臉特征點標定:python dlib學習(二):人臉特征點標定。這次試著使用這些人臉特征點來對人臉進行對齊。
完整工程鏈接附在文章最后。

程序

上代碼,程序中使用了python-opencv,事先要配置好環境。
我們在程序中會導入識別人臉特征點的模型,官方例程給出的模型的鏈接:
http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2(5個特征點)
我使用的跟前面博客(python dlib學習(二):人臉特征點標定)中的一樣,是檢測人臉68個特征點的模型。
下載鏈接:http://pan.baidu.com/s/1i46vPu1。

程序中已有注釋,不做贅述。

# coding: utf-8 import cv2 import dlib import sys import numpy as np import os# 獲取當前路徑 current_path = os.getcwd() # 指定你存放的模型的路徑,我使用的是檢測68個特征點的那個模型, # predicter_path = current_path + '/model/shape_predictor_5_face_landmarks.dat'# 檢測人臉特征點的模型放在當前文件夾中 predicter_path = current_path + '/model/shape_predictor_68_face_landmarks.dat' face_file_path = current_path + '/faces/inesta.jpg'# 要使用的圖片,圖片放在當前文件夾中 print predicter_path print face_file_path# 導入人臉檢測模型 detector = dlib.get_frontal_face_detector() # 導入檢測人臉特征點的模型 sp = dlib.shape_predictor(predicter_path)# 讀入圖片 bgr_img = cv2.imread(face_file_path) if bgr_img is None:print("Sorry, we could not load '{}' as an image".format(face_file_path))exit()# opencv的顏色空間是BGR,需要轉為RGB才能用在dlib中 rgb_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB) # 檢測圖片中的人臉 dets = detector(rgb_img, 1) # 檢測到的人臉數量 num_faces = len(dets) if num_faces == 0:print("Sorry, there were no faces found in '{}'".format(face_file_path))exit()# 識別人臉特征點,并保存下來 faces = dlib.full_object_detections() for det in dets:faces.append(sp(rgb_img, det))# 人臉對齊 images = dlib.get_face_chips(rgb_img, faces, size=320) # 顯示計數,按照這個計數創建窗口 image_cnt = 0 # 顯示對齊結果 for image in images:image_cnt += 1cv_rgb_image = np.array(image).astype(np.uint8)# 先轉換為numpy數組cv_bgr_image = cv2.cvtColor(cv_rgb_image, cv2.COLOR_RGB2BGR)# opencv下顏色空間為bgr,所以從rgb轉換為bgrcv2.imshow('%s'%(image_cnt), cv_bgr_image)cv2.waitKey(0) cv2.destroyAllWindows()

運行結果

原圖:

完整工程下載鏈接:
http://download.csdn.net/download/hongbin_xu/10115082

總結

以上是生活随笔為你收集整理的python dlib学习(七):人脸特征点对齐的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。