-
Notifications
You must be signed in to change notification settings - Fork 1
/
Snapchat-Filter.py
62 lines (39 loc) · 1.66 KB
/
Snapchat-Filter.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
52
53
54
55
56
57
58
59
60
61
62
import cv2
import numpy as np
import pandas as pd
image = './Assets/Before.png'
face_cascade = cv2.CascadeClassifier("./Dataset/haarcascade_frontalface_alt.xml")
eyecascade = cv2.CascadeClassifier("./Dataset/frontalEyes35x16.xml")
nosecascade = cv2.CascadeClassifier("./Dataset/Nose18x15.xml")
glasses = cv2.imread('./FilterImages/glasses.png', -1)
mustache = cv2.imread('./FilterImages/mustache.png', -1)
frame = cv2.imread(image)
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray_frame, 1.2, 5)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
for face in faces:
x, y, w, h = face
rol_gray = gray_frame[y:y+h, x:x+h]
rol_color = frame[y:y+h, x:x+h]
eyes = eyecascade.detectMultiScale(rol_gray,1.3,3)
for (ex,ey,ew,eh) in eyes:
glasses = cv2.resize(glasses,(ew,eh))
gw, gh, gc = glasses.shape
for i in range(0, gw):
for j in range(0, gh):
if glasses[i,j][3] != 0:
rol_color[ey + i, ex + j] = glasses[i,j]
nose = nosecascade.detectMultiScale(rol_gray, 1.3, 7)
for (nx, ny, nw, nh) in nose:
mustache = cv2.resize(mustache, (nw+10,nh))
mw, mh, mc = mustache.shape
for i in range(0,mw):
for j in range(0, mh):
if mustache[i,j][3] != 0:
rol_color[ny+int(nh/2.0)+i, nx+j+3] = mustache[i,j]
frame = cv2.cvtColor(frame, cv2.COLOR_BGRA2BGR)
cv2.imshow("window", frame)
frame = np.resize(frame,(-1,3))
pd.DataFrame(frame, columns=['Channel 1',
'Channel 2', 'Channel 3']).to_csv('./Prediction.csv', index= False)
cv2.waitKey(0)