Python用dilb提取照片上人臉的示例
上代碼:
#coding=utf-8import cv2import dlibpath = 'imagePath/9.jpg'img = cv2.imread(path)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)#人臉?lè)诸惼鱠etector = dlib.get_frontal_face_detector()# 獲取人臉檢測(cè)器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個(gè)標(biāo)定點(diǎn) chang=[] kuan= [] # 遍歷所有點(diǎn),打印出其坐標(biāo),并圈出來(lái) 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()
識(shí)別效果:
以上就是Python用dilb提取照片上人臉的示例的詳細(xì)內(nèi)容,更多關(guān)于python 提取人臉的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. Intellij IDEA 2019 最新亂碼問(wèn)題及解決必殺技(必看篇)2. JS繪圖Flot如何實(shí)現(xiàn)動(dòng)態(tài)可刷新曲線圖3. 關(guān)于HTML5的img標(biāo)簽4. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫(huà)特效5. 未來(lái)的J2EE主流應(yīng)用框架:對(duì)比Spring和EJB36. Android Manifest中meta-data擴(kuò)展元素?cái)?shù)據(jù)的配置與獲取方式7. Android自定義View實(shí)現(xiàn)掃描效果8. JS+css3實(shí)現(xiàn)幻燈片輪播圖9. css3溢出隱藏的方法10. ASP.NET MVC獲取多級(jí)類別組合下的產(chǎn)品
