krrishD commited on
Commit
dd7f377
1 Parent(s): 72adce4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -18,6 +18,7 @@ from io import BytesIO
18
  import os
19
  from PIL import Image
20
  import gdown
 
21
 
22
  def download_gdrive_url():
23
  url = 'https://drive.google.com/u/0/uc?id=1PPO2MCttsmSqyB-vKh5C7SumwFKuhgyj&export=download'
@@ -47,17 +48,15 @@ def inpaint(p, init_image, mask_image=None, strength=0.75, guidance_scale=7.5, g
47
  return return_image
48
 
49
  def identify_face(user_image):
50
- img = cv2.imread(user_image.name) # read the resized image in cv2
 
51
  print(img.shape)
52
- gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale
53
- download_gdrive_url() #download the haarcascade face recognition stuff
54
- haar_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
55
- faces_rect = haar_cascade.detectMultiScale(gray_img, scaleFactor=1.1, minNeighbors=9)
56
- for (x, y, w, h) in faces_rect[:1]:
57
- mask = np.zeros(img.shape[:2], dtype="uint8")
58
- print(mask.shape)
59
- cv2.rectangle(mask, (x, y), (x+w, y+h), 255, -1)
60
  print(mask.shape)
 
61
  inverted_image = cv2.bitwise_not(mask)
62
  return inverted_image
63
 
 
18
  import os
19
  from PIL import Image
20
  import gdown
21
+ import face_recognition
22
 
23
  def download_gdrive_url():
24
  url = 'https://drive.google.com/u/0/uc?id=1PPO2MCttsmSqyB-vKh5C7SumwFKuhgyj&export=download'
 
48
  return return_image
49
 
50
  def identify_face(user_image):
51
+ # img = cv2.imread(user_image.name) # read the resized image in cv2
52
+ img = face_recognition.load_image_file(user_image.name)
53
  print(img.shape)
54
+ face_locations = face_recognition.face_locations(img)
55
+ for face_location in face_locations:
56
+ top, right, bottom, left = face_location
57
+ mask = np.zeros(image.shape[:2], dtype="uint8")
 
 
 
 
58
  print(mask.shape)
59
+ cv2.rectangle(mask, (left, top), (right, bottom), 255, -1)
60
  inverted_image = cv2.bitwise_not(mask)
61
  return inverted_image
62