diff --git a/PyFry.py b/PyFry.py index 1bc7fec..04fc397 100644 --- a/PyFry.py +++ b/PyFry.py @@ -1,20 +1,25 @@ import cv2 -from PIL import Image, ImageOps, ImageEnhance import os -from utils.utils import Colors -from imutils import face_utils import dlib import tkinter as tk +from PIL import Image, ImageOps, ImageEnhance +from utils.utils import Colors +from imutils import face_utils from tkinter import filedialog + ''' TODO: -> Compressing (Crushing) and back (to increase noise) :: DONE -> Applying Red and Orange hue filters for classic deep fry look :: DONE -> Detecting eye coordinates and applying the deepfry eye flare in the center::DONE ''' + def userInput(): - #Allowing user to choose the image that has to be deepfried - root = tk.Tk() +up-and-structure-issue12 + ''' + Allowing user to choose the image that has to be deepfried + ''' + root =tk.Tk() root.withdraw() global filepath filepath = list(root.tk.splitlist(filedialog.askopenfilenames(title="PyFry - Choose Image"))) @@ -22,13 +27,18 @@ def userInput(): def irisCoords(eye): - #Finding the center point of the eye using the average outer extremes average of the eyes + ''' + Finding the center point of the eye using the average outer extremes average of the eyes + ''' mid = (eye[0] +eye[3])/2 mid = (int(mid[0]), int(mid[1])) return mid + def generateHue(img): - #Generating and increasing prominency of red band of the image + ''' + Generating and increasing prominency of red band of the image + ''' img = img.convert('RGB') red = img.split()[0] #(R,G,B) red = ImageEnhance.Contrast(red).enhance(2.0) @@ -39,6 +49,7 @@ def generateHue(img): img = ImageEnhance.Sharpness(img).enhance(150) return img + def crushAndBack(img): img = img.convert('RGB') w,h = img.width, img.height @@ -47,8 +58,13 @@ def crushAndBack(img): img = img.resize((int(w ** .90), int(h ** .90)), resample = Image.BICUBIC) img = img.resize((w,h), resample = Image.BICUBIC) return img + + def addFlare(img): - ''' Initialising dlib for frontal facial features ''' + ''' + Initialising dlib for frontal facial features + ''' + flare = Image.open('flare.png') detect = dlib.get_frontal_face_detector() predict = dlib.shape_predictor("assets\shape_predictor_68_face_landmarks.dat") @@ -56,11 +72,9 @@ def addFlare(img): (lS, lE) = face_utils.FACIAL_LANDMARKS_68_IDXS["left_eye"] (rS, rE) = face_utils.FACIAL_LANDMARKS_68_IDXS["right_eye"] - imgCV = cv2.imread('test.jpg') #imgCV = cv2.imread('test2.jpg') - gray = cv2.cvtColor(imgCV, cv2.COLOR_BGR2GRAY) subjects = detect(gray, 0) @@ -69,6 +83,7 @@ def addFlare(img): shape = face_utils.shape_to_np(shape) leftEye = shape[lS:lE] rightEye = shape[rS:rE] + ''' Assigning an area to paste the flare png Using the coordinates given by the Dlib module ln,rn is the distance between the top left and bottom right of the iris multiplied by 4. @@ -87,16 +102,16 @@ def addFlare(img): print("Area for left eye",rec0,rec1) print("Area for right eye",rec2,rec3) - """ Area Assignment for left eye and right eye""" + #Area Assignment for left eye and right eye areaLeft=(rec0[0],rec0[1],rec1[0],rec1[1]) areaRight=(rec2[0],rec2[1],rec3[0],rec3[1]) - """ Resizing the flare image to fit the area""" + #Resizing the flare image to fit the area flareLeft=flare.resize((rec1[0]-rec0[0],rec1[1]-rec0[1])) flareRight=flare.resize((rec3[0]-rec2[0],rec3[1]-rec2[1])) - """Pasting the flare image on the area. - Third parameter is an alpha channel that provides transparency for the png""" + #Pasting the flare image on the area. + #Third parameter is an alpha channel that provides transparency for the png img.paste(flareLeft,areaLeft,flareLeft) img.paste(flareRight,areaRight,flareRight) return img