#!/usr/bin/env python3 import argparse import json from pathlib import Path import cv2 parser = argparse.ArgumentParser(description="Locate a template image inside a larger image.") parser.add_argument("scene", type=Path) parser.add_argument("template", type=Path) parser.add_argument("output", type=Path) args = parser.parse_args() scene_color = cv2.imread(str(args.scene), cv2.IMREAD_COLOR) scene_gray = cv2.imread(str(args.scene), cv2.IMREAD_GRAYSCALE) template_gray = cv2.imread(str(args.template), cv2.IMREAD_GRAYSCALE) if scene_color is None or scene_gray is None: raise SystemExit(f"could not read scene image: {args.scene}") if template_gray is None: raise SystemExit(f"could not read template image: {args.template}") if template_gray.shape[0] > scene_gray.shape[0] or template_gray.shape[1] > scene_gray.shape[1]: raise SystemExit("template image must not be larger than the scene image")