Files

32 lines
855 B
Python

#!/usr/bin/env python
"""把图片转成连续的 HWC uint8 缓冲,供 C++ 参考实现读取与对拍。
uv run python scripts/dump_raw.py 某张图.png /tmp/image.bin
打印 `宽 高 通道`,直接喂给 deploy/cpp 的 film_predict。
"""
import sys
from pathlib import Path
import numpy as np
from PIL import Image
def main() -> int:
if len(sys.argv) != 3:
print(__doc__)
return 1
with Image.open(sys.argv[1]) as handle:
image = handle.convert("L") if handle.mode in ("L", "1", "I;16") else handle.convert("RGB")
array = np.asarray(image)
if array.ndim == 2:
array = array[..., None]
Path(sys.argv[2]).write_bytes(np.ascontiguousarray(array).tobytes())
print(array.shape[1], array.shape[0], array.shape[2])
return 0
if __name__ == "__main__":
raise SystemExit(main())