-
Notifications
You must be signed in to change notification settings - Fork 11
/
main_webcam.py
51 lines (41 loc) · 1.37 KB
/
main_webcam.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
44
45
46
47
48
49
50
51
#! /usr/bin/env python
import sys
import numpy as np
import cv2
from imutils import face_utils
import datetime
import imutils
import time
import dlib
from utils import face_swap3, face_swap
if __name__ == '__main__' :
# Make sure OpenCV is version 3.0 or above
(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
if int(major_ver) < 3 :
print >> sys.stderr, 'ERROR: Script needs OpenCV 3.0 or higher'
sys.exit(1)
print("[INFO] loading facial landmark predictor...")
model = "shape_predictor_68_face_landmarks.dat"
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(model)
video_capture = cv2.VideoCapture(0)
ret, img = video_capture.read()
cv2.imshow("Face Swapped", img)
img = cv2.imread('ji2.jpg')
img2 = cv2.imread('donald_trump.jpg')
while (True):
print "what"
ret, img = video_capture.read()
output = face_swap3(img, detector, predictor)
if (output != None):
cv2.imshow("Face Swapped", output)
else:
cv2.imshow("Face Swapped", img)
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
#output = face_swap3(img, detector, predictor)
#cv2.imwrite('lol3.jpg',output)
cv2.destroyAllWindows()
video_capture.release()