2025-05-05 21:10:00 +08:00
|
|
|
import os
|
2025-05-05 20:59:44 +08:00
|
|
|
import cv2
|
|
|
|
import numpy as np
|
|
|
|
|
2025-05-05 21:19:29 +08:00
|
|
|
# Utility function to support unicode characters in file paths for reading
|
2025-05-05 20:59:44 +08:00
|
|
|
def imread_unicode(path, flags=cv2.IMREAD_COLOR):
|
|
|
|
return cv2.imdecode(np.fromfile(path, dtype=np.uint8), flags)
|
|
|
|
|
2025-05-05 21:19:29 +08:00
|
|
|
# Utility function to support unicode characters in file paths for writing
|
2025-05-05 20:59:44 +08:00
|
|
|
def imwrite_unicode(path, img, params=None):
|
2025-05-05 21:10:00 +08:00
|
|
|
root, ext = os.path.splitext(path)
|
|
|
|
if not ext:
|
|
|
|
ext = ".png"
|
|
|
|
result, encoded_img = cv2.imencode(ext, img, params if params else [])
|
2025-05-05 20:59:44 +08:00
|
|
|
if result:
|
2025-05-05 21:19:29 +08:00
|
|
|
encoded_img.tofile(path)
|
2025-05-05 20:59:44 +08:00
|
|
|
return True
|
2025-05-05 21:19:29 +08:00
|
|
|
return False
|