Python用dilb提取照片上人臉的示例
更新時(shí)間:2020年10月26日 11:57:40 作者:凹凸曼大人
這篇文章主要介紹了Python用dilb提取照片上人臉的示例,幫助大家更好的利用python處理人像,感興趣的朋友可以了解下
上代碼:
#coding=utf-8 import cv2 import dlib path = "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個(gè)標(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()
識(shí)別效果:
以上就是Python用dilb提取照片上人臉的示例的詳細(xì)內(nèi)容,更多關(guān)于python 提取人臉的資料請關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:
- Python使用百度api做人臉對比的方法
- python基于opencv實(shí)現(xiàn)人臉識(shí)別
- python使用dlib進(jìn)行人臉檢測和關(guān)鍵點(diǎn)的示例
- python實(shí)現(xiàn)圖片,視頻人臉識(shí)別(dlib版)
- python實(shí)現(xiàn)圖片,視頻人臉識(shí)別(opencv版)
- python調(diào)用百度API實(shí)現(xiàn)人臉識(shí)別
- 使用python-cv2實(shí)現(xiàn)Harr+Adaboost人臉識(shí)別的示例
- Python環(huán)境使用OpenCV檢測人臉實(shí)現(xiàn)教程
- python openCV實(shí)現(xiàn)攝像頭獲取人臉圖片
- 基于Python實(shí)現(xiàn)視頻的人臉融合功能
- python實(shí)現(xiàn)人臉簽到系統(tǒng)
- Python3 利用face_recognition實(shí)現(xiàn)人臉識(shí)別的方法
- python 使用百度AI接口進(jìn)行人臉對比的步驟
相關(guān)文章
利用python GDAL庫讀寫geotiff格式的遙感影像方法
今天小編就為大家分享一篇利用python GDAL庫讀寫geotiff格式的遙感影像方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11python基于opencv 實(shí)現(xiàn)圖像時(shí)鐘
這篇文章主要介紹了python基于opencv 實(shí)現(xiàn)圖像時(shí)鐘的方法,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2021-01-01Python深度學(xué)習(xí)之FastText實(shí)現(xiàn)文本分類詳解
FastText是一種典型的深度學(xué)習(xí)詞向量的表示方法,它非常簡單通過Embedding層將單詞映射到稠密空間,然后將句子中所有的單詞在Embedding空間中進(jìn)行平均,進(jìn)而完成分類操作2022-09-09