from pathlib import Path import cv2 def imwrite(*args, **kwargs): Path(args[0]).parent.mkdir(parents=True, exist_ok=True) return cv2.imwrite(*args, **kwargs)