Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Snapchat_Filters/minion eyes filter folder #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Snapchat_Filters/MinionEyes Filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Make Fun Minions Filter with OpenCV 😊

+ Real time Minions eye filter using simple OpenCV libraries
+ Used CascadeClassifier instead of Dlib for efficient real-time application

<p style="margin-top: 40px; margin-bottom: 40px;">
<img src="img/output.JPG" alt="output" width="400" height="300">
</p>

## 👇 Getting started 👇
1. Clone this repository and navigate to this folder
2. run face_filter.py file

```
python face_filter.py
```

3. Enjoy cute and fun Minions filter!😍

(If you want to develop this filter further, feel free to make advanced filter that minion eyes follow your gaze)

67 changes: 67 additions & 0 deletions Snapchat_Filters/MinionEyes Filter/face_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Face filters (Snapchat like) using OpenCV
# @author:PSY222

import cv2
import sys
import datetime as dt
from time import sleep
import numpy as np
import os

current_dir = os.path.dirname(__file__)
image_path = os.path.join(current_dir, 'img/minion_eyes.png')
cascPath = os.path.join(current_dir, 'frontalEyes.xml') # for eye detection

if os.path.exists(cascPath):
print('Loading camera now')
else:
print('CascPath does not exists')

eyeCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)
anterior = 0
eyes = cv2.imread(image_path)


def put_eyes(eyes,fc,x,y,w,h):
eye_width,eye_height = w, h
eye = cv2.resize(eyes,(w,h))

for i in range(eye.shape[0]):
for j in range(eye.shape[1]):
for k in range(3):
if not np.all(eye[i,j,k]==[0,0,0]):
fc[y+i,x+j][k] = eye[i,j][k]
return fc


while True:
if not video_capture.isOpened():
print('Unable to load camera.')
sleep(5)
pass

ret, frame = video_capture.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

eye_loc = eyeCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(40,40)
)

for (x, y, w, h) in eye_loc:
frame = put_eyes(eyes,frame,x,y,w,h)


# Display the resulting frame
cv2.imshow('Video', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

video_capture.release()
cv2.destroyAllWindows()
Loading