cv2.rectangle(scene_color, top_left, bottom_right, (0, 0, 255), 3) cv2.putText( scene_color, f"difference {best_difference:.3f}", (top_left[0], max(25, top_left[1] - 10)), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2, ) args.output.parent.mkdir(parents=True, exist_ok=True) if not cv2.imwrite(str(args.output), scene_color): raise SystemExit(f"could not write output image: {args.output}") report_path = args.output.with_suffix(".json") report_path.write_text( json.dumps( { "best_difference": best_difference, "top_left": top_left, "bottom_right": bottom_right, }, indent=2, ) + "\n", encoding="utf-8", ) print(f"scene size: {scene_gray.shape[1]}x{scene_gray.shape[0]}") print(f"template size: {width}x{height}") print(f"result map: {result.shape[1]}x{result.shape[0]}") print(f"best difference: {best_difference:.3f}") print(f"top-left: x={top_left[0]}, y={top_left[1]}") print(f"bottom-right: x={bottom_right[0]}, y={bottom_right[1]}") print(f"report: {report_path}") print(f"output: {args.output}")