亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

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

#!/usr/bin/env python# -*- coding:utf-8-*-# file: {NAME}.py# @author: jory.d# @contact: dangxusheng163@163.com# @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级高清免费酷网 日本特黄一级 | 日本免费一区二区视频 | chinese国产在线视频 | 国产精品综合久成人 | 国产日本三级在线播放线观看 | 亚洲一区二区三区亚瑟 | 亚洲一级生活片 | 成人精品第一区二区三区 | 在线视频免费观看a毛片 | 黄页网址大全免费观看不用 | 亚洲国产成人久久一区www | 男女日批视频在线永久观看 | 国产成人一区二区三区高清 | 高清一区二区三区视频 | 午夜国产精品影院在线观看 | 亚洲欧美另类国产综合 | 日韩精品视频在线观看免费 | 久久国产自偷自偷免 | 公妇乱淫日本免费观看 | 黄色一级大片 | 风间由美理伦片在线观看 | 一区二区三区四区日韩 | 国产精品亚洲片在线观看麻豆 | caoporen个人免费公开视频 | 黄网在线免费看 | 成人合成mv福利视频网站 | 亚洲一区二区三区四区热压胶 | 91精品国产综合久久久久久 | 伊人久久网站 | 精精国产xxxx视频在线播放器 | 精品香蕉伊思人在线观看 | 欧美成人福利视频 | 亚洲 欧美 中文 日韩专区 | 久久一本精品久久精品66 | 黄色天堂网站 |