from argparse import ArgumentParser from pathlib import Path import cv2 as cv parser = ArgumentParser() parser.add_argument("--input", default="input/scene.png", help="Source image") parser.add_argument("--output", default="output/scene-copy.png", help="Output image") args = parser.parse_args() input_path = Path(args.input) output_path = Path(args.output) output_path.parent.mkdir(parents=True, exist_ok=True) image = cv.imread(str(input_path), cv.IMREAD_COLOR) if image is None: raise SystemExit(f"could not read input image: {input_path}") if not cv.imwrite(str(output_path), image): raise SystemExit(f"could not write output image: {output_path}") written = cv.imread(str(output_path), cv.IMREAD_COLOR) if written is None: raise SystemExit(f"could not read written image: {output_path}") if written.shape != image.shape: raise SystemExit(f"shape changed: source={image.shape} written={written.shape}") source_height, source_width = image.shape[:2] written_height, written_width = written.shape[:2] source_channels = 1 if image.ndim == 2 else image.shape[2] written_channels = 1 if written.ndim == 2 else written.shape[2] print(f"read: {input_path}") print(f"source: {source_width}x{source_height} channels={source_channels} dtype={image.dtype}") print(f"wrote: {output_path}") print(f"verified: {written_width}x{written_height} channels={written_channels} dtype={written.dtype}")