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

您的位置:首頁技術(shù)文章
文章詳情頁

python使用dlib進(jìn)行人臉檢測和關(guān)鍵點的示例

瀏覽:4日期: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進(jìn)行人臉檢測和人臉關(guān)鍵點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 # 位運算時需要轉(zhuǎn)化成灰度圖像 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進(jìn)行人臉檢測和關(guān)鍵點的示例

python使用dlib進(jìn)行人臉檢測和關(guān)鍵點的示例

python使用dlib進(jìn)行人臉檢測和關(guān)鍵點的示例

以上就是python使用dlib進(jìn)行人臉檢測和關(guān)鍵點的示例的詳細(xì)內(nèi)容,更多關(guān)于python 人臉檢測的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产成人毛片毛片久久网 | 国产又黄又爽又色视频观看免费 | 久久视频在线播放视频99re6 | 性做久久久久久久久25的美女 | 五月丁六月停停 | 成人私拍福利视频在线 | 国产尻逼视频 | 久久国产精品免费一区二区三区 | 涩久久| 亚洲 另类色区 欧美日韩 | 国产精品免费久久久免费 | 中国一级免费毛片 | 成年片美女福利视频在线 | 国产农村精品一级毛片视频 | 亚洲美女在线观看播放 | 国产在线观看a | 日韩在线综合 | 日本二区免费一片黄2019 | 一级黄色大片视频 | 亚洲天堂色图 | 国产欧美激情一区二区三区 | 日本美女一区二区 | 国产萝控精品福利视频免费观看 | 福利午夜国产网站在线不卡 | 激情777| 亚洲欧美日韩国产 | 久青草国产在线 | 亚洲成人三级 | 欧美大片国产在线永久播放 | 玖玖爱视频在线观看 | 精品一区二区高清在线观看 | 日韩欧一级毛片在线播无遮挡 | 亚洲精品久久久久影 | 欧美一区欧美二区 | 亚洲一区二区三区精品国产 | 九九精品免费 | 最新国产大片高清视频 | 久草视频福利在线 | 国产综合久久一区二区三区 | 久久综合九色综合欧美播 | 一区二区免费视频观看 |