반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- 대이터
- discrete_scatter
- Keras
- CES 2O21 참가
- bccard
- 재귀함수
- postorder
- 결합전문기관
- 웹 용어
- cudnn
- vscode
- html
- C언어
- KNeighborsClassifier
- pycharm
- tensorflow
- broscoding
- CES 2O21 참여
- 데이터전문기관
- java역사
- web 사진
- 자료구조
- 머신러닝
- web 용어
- mglearn
- classification
- paragraph
- web
- web 개발
- inorder
Archives
- Today
- Total
bro's coding
dlib 이용 얼굴인식 in python 본문
반응형
# install for dlib in cmd
# pip install cmake
# pip install dlib
import dlib
import cv2 as cv
import numpy as np
detector = dlib.get_frontal_face_detector()
# down learnning model from this site
# http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
predictor = dlib.shape_predictor('C:\\Users\\givemebro\\Desktop\\shape_predictor_68_face_landmarks.dat')
cap = cv.VideoCapture(0)
ALL = list(range(0, 68))
RIGHT_EYEBROW = list(range(17, 22))
LEFT_EYEBROW = list(range(22, 27))
RIGHT_EYE = list(range(36, 42))
LEFT_EYE = list(range(42, 48))
NOSE = list(range(27, 36))
MOUTH_OUTLINE = list(range(48, 61))
MOUTH_INNER = list(range(61, 68))
JAWLINE = list(range(0, 17))
index = ALL
while True:
ret, img_frame = cap.read()
img_gray = cv.cvtColor(img_frame, cv.COLOR_BGR2GRAY)
dets = detector(img_gray, 1)
for face in dets:
shape = predictor(img_frame, face) #얼굴에서 68개 점 찾기
list_points = []
for p in shape.parts():
list_points.append([p.x, p.y])
list_points = np.array(list_points)
for i,pt in enumerate(list_points[index]):
pt_pos = (pt[0], pt[1])
cv.circle(img_frame, pt_pos, 2, (0, 255, 0), -1)
cv.rectangle(img_frame, (face.left(), face.top()), (face.right(), face.bottom()),
(0, 0, 255), 3)
cv.imshow('result', img_frame)
key = cv.waitKey(1)
if key == 27:
break
elif key == ord('1'):
index = ALL
elif key == ord('2'):
index = LEFT_EYEBROW + RIGHT_EYEBROW
elif key == ord('3'):
index = LEFT_EYE + RIGHT_EYE
elif key == ord('4'):
index = NOSE
elif key == ord('5'):
index = MOUTH_OUTLINE+MOUTH_INNER
elif key == ord('6'):
index = JAWLINE
cap.release()
반응형
'[AI] > openCV' 카테고리의 다른 글
Gaussian(잡음 추가) in C++ (0) | 2020.06.22 |
---|---|
GaussianBlur(unsharp) in C++ (0) | 2020.06.22 |
GaussianBlur in C++ (0) | 2020.06.22 |
blurring_mean in C++ (0) | 2020.06.22 |
embossing filter in C++ (0) | 2020.06.22 |
openCV_blink_eyes_count in python (0) | 2020.06.19 |
dlib install (0) | 2020.06.19 |
openCV.install (0) | 2020.06.16 |
Comments