28 lines
973 B
Python
28 lines
973 B
Python
|
|
# ruff: noqa
|
||
|
|
# Upstream helper intentionally preserved verbatim, including its unused path branches.
|
||
|
|
# Copyright 2024-2025 The Alibaba Wan Team Authors. All rights reserved.
|
||
|
|
# Exact read_img helper captured from Wan2.2 preprocess/pose2d_utils.py.
|
||
|
|
# Kept in CPU tests to verify upstream ndarray BGR conversion without ONNX/GPU.
|
||
|
|
import numpy as np
|
||
|
|
from PIL import Image
|
||
|
|
|
||
|
|
def read_img(image, convert='RGB', check_exist=False):
|
||
|
|
if isinstance(image, str):
|
||
|
|
if check_exist and not osp.exists(image):
|
||
|
|
return None
|
||
|
|
try:
|
||
|
|
img = Image.open(image)
|
||
|
|
if convert:
|
||
|
|
img = img.convert(convert)
|
||
|
|
except:
|
||
|
|
raise IOError('File error: ', image)
|
||
|
|
return np.asarray(img)
|
||
|
|
else:
|
||
|
|
if isinstance(image, np.ndarray):
|
||
|
|
if convert:
|
||
|
|
return image[..., ::-1]
|
||
|
|
else:
|
||
|
|
if convert:
|
||
|
|
img = img.convert(convert)
|
||
|
|
return np.asarray(img)
|