Python用dilb提取照片上人臉的示例
上代碼:
#coding=utf-8import cv2import dlibpath = 'imagePath/9.jpg'img = cv2.imread(path)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)#人臉分類器detector = dlib.get_frontal_face_detector()# 獲取人臉檢測器predictor = dlib.shape_predictor( 'shape_predictor_68_face_landmarks.dat')color = (0, 255, 0) # 定義繪制顏色dets = detector(gray, 1)for face in dets: shape = predictor(img, face) # 尋找人臉的68個標(biāo)定點(diǎn) chang=[] kuan= [] # 遍歷所有點(diǎn),打印出其坐標(biāo),并圈出來 for pt in shape.parts(): pt_pos = (pt.x, pt.y) chang.append(pt.x) kuan.append(pt.y) #cv2.circle(img, pt_pos, 1, (0, 255, 0), 1) x1 = max(chang) x2 = min(chang) y1 = max(kuan) y2 = min(kuan) cv2.rectangle(img, (x2, y2), (x1, y1), color, 1) cropped = img[y2 + 1:y1, x2 + 1:x1] # 裁剪坐標(biāo)為[y0:y1, x0:x1] cv2.imshow('image', cropped) k = cv2.waitKey(0) if k == ord('s'): cv2.imwrite('imagePath/9-7.png', cropped)cv2.destroyAllWindows()
識別效果:
以上就是Python用dilb提取照片上人臉的示例的詳細(xì)內(nèi)容,更多關(guān)于python 提取人臉的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. Ajax實(shí)現(xiàn)文件上傳功能(Spring MVC)2. 基于javaweb+jsp實(shí)現(xiàn)學(xué)生宿舍管理系統(tǒng)3. idea設(shè)置代碼格式化的方法步驟4. 使用EF Code First搭建簡易ASP.NET MVC網(wǎng)站并允許數(shù)據(jù)庫遷移5. ASP開發(fā)準(zhǔn)則是什么6. vue動態(tài)加載SVG文件并修改節(jié)點(diǎn)數(shù)據(jù)的操作代碼7. python 工具 字符串轉(zhuǎn)numpy浮點(diǎn)數(shù)組的實(shí)現(xiàn)8. Python 實(shí)現(xiàn)平臺類游戲添加跳躍功能9. Python多分支if語句的使用10. python 日志模塊logging的使用場景及示例
