Skip to content

Commit 71a6739

Browse files
update: compute H (#120)
* add: demo * update: demo images path * update: clear outputs * update: compute H * style: pre-commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2f346fc commit 71a6739

File tree

2 files changed

+158
-2
lines changed

2 files changed

+158
-2
lines changed

imcui/ui/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,8 @@ def compute_geometry(
623623
geo_info["Fundamental"] = F.tolist()
624624
geo_info["mask_f"] = mask_f
625625
H, mask_h = proc_ransac_matches(
626-
mkpts1,
627626
mkpts0,
627+
mkpts1,
628628
ransac_method,
629629
ransac_reproj_threshold,
630630
ransac_confidence,
@@ -683,7 +683,8 @@ def wrap_images(
683683

684684
title: List[str] = []
685685
if geom_type == "Homography":
686-
rectified_image1 = cv2.warpPerspective(img1, H, (w0, h0))
686+
H_inv = np.linalg.inv(H)
687+
rectified_image1 = cv2.warpPerspective(img1, H_inv, (w0, h0))
687688
title = ["Image 0", "Image 1 - warped"]
688689
elif geom_type == "Fundamental":
689690
if geom_type not in geo_info:

tests/demo.ipynb

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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

Comments
 (0)