{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Camera Models" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import torch\n", "from pyrad.cameras import cameras\n", "import plotly.graph_objects as go\n", "import mediapy as media" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def vis_camera_rays(camera):\n", " coords = camera.get_image_coords()\n", " coords[..., 0] /= camera.get_image_height()\n", " coords[..., 1] /= camera.get_image_width()\n", " coords = torch.cat([coords, torch.ones((*coords.shape[:-1], 1))], dim=-1)\n", "\n", " print(\"Image UV coordinates\")\n", " media.show_image(coords, width=400)\n", "\n", " ray_bundle = camera.get_camera_ray_bundle()\n", "\n", " print(\"Pixel Area\")\n", " media.show_image(ray_bundle.pixel_area, width=400, cmap=\"hot\")\n", "\n", " origins = ray_bundle.origins.view(-1, 3)\n", " directions = ray_bundle.directions.view(-1, 3)\n", " coords = coords.view(-1, 3)\n", "\n", " lines = torch.empty((origins.shape[0] * 2, 3))\n", " lines[0::2] = origins\n", " lines[1::2] = origins + directions\n", "\n", " colors = torch.empty((coords.shape[0] * 2, 3))\n", " colors[0::2] = coords\n", " colors[1::2] = coords\n", "\n", " fig = go.Figure(\n", " data=go.Scatter3d(\n", " x=lines[:, 0],\n", " y=lines[:, 1],\n", " z=lines[:, 2],\n", " marker=dict(\n", " size=4,\n", " color=colors,\n", " ),\n", " line=dict(color=\"lightblue\", width=1),\n", " )\n", " )\n", "\n", " fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pinhole Camera Model" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Image UV coordinates\n" ] }, { "data": { "text/html": [ "