色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

瀏覽: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進(jìn)行人臉檢測(cè)和人臉關(guān)鍵點(diǎ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) # 只把臉切出來(lái) 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 # 位運(yùn)算時(shí)需要轉(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)行人臉檢測(cè)和關(guān)鍵點(diǎn)的示例

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

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

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲精品专区一区二区欧美 | 日本a级特黄三级三级三级 日本a一级片 | 欧美久色| 狠狠se| 一级a毛片免费观看久久精品 | 99在线在线视频免费视频观看 | 久久高清免费 | 免费在线观看黄色毛片 | 国产成人禁片免费观看视频 | 韩国精品一区二区三区四区五区 | 成人国产永久福利看片 | 亚洲精品自产拍在线观看 | 日美三级 | 亚洲国产小视频 | 欧美大狠狠大臿蕉香蕉大视频 | 亚洲精品日韩中文字幕久久久 | 欧美日韩亚洲精品一区 | 不卡国产视频 | a级片免费 | 国产成人香蕉在线视频网站 | 正在播放国产大学生情侣 | 欧美日韩一区在线观看 | 亚洲精品国产福利 | 国产美女主播一级成人毛片 | 久久久久久久免费视频 | 亚洲视频网站在线观看 | 亚洲最新视频在线观看 | 综合图片亚洲网友自拍10p | 国产成人免费福利网站 | 免费看岛国视频在线观看 | 国产一级毛片大陆 | 国产成人啪精品视频免费软件 | 亚洲网站在线播放 | 视频二区国产 | 欧美日韩高清不卡一区二区三区 | 中文字幕一区二区三区有限公司 | 国产亚洲精品一区二区 | 大伊香蕉精品视频在线观看 | 国产精品黄页网站在线播放免费 | 日韩欧美视频在线一区二区 | 99久久综合精品免费 |