matheus-erthal commited on
Commit
c50a96c
1 Parent(s): 6974862

Ajustes no crop, tranpose e gitignore

Browse files
Files changed (3) hide show
  1. .gitignore +4 -1
  2. app.py +5 -3
  3. image_crop.py +1 -1
.gitignore CHANGED
@@ -1,4 +1,7 @@
1
  __pycache__
2
  flagged
3
  .env
4
- venv/
 
 
 
 
1
  __pycache__
2
  flagged
3
  .env
4
+ venv/
5
+ test-images/
6
+ test.py
7
+ temp/*
app.py CHANGED
@@ -5,6 +5,7 @@ from dotenv import load_dotenv
5
  from image_crop import crop_faces
6
  import cv2
7
  import numpy as np
 
8
 
9
  load_dotenv()
10
 
@@ -14,10 +15,10 @@ def crop_photoshoot_images(photo_shoot_id):
14
 
15
  for file in files:
16
  s3_object = AwsService.get_image_from_s3(os.environ.get('AWS_S3_BUCKET'), file['Key'])
17
- image = s3_object["pil"]
18
  key = s3_object["key"]
19
- cv2_img = np.array(image)
20
- cv2_img = cv2_img[:, :, ::-1].copy()
21
  faces = crop_faces(cv2_img)
22
  i = 1
23
  for face in faces:
@@ -26,6 +27,7 @@ def crop_photoshoot_images(photo_shoot_id):
26
  AwsService.send_image_to_s3(filename, os.environ.get('AWS_S3_BUCKET'), f'PhotoShoots/{photo_shoot_id}/Croppeds/{key}-{i}.jpg')
27
  os.remove(filename)
28
  i += 1
 
29
 
30
  return {"message": f"{len(files)} images cropped successfully"}
31
 
 
5
  from image_crop import crop_faces
6
  import cv2
7
  import numpy as np
8
+ from PIL import ImageOps
9
 
10
  load_dotenv()
11
 
 
15
 
16
  for file in files:
17
  s3_object = AwsService.get_image_from_s3(os.environ.get('AWS_S3_BUCKET'), file['Key'])
18
+ image = ImageOps.exif_transpose(s3_object["pil"])
19
  key = s3_object["key"]
20
+ image.save(f"temp/{key}.jpg")
21
+ cv2_img = cv2.imread(f"temp/{key}.jpg")
22
  faces = crop_faces(cv2_img)
23
  i = 1
24
  for face in faces:
 
27
  AwsService.send_image_to_s3(filename, os.environ.get('AWS_S3_BUCKET'), f'PhotoShoots/{photo_shoot_id}/Croppeds/{key}-{i}.jpg')
28
  os.remove(filename)
29
  i += 1
30
+ os.remove(f"temp/{key}.jpg")
31
 
32
  return {"message": f"{len(files)} images cropped successfully"}
33
 
image_crop.py CHANGED
@@ -8,7 +8,7 @@ def discover_square_crop_points(points, image, step=3, maximum_step=30):
8
  h = points["h"]
9
 
10
  if step >= maximum_step:
11
- return {"initial_x": x, "initial_y": y, "final_x": x + w, "final_y": x + h}
12
 
13
  img_height = image.shape[0]
14
  img_width = image.shape[1]
 
8
  h = points["h"]
9
 
10
  if step >= maximum_step:
11
+ return {"initial_x": x, "initial_y": y, "final_x": x + w, "final_y": y + h}
12
 
13
  img_height = image.shape[0]
14
  img_width = image.shape[1]