From d3f78558fffdb4fdbac14311f9a4f0b658c5182b Mon Sep 17 00:00:00 2001 From: RayVik Date: Thu, 27 Apr 2023 15:49:32 +0300 Subject: [PATCH 1/4] Fix bug with unicode filenames --- deepface/commons/functions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index 81a2753..515ab17 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -103,7 +103,12 @@ def load_image(img): if os.path.isfile(img) is not True: raise ValueError(f"Confirm that {img} exists") - return cv2.imread(img) + img = open(img, "rb") + chunk = img.read() + chunk_arr = np.frombuffer(chunk, dtype=np.uint8) + img = cv2.imdecode(chunk_arr, cv2.IMREAD_COLOR) + + return img # -------------------------------------------------- From 06ca8161bcb461a2e33a73c716373df79c90f20c Mon Sep 17 00:00:00 2001 From: RayVik Date: Fri, 28 Apr 2023 02:39:58 +0300 Subject: [PATCH 2/4] Update functions.py --- deepface/commons/functions.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index 515ab17..4b0e290 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -103,11 +103,11 @@ def load_image(img): if os.path.isfile(img) is not True: raise ValueError(f"Confirm that {img} exists") - img = open(img, "rb") - chunk = img.read() - chunk_arr = np.frombuffer(chunk, dtype=np.uint8) - img = cv2.imdecode(chunk_arr, cv2.IMREAD_COLOR) - + with open(img, "rb") as img: + chunk = img.read() + chunk_arr = np.frombuffer(chunk, dtype=np.uint8) + img = cv2.imdecode(chunk_arr, cv2.IMREAD_COLOR) + return img From 6522fa7d027290f51fddd653327675de6a1af2d8 Mon Sep 17 00:00:00 2001 From: RayVik Date: Fri, 28 Apr 2023 18:39:20 +0300 Subject: [PATCH 3/4] Update functions.py --- deepface/commons/functions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index 4b0e290..309f0d4 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -102,13 +102,16 @@ def load_image(img): # The image is a path if os.path.isfile(img) is not True: raise ValueError(f"Confirm that {img} exists") - - with open(img, "rb") as img: - chunk = img.read() + + # For reading images with unicode names + with open(img, "rb") as img_f: + chunk = img_f.read() chunk_arr = np.frombuffer(chunk, dtype=np.uint8) img = cv2.imdecode(chunk_arr, cv2.IMREAD_COLOR) return img + # This causes troubles when reading files with non english names + # return cv2.imread(img) # -------------------------------------------------- From 8d91ea2f21db294e342440c896cb182add58404d Mon Sep 17 00:00:00 2001 From: RayVik Date: Fri, 28 Apr 2023 19:03:57 +0300 Subject: [PATCH 4/4] Update functions.py --- deepface/commons/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index 309f0d4..d04d71c 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -102,7 +102,7 @@ def load_image(img): # The image is a path if os.path.isfile(img) is not True: raise ValueError(f"Confirm that {img} exists") - + # For reading images with unicode names with open(img, "rb") as img_f: chunk = img_f.read()