Support non-ascii characters

This commit is contained in:
Kenneth Estanislao
2026-06-14 20:18:56 +08:00
parent 3b69413d61
commit 834bc43768
8 changed files with 73 additions and 52 deletions
+2 -2
View File
@@ -126,7 +126,7 @@ def process_video_in_memory(source_path: str, target_path: str, fps: float) -> b
Returns True on success, False on failure (caller should fall back to the
disk-based pipeline).
"""
import cv2
from modules import imread_unicode
from modules.face_analyser import get_one_face
from modules.utilities import (
get_video_dimensions,
@@ -139,7 +139,7 @@ def process_video_in_memory(source_path: str, target_path: str, fps: float) -> b
# --- Pre-load source face (needed by face_swapper in simple mode) ---
source_face = None
if source_path and os.path.exists(source_path):
source_img = cv2.imread(source_path)
source_img = imread_unicode(source_path)
if source_img is not None:
source_face = get_one_face(source_img)
del source_img
+5 -4
View File
@@ -10,6 +10,7 @@ import onnxruntime
import modules.globals
import modules.processors.frame.core
from modules import imread_unicode, imwrite_unicode
from modules.core import update_status
from modules.face_analyser import get_many_faces
from modules.typing import Frame, Face
@@ -407,7 +408,7 @@ def process_frames(
progress.update(1)
continue
temp_frame = cv2.imread(temp_frame_path)
temp_frame = imread_unicode(temp_frame_path)
if temp_frame is None:
print(
f"{NAME}: Warning: Failed to read frame {temp_frame_path}, skipping."
@@ -417,7 +418,7 @@ def process_frames(
continue
result_frame = process_frame(None, temp_frame)
cv2.imwrite(temp_frame_path, result_frame)
imwrite_unicode(temp_frame_path, result_frame)
if progress:
progress.update(1)
@@ -426,12 +427,12 @@ def process_image(
source_path: str | None, target_path: str, output_path: str
) -> None:
"""Processes a single image file."""
target_frame = cv2.imread(target_path)
target_frame = imread_unicode(target_path)
if target_frame is None:
print(f"{NAME}: Error: Failed to read target image {target_path}")
return
result_frame = process_frame(None, target_frame)
cv2.imwrite(output_path, result_frame)
imwrite_unicode(output_path, result_frame)
print(f"{NAME}: Enhanced image saved to {output_path}")
@@ -4,10 +4,9 @@ from typing import Any, List
import os
import threading
import cv2
import modules.globals
import modules.processors.frame.core
from modules import imread_unicode, imwrite_unicode
from modules.core import update_status
from modules.face_analyser import get_one_face
from modules.typing import Frame, Face
@@ -102,24 +101,24 @@ def process_frames(
source_path: str | None, temp_frame_paths: List[str], progress: Any = None
) -> None:
for temp_frame_path in temp_frame_paths:
temp_frame = cv2.imread(temp_frame_path)
temp_frame = imread_unicode(temp_frame_path)
if temp_frame is None:
if progress:
progress.update(1)
continue
result = process_frame(None, temp_frame)
cv2.imwrite(temp_frame_path, result)
imwrite_unicode(temp_frame_path, result)
if progress:
progress.update(1)
def process_image(source_path: str | None, target_path: str, output_path: str) -> None:
target_frame = cv2.imread(target_path)
target_frame = imread_unicode(target_path)
if target_frame is None:
print(f"{NAME}: Error: Failed to read target image {target_path}")
return
result_frame = process_frame(None, target_frame)
cv2.imwrite(output_path, result_frame)
imwrite_unicode(output_path, result_frame)
print(f"{NAME}: Enhanced image saved to {output_path}")
@@ -4,10 +4,9 @@ from typing import Any, List
import os
import threading
import cv2
import modules.globals
import modules.processors.frame.core
from modules import imread_unicode, imwrite_unicode
from modules.core import update_status
from modules.face_analyser import get_one_face
from modules.typing import Frame, Face
@@ -102,24 +101,24 @@ def process_frames(
source_path: str | None, temp_frame_paths: List[str], progress: Any = None
) -> None:
for temp_frame_path in temp_frame_paths:
temp_frame = cv2.imread(temp_frame_path)
temp_frame = imread_unicode(temp_frame_path)
if temp_frame is None:
if progress:
progress.update(1)
continue
result = process_frame(None, temp_frame)
cv2.imwrite(temp_frame_path, result)
imwrite_unicode(temp_frame_path, result)
if progress:
progress.update(1)
def process_image(source_path: str | None, target_path: str, output_path: str) -> None:
target_frame = cv2.imread(target_path)
target_frame = imread_unicode(target_path)
if target_frame is None:
print(f"{NAME}: Error: Failed to read target image {target_path}")
return
result_frame = process_frame(None, target_frame)
cv2.imwrite(output_path, result_frame)
imwrite_unicode(output_path, result_frame)
print(f"{NAME}: Enhanced image saved to {output_path}")
+7 -6
View File
@@ -7,6 +7,7 @@ import numpy as np
import platform
import modules.globals
import modules.processors.frame.core
from modules import imread_unicode, imwrite_unicode
from modules.core import update_status
from modules.face_analyser import get_one_face, get_many_faces, default_source_face
from modules.typing import Face, Frame
@@ -917,7 +918,7 @@ def process_frames(
# Log the error but allow proceeding; subsequent check will stop processing.
else:
try:
source_img = cv2.imread(source_path)
source_img = imread_unicode(source_path)
if source_img is None:
# Specific error for file reading failure
update_status(f"Error reading source image file {source_path}. Please check the path and file integrity.", NAME)
@@ -957,7 +958,7 @@ def process_frames(
# Read the target frame
temp_frame = None
try:
temp_frame = cv2.imread(temp_frame_path)
temp_frame = imread_unicode(temp_frame_path)
if temp_frame is None:
print(f"{NAME}: Error: Could not read frame: {temp_frame_path}, skipping.")
if progress:
@@ -995,7 +996,7 @@ def process_frames(
# Write the result back to the same frame path with optimized compression
try:
# Use PNG compression level 3 (faster) instead of default 9
write_success = cv2.imwrite(temp_frame_path, result_frame, [cv2.IMWRITE_PNG_COMPRESSION, 3])
write_success = imwrite_unicode(temp_frame_path, result_frame, [cv2.IMWRITE_PNG_COMPRESSION, 3])
if not write_success:
print(f"{NAME}: Error: Failed to write processed frame to {temp_frame_path}")
except Exception as write_e:
@@ -1025,7 +1026,7 @@ def process_image(source_path: str, target_path: str, output_path: str) -> None:
# Read target first
try:
target_frame = cv2.imread(target_path)
target_frame = imread_unicode(target_path)
if target_frame is None:
update_status(f"Error: Could not read target image: {target_path}", NAME)
return
@@ -1044,7 +1045,7 @@ def process_image(source_path: str, target_path: str, output_path: str) -> None:
else: # Simple mode
try:
source_img = cv2.imread(source_path)
source_img = imread_unicode(source_path)
if source_img is None:
update_status(f"Error: Could not read source image: {source_path}", NAME)
return
@@ -1060,7 +1061,7 @@ def process_image(source_path: str, target_path: str, output_path: str) -> None:
# Write the result if processing was successful
if result is not None:
write_success = cv2.imwrite(output_path, result)
write_success = imwrite_unicode(output_path, result)
if write_success:
update_status(f"Output image saved to: {output_path}", NAME)
else: