|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "5dc545c2-fe6a-4846-aaf7-8fb22bd4be9d", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import cv2\n", |
| 11 | + "from imcui.ui.utils import DEVICE\n", |
| 12 | + "from imcui.api import ImageMatchingAPI\n", |
| 13 | + "from imcui.ui.viz import display_matches" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "markdown", |
| 18 | + "id": "a2e18a24", |
| 19 | + "metadata": {}, |
| 20 | + "source": [ |
| 21 | + "## Loading images" |
| 22 | + ] |
| 23 | + }, |
| 24 | + { |
| 25 | + "cell_type": "code", |
| 26 | + "execution_count": 2, |
| 27 | + "id": "f7b83a1b-d961-4165-970c-da6254e19704", |
| 28 | + "metadata": {}, |
| 29 | + "outputs": [], |
| 30 | + "source": [ |
| 31 | + "img_path1 = \"data/02928139_3448003521.jpg\"\n", |
| 32 | + "img_path2 = \"data/17295357_9106075285.jpg\"\n", |
| 33 | + "image0 = cv2.imread(str(img_path1))[:, :, ::-1] # RGB\n", |
| 34 | + "image1 = cv2.imread(str(img_path2))[:, :, ::-1] # RGB" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "markdown", |
| 39 | + "id": "24d11817", |
| 40 | + "metadata": {}, |
| 41 | + "source": [ |
| 42 | + "## Dense matching" |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "code", |
| 47 | + "execution_count": null, |
| 48 | + "id": "73ecb33a", |
| 49 | + "metadata": {}, |
| 50 | + "outputs": [], |
| 51 | + "source": [ |
| 52 | + "conf = {\n", |
| 53 | + " \"matcher\": {\n", |
| 54 | + " \"output\": \"matches-loftr\",\n", |
| 55 | + " \"model\": {\n", |
| 56 | + " \"name\": \"loftr\",\n", |
| 57 | + " \"weights\": \"outdoor\",\n", |
| 58 | + " \"max_keypoints\": 2000,\n", |
| 59 | + " \"match_threshold\": 0.2,\n", |
| 60 | + " },\n", |
| 61 | + " \"preprocessing\": {\n", |
| 62 | + " \"grayscale\": True,\n", |
| 63 | + " \"resize_max\": 1024,\n", |
| 64 | + " \"dfactor\": 8,\n", |
| 65 | + " \"width\": 640,\n", |
| 66 | + " \"height\": 480,\n", |
| 67 | + " \"force_resize\": True,\n", |
| 68 | + " },\n", |
| 69 | + " \"max_error\": 1,\n", |
| 70 | + " \"cell_size\": 1,\n", |
| 71 | + " },\n", |
| 72 | + " \"dense\": True,\n", |
| 73 | + "}\n", |
| 74 | + "\n", |
| 75 | + "api = ImageMatchingAPI(conf=conf, device=DEVICE)\n", |
| 76 | + "pred = api(image0, image1)\n", |
| 77 | + "assert pred is not None\n", |
| 78 | + "titles = [\"Image 0 - RANSAC matched keypoints\", \"Image 1 - RANSAC matched keypoints\"]\n", |
| 79 | + "output_matches_ransac, _ = display_matches(pred, titles=titles, tag=\"KPTS_RANSAC\")" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "markdown", |
| 84 | + "id": "8c7e0f67", |
| 85 | + "metadata": {}, |
| 86 | + "source": [ |
| 87 | + "## Sparse matching" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": null, |
| 93 | + "id": "223265ee", |
| 94 | + "metadata": {}, |
| 95 | + "outputs": [], |
| 96 | + "source": [ |
| 97 | + "conf = {\n", |
| 98 | + " \"feature\": {\n", |
| 99 | + " \"output\": \"feats-superpoint-n4096-rmax1600\",\n", |
| 100 | + " \"model\": {\n", |
| 101 | + " \"name\": \"superpoint\",\n", |
| 102 | + " \"nms_radius\": 3,\n", |
| 103 | + " \"max_keypoints\": 4096,\n", |
| 104 | + " \"keypoint_threshold\": 0.000,\n", |
| 105 | + " },\n", |
| 106 | + " \"preprocessing\": {\n", |
| 107 | + " \"grayscale\": True,\n", |
| 108 | + " \"force_resize\": True,\n", |
| 109 | + " \"resize_max\": 1600,\n", |
| 110 | + " \"width\": 640,\n", |
| 111 | + " \"height\": 480,\n", |
| 112 | + " \"dfactor\": 8,\n", |
| 113 | + " },\n", |
| 114 | + " },\n", |
| 115 | + " \"matcher\": {\n", |
| 116 | + " \"output\": \"matches-NN-mutual\",\n", |
| 117 | + " \"model\": {\n", |
| 118 | + " \"name\": \"nearest_neighbor\",\n", |
| 119 | + " \"do_mutual_check\": True,\n", |
| 120 | + " \"match_threshold\": 0.2,\n", |
| 121 | + " },\n", |
| 122 | + " },\n", |
| 123 | + " \"dense\": False,\n", |
| 124 | + "}\n", |
| 125 | + "\n", |
| 126 | + "api = ImageMatchingAPI(conf=conf, device=DEVICE)\n", |
| 127 | + "pred = api(image0, image1)\n", |
| 128 | + "assert pred is not None\n", |
| 129 | + "titles = [\"Image 0 - RANSAC matched keypoints\", \"Image 1 - RANSAC matched keypoints\"]\n", |
| 130 | + "output_matches_ransac, _ = display_matches(pred, titles=titles, tag=\"KPTS_RANSAC\")" |
| 131 | + ] |
| 132 | + } |
| 133 | + ], |
| 134 | + "metadata": { |
| 135 | + "kernelspec": { |
| 136 | + "display_name": "imw", |
| 137 | + "language": "python", |
| 138 | + "name": "imw" |
| 139 | + }, |
| 140 | + "language_info": { |
| 141 | + "codemirror_mode": { |
| 142 | + "name": "ipython", |
| 143 | + "version": 3 |
| 144 | + }, |
| 145 | + "file_extension": ".py", |
| 146 | + "mimetype": "text/x-python", |
| 147 | + "name": "python", |
| 148 | + "nbconvert_exporter": "python", |
| 149 | + "pygments_lexer": "ipython3", |
| 150 | + "version": "3.10.10" |
| 151 | + } |
| 152 | + }, |
| 153 | + "nbformat": 4, |
| 154 | + "nbformat_minor": 5 |
| 155 | +} |
0 commit comments