Update __init__.py

pull/1210/head
KUNJ SHAH 2025-05-05 18:29:44 +05:30 committed by GitHub
parent b1f610d432
commit c9f36eb350
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 0 deletions

View File

@ -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