From c9f36eb350dfb66296c92b604feeed4b1acc6b5f Mon Sep 17 00:00:00 2001 From: KUNJ SHAH Date: Mon, 5 May 2025 18:29:44 +0530 Subject: [PATCH 1/4] Update __init__.py --- modules/__init__.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/__init__.py b/modules/__init__.py index e69de29..8b50aa7 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -0,0 +1,23 @@ +import cv2 +import numpy as np + +# Define a new function that supports unicode characters in file paths +def imread_unicode(path, flags=cv2.IMREAD_COLOR): + return cv2.imdecode(np.fromfile(path, dtype=np.uint8), flags) + +# Override the original `cv2.imread` +cv2.imread = imread_unicode + +# Define a function to support unicode characters in file paths when saving +def imwrite_unicode(path, img, params=None): + # Encode the image + ext = path.split(".")[-1] # Get file extension + result, encoded_img = cv2.imencode(f".{ext}", img, params if params else []) + + if result: + encoded_img.tofile(path) # Save image using numpy's `tofile()` + return True + return False + +# Override `cv2.imwrite` +cv2.imwrite = imwrite_unicode From 9ecd2dab8311286e47e205a25ccd526f75d7564b Mon Sep 17 00:00:00 2001 From: KUNJ SHAH Date: Mon, 5 May 2025 13:10:00 +0000 Subject: [PATCH 2/4] changes --- modules/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/__init__.py b/modules/__init__.py index 8b50aa7..c740bae 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -1,3 +1,4 @@ +import os import cv2 import numpy as np @@ -11,8 +12,11 @@ cv2.imread = imread_unicode # Define a function to support unicode characters in file paths when saving def imwrite_unicode(path, img, params=None): # Encode the image - ext = path.split(".")[-1] # Get file extension - result, encoded_img = cv2.imencode(f".{ext}", img, params if params else []) + root, ext = os.path.splitext(path) + # If no extension is found, you can choose a default extension (e.g., ".png") + if not ext: + ext = ".png" + result, encoded_img = cv2.imencode(ext, img, params if params else []) if result: encoded_img.tofile(path) # Save image using numpy's `tofile()` @@ -20,4 +24,4 @@ def imwrite_unicode(path, img, params=None): return False # Override `cv2.imwrite` -cv2.imwrite = imwrite_unicode +cv2.imwrite = imwrite_unicode \ No newline at end of file From fe4a87e8f23a9bbd9dd92517f5dac64668ef31f5 Mon Sep 17 00:00:00 2001 From: KUNJ SHAH Date: Mon, 5 May 2025 13:19:29 +0000 Subject: [PATCH 3/4] update --- modules/__init__.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/modules/__init__.py b/modules/__init__.py index c740bae..7968738 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -2,26 +2,17 @@ import os import cv2 import numpy as np -# Define a new function that supports unicode characters in file paths +# Utility function to support unicode characters in file paths for reading def imread_unicode(path, flags=cv2.IMREAD_COLOR): return cv2.imdecode(np.fromfile(path, dtype=np.uint8), flags) -# Override the original `cv2.imread` -cv2.imread = imread_unicode - -# Define a function to support unicode characters in file paths when saving +# Utility function to support unicode characters in file paths for writing def imwrite_unicode(path, img, params=None): - # Encode the image root, ext = os.path.splitext(path) - # If no extension is found, you can choose a default extension (e.g., ".png") if not ext: ext = ".png" result, encoded_img = cv2.imencode(ext, img, params if params else []) - if result: - encoded_img.tofile(path) # Save image using numpy's `tofile()` + encoded_img.tofile(path) return True - return False - -# Override `cv2.imwrite` -cv2.imwrite = imwrite_unicode \ No newline at end of file + return False \ No newline at end of file From a64940def77f1201fd23efea6bc4d9dadae33a2b Mon Sep 17 00:00:00 2001 From: KUNJ SHAH Date: Mon, 5 May 2025 13:19:46 +0000 Subject: [PATCH 4/4] update --- modules/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/__init__.py b/modules/__init__.py index 7968738..45a9cac 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -12,7 +12,7 @@ def imwrite_unicode(path, img, params=None): if not ext: ext = ".png" result, encoded_img = cv2.imencode(ext, img, params if params else []) - if result: + result, encoded_img = cv2.imencode(f".{ext}", img, params if params is not None else []) encoded_img.tofile(path) return True return False \ No newline at end of file