mirror of
https://github.com/serengil/deepface.git
synced 2025-07-23 02:10:02 +00:00
resize approach
This commit is contained in:
parent
94236318ac
commit
ed9367b8f1
@ -130,7 +130,12 @@ def preprocess_face(img, target_size=(224, 224), grayscale = False, enforce_dete
|
|||||||
# img = cv2.resize(img, target_size) #resize causes transformation on base image, adding black pixels to resize will not deform the base image
|
# img = cv2.resize(img, target_size) #resize causes transformation on base image, adding black pixels to resize will not deform the base image
|
||||||
|
|
||||||
# First resize the longer side to the target size
|
# First resize the longer side to the target size
|
||||||
factor = target_size[0] / max(img.shape) # Suppose target_size[0] == target_size[1]. What if this condition is not satisfied? E.g. DeepID expects 57x47 shaped inputs.
|
#factor = target_size[0] / max(img.shape)
|
||||||
|
|
||||||
|
factor_0 = target_size[0] / img.shape[0]
|
||||||
|
factor_1 = target_size[1] / img.shape[1]
|
||||||
|
factor = min(factor_0, factor_1)
|
||||||
|
|
||||||
dsize = (int(img.shape[1] * factor), int(img.shape[0] * factor))
|
dsize = (int(img.shape[1] * factor), int(img.shape[0] * factor))
|
||||||
img = cv2.resize(img, dsize)
|
img = cv2.resize(img, dsize)
|
||||||
|
|
||||||
@ -143,6 +148,10 @@ def preprocess_face(img, target_size=(224, 224), grayscale = False, enforce_dete
|
|||||||
else:
|
else:
|
||||||
img = np.pad(img, ((diff_0 // 2, diff_0 - diff_0 // 2), (diff_1 // 2, diff_1 - diff_1 // 2)), 'constant')
|
img = np.pad(img, ((diff_0 // 2, diff_0 - diff_0 // 2), (diff_1 // 2, diff_1 - diff_1 // 2)), 'constant')
|
||||||
|
|
||||||
|
#double check: if target image is not still the same size with target.
|
||||||
|
if img.shape[0:2] != target_size:
|
||||||
|
img = cv2.resize(img, target_size)
|
||||||
|
|
||||||
#---------------------------------------------------
|
#---------------------------------------------------
|
||||||
|
|
||||||
img_pixels = image.img_to_array(img)
|
img_pixels = image.img_to_array(img)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user