-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebcam_sticker.py
43 lines (32 loc) · 1.21 KB
/
webcam_sticker.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
import numpy as np
import cv2
import dlib
from newaddsticker import img2sticker
from kfaddsticker import img2sticker_kf
detector_hog = dlib.get_frontal_face_detector()
landmark_predictor = dlib.shape_predictor('./models/shape_predictor_68_face_landmarks.dat')
def main():
cv2.namedWindow('show', 0)
cv2.resizeWindow('show', 640, 360)
vc = cv2.VideoCapture(0)
img_sticker = cv2.imread('./images/king.png')
vlen = int(vc.get(cv2.CAP_PROP_FRAME_COUNT))
print (vlen) # 웹캠은 video length 가 0 입니다.
# 정해진 길이가 없기 때문에 while 을 주로 사용합니다.
# for i in range(vlen):
while True:
ret, img = vc.read()
if ret == False:
break
start = cv2.getTickCount()
img = cv2.flip(img, 1) # 보통 웹캠은 좌우 반전
# 스티커 메소드를 사용
img_result = img2sticker_kf(img, img_sticker.copy(), detector_hog, landmark_predictor)
time = (cv2.getTickCount() - start) / cv2.getTickFrequency() * 1000
print ('[INFO] time: %.2fms'%time)
cv2.imshow('show', img_result)
key = cv2.waitKey(1)
if key == 27:
break
if __name__ == '__main__':
main()