国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

python使用dlib進行人臉檢測和關鍵點的示例

瀏覽:4日期:2022-07-03 10:28:52

#!/usr/bin/env python# -*- coding:utf-8-*-# file: {NAME}.py# @author: jory.d# @contact: [email protected]# @time: 2020/04/10 19:42# @desc: 使用dlib進行人臉檢測和人臉關鍵點import cv2import numpy as npimport globimport dlibFACE_DETECT_PATH = ’/home/build/dlib-v19.18/data/mmod_human_face_detector.dat’FACE_LANDMAKR_5_PATH = ’/home/build/dlib-v19.18/data/shape_predictor_5_face_landmarks.dat’FACE_LANDMAKR_68_PATH = ’/home/build/dlib-v19.18/data/shape_predictor_68_face_landmarks.dat’def face_detect(): root = ’/media/dangxs/E/Project/DataSet/VGG Face Dataset/vgg_face_dataset/vgg_face_dataset/vgg_face_dataset’ imgs = glob.glob(root + ’/**/*.jpg’, recursive=True) assert len(imgs) > 0 detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(FACE_LANDMAKR_68_PATH) for f in imgs: img = cv2.imread(f) # The 1 in the second argument indicates that we should upsample the image # 1 time. This will make everything bigger and allow us to detect more # faces. dets = detector(img, 1) print('Number of faces detected: {}'.format(len(dets))) for i, d in enumerate(dets): x1, y1, x2, y2 = d.left(), d.top(), d.right(), d.bottom() print('Detection {}: Left: {} Top: {} Right: {} Bottom: {}'.format(i, x1, y1, x2, y2)) cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 1) # Get the landmarks/parts for the face in box d. shape = predictor(img, d) print('Part 0: {}, Part 1: {} ...'.format(shape.part(0), shape.part(1))) # # Draw the face landmarks on the screen. ’’’ # landmark 順序: 外輪廓 - 左眉毛 - 右眉毛 - 鼻子 - 左眼 - 右眼 - 嘴巴 ’’’ for i in range(shape.num_parts):x, y = shape.part(i).x, shape.part(i).ycv2.circle(img, (x, y), 2, (0, 0, 255), 1)cv2.putText(img, str(i), (x, y), cv2.FONT_HERSHEY_COMPLEX, 0.3, (0, 0, 255), 1) cv2.resize(img, dsize=None, dst=img, fx=2, fy=2) cv2.imshow(’w’, img) cv2.waitKey(0)def face_detect_mask(): root = ’/media/dangxs/E/Project/DataSet/VGG Face Dataset/vgg_face_dataset/vgg_face_dataset/vgg_face_dataset’ imgs = glob.glob(root + ’/**/*.jpg’, recursive=True) assert len(imgs) > 0 detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(FACE_LANDMAKR_68_PATH) for f in imgs: img = cv2.imread(f) # The 1 in the second argument indicates that we should upsample the image # 1 time. This will make everything bigger and allow us to detect more # faces. dets = detector(img, 1) print('Number of faces detected: {}'.format(len(dets))) for i, d in enumerate(dets): x1, y1, x2, y2 = d.left(), d.top(), d.right(), d.bottom() print('Detection {}: Left: {} Top: {} Right: {} Bottom: {}'.format(i, x1, y1, x2, y2)) cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 1) # Get the landmarks/parts for the face in box d. shape = predictor(img, d) print('Part 0: {}, Part 1: {} ...'.format(shape.part(0), shape.part(1))) # # Draw the face landmarks on the screen. ’’’ # landmark 順序: 外輪廓 - 左眉毛 - 右眉毛 - 鼻子 - 左眼 - 右眼 - 嘴巴 ’’’ points = [] for i in range(shape.num_parts):x, y = shape.part(i).x, shape.part(i).yif i < 26: points.append([x, y])# cv2.circle(img, (x, y), 2, (0, 0, 255), 1)# cv2.putText(img, str(i), (x,y),cv2.FONT_HERSHEY_COMPLEX, 0.3 ,(0,0,255),1) # 只把臉切出來 points[17:] = points[17:][::-1] points = np.asarray(points, np.int32).reshape(-1, 1, 2) img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) black_img = np.zeros_like(img) cv2.polylines(black_img, [points], 1, 255) cv2.fillPoly(black_img, [points], (1, 1, 1)) mask = black_img masked_bgr = img * mask # 位運算時需要轉化成灰度圖像 mask_gray = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY) masked_gray = cv2.bitwise_and(img_gray, img_gray, mask=mask_gray) cv2.resize(img, dsize=None, dst=img, fx=2, fy=2) cv2.imshow(’w’, img) cv2.imshow(’mask’, mask) cv2.imshow(’mask2’, masked_gray) cv2.imshow(’mask3’, masked_bgr) cv2.waitKey(0)if __name__ == ’__main__’: face_detect()

python使用dlib進行人臉檢測和關鍵點的示例

python使用dlib進行人臉檢測和關鍵點的示例

python使用dlib進行人臉檢測和關鍵點的示例

以上就是python使用dlib進行人臉檢測和關鍵點的示例的詳細內容,更多關于python 人臉檢測的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 日韩一级片视频 | 免费一级欧美大片久久网 | 国产精品国三级国产aⅴ | 午夜爽爽爽 | 国产美女做爰免费视频网址 | 国产中文久久精品 | 三级成人网 | 亚洲国产欧美在线人成精品一区二区 | 久久久国产精品免费看 | 一级毛片免费不卡在线视频 | 有码视频在线观看 | 亚洲福利影视 | 日产一区两区三区四区 | 国产精品欧美一区二区三区不卡 | 亚洲www.| 国产一区二区三区精品久久呦 | 狠狠色婷婷丁香综合久久韩国 | 亚洲一区免费视频 | 国内美女福利视频在线观看网站 | 亚洲国产精品一区二区三区在线观看 | 九色97 | 日韩欧美一级毛片精品6 | 久久精品视频久久 | 国产精品国产三级国产普通 | 新版天堂资源中文在线 | 久久爱91| 真人毛片 | 成年人在线免费 | 久久一区二区三区免费 | 91久久精品一区二区三区 | 国产成人精品一区二区三在线观看 | 一级片在线播放 | 99爱视频99爱在线观看免费 | 热久久91| 黄色三级在线播放 | 91久久香蕉国产线看观看软件 | 国内精品视频成人一区二区 | 91人人视频国产香蕉 | 美国毛片一级 | 国产精品系列在线 | 美女被爆免费视频软件 |