pull/1210/head
KUNJ SHAH 2025-05-05 13:10:00 +00:00
parent c9f36eb350
commit 9ecd2dab83
1 changed files with 7 additions and 3 deletions

View File

@ -1,3 +1,4 @@
import os
import cv2 import cv2
import numpy as np import numpy as np
@ -11,8 +12,11 @@ cv2.imread = imread_unicode
# Define a function to support unicode characters in file paths when saving # Define a function to support unicode characters in file paths when saving
def imwrite_unicode(path, img, params=None): def imwrite_unicode(path, img, params=None):
# Encode the image # Encode the image
ext = path.split(".")[-1] # Get file extension root, ext = os.path.splitext(path)
result, encoded_img = cv2.imencode(f".{ext}", img, params if params else []) # 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: if result:
encoded_img.tofile(path) # Save image using numpy's `tofile()` encoded_img.tofile(path) # Save image using numpy's `tofile()`