{ "cells": [ { "cell_type": "markdown", "id": "dc4ef0c3", "metadata": {}, "source": [ "# Pipeline walkthrough\n", "\n", "Step through the extraction pipeline on a single photo to see what each stage produces.\n", "Requires `pip install -e \".[notebook]\"` from the repository root." ] }, { "cell_type": "code", "execution_count": null, "id": "221851b3", "metadata": {}, "outputs": [], "source": [ "import math\n", "from pathlib import Path\n", "\n", "import cv2 as cv\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "from rowing_stats.display import crop_display\n", "from rowing_stats.image_io import get_datetime_taken, load_image, pil_to_cv\n", "from rowing_stats.ocr import ocr_image, preprocess_for_ocr\n", "from rowing_stats.parsing import parse_stats" ] }, { "cell_type": "code", "execution_count": null, "id": "438ecbd5", "metadata": {}, "outputs": [], "source": [ "def plot_images(imgs: list[np.ndarray]):\n", " \"\"\"\n", " Plot a list of images in a single matplotlib figure.\n", "\n", " Parameters\n", " ----------\n", " imgs : list[np.ndarray]\n", " List of images (H×W greyscale or H×W×3 BGR arrays).\n", " \"\"\"\n", " if not imgs:\n", " return\n", "\n", " n = len(imgs)\n", " cols = math.ceil(math.sqrt(n))\n", " rows = math.ceil(n / cols)\n", "\n", " fig, axes = plt.subplots(rows, cols, figsize=(cols * 5, rows * 5))\n", " axes = np.atleast_1d(axes).ravel()\n", "\n", " for ax, img in zip(axes, imgs):\n", " if img.ndim == 2:\n", " ax.imshow(img, cmap=\"gray\")\n", " else:\n", " ax.imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB))\n", " ax.axis(\"off\")\n", "\n", " # Hide any unused subplots\n", " for ax in axes[len(imgs):]:\n", " ax.axis(\"off\")\n", "\n", " plt.tight_layout()\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "da8bada5", "metadata": {}, "outputs": [], "source": [ "photos_path = Path(\"../photos\")\n", "img = load_image(photos_path / \"IMG_5413.JPEG\")\n", "arr = pil_to_cv(img)\n", "print(get_datetime_taken(img))" ] }, { "cell_type": "code", "execution_count": null, "id": "cb01649f", "metadata": {}, "outputs": [], "source": [ "warped = crop_display(arr)\n", "plot_images([arr, warped, preprocess_for_ocr(warped)])" ] }, { "cell_type": "code", "execution_count": null, "id": "5dd910f8", "metadata": {}, "outputs": [], "source": [ "text = ocr_image(warped)\n", "print(text)\n", "parse_stats(text)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }