Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke-a-uchida committed Aug 5, 2018
1 parent 7ccc00b commit 918c05f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions utkface/create_db_utkface_with_margin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
from pathlib import Path
from tqdm import tqdm
import pandas as pd
import cv2
import dlib

Expand All @@ -19,6 +18,8 @@ def get_args():
return args


# robust image cropping from
# https://stackoverflow.com/questions/15589517/how-to-crop-an-image-in-opencv-using-python
def imcrop(img, x1, y1, x2, y2):
if x1 < 0 or y1 < 0 or x2 > img.shape[1] or y2 > img.shape[0]:
img, x1, x2, y1, y2 = pad_img_to_fit_bbox(img, x1, x2, y1, y2)
Expand Down Expand Up @@ -57,10 +58,7 @@ def main():
yw1 = int(y1 - margin * h)
xw2 = int(x2 + margin * w)
yw2 = int(y2 + margin * h)

image_name = image_path.name
print(image_name, x1, y1, x2, y2)

cropped_img = imcrop(img, xw1, yw1, xw2, yw2)
cv2.imwrite(str(output_dir.joinpath(image_name)), cropped_img)

Expand Down

0 comments on commit 918c05f

Please sign in to comment.