API reference
kornia_moons.feature
Conversions between OpenCV and kornia local feature formats.
OpenCV cv2.KeyPoint lists ↔ kornia local affine frames (LAFs),
cv2.DMatch lists ↔ kornia match tensors, and nn.Module wrappers
that let OpenCV detectors and descriptors slot into kornia pipelines.
OpenCVDetectorKornia
Bases: Module
Wrap an OpenCV detector into a kornia-compatible detection module.
The wrapped detector runs on the numpy image under the hood; the module accepts and returns torch tensors, so it can slot into kornia pipelines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
opencv_detector
|
Any OpenCV detector exposing |
required | |
mrSize
|
float
|
Measurement-region scale multiplier (6.0 for SIFT, 1.0 for ORB). |
6.0
|
make_upright
|
If True, deduplicate keypoints and zero their angles. |
False
|
|
max_kpts
|
Keep at most this many of the highest-response keypoints,
applied whether or not |
-1
|
Example
detector = OpenCVDetectorKornia(cv2.SIFT_create(500)) timg = kornia.image_to_tensor(img, False).float() / 255. lafs, resps = detector(timg)
Source code in kornia_moons/feature.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
forward(x, mask=None)
Detect keypoints on a batched image tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Image tensor of shape :math: |
required |
mask
|
Optional detection mask, :math: |
None
|
Returns:
| Type | Description |
|---|---|
|
LAFs of shape :math: |
Source code in kornia_moons/feature.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
OpenCVFeatureKornia
Bases: Module
Wrap an OpenCV detect-and-describe pipeline for kornia.
The wrapped feature (e.g. cv2.SIFT_create()) runs detectAndCompute
on the numpy image under the hood; the module accepts and returns torch
tensors, so it can slot into kornia pipelines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
opencv_detector
|
Any OpenCV feature exposing |
required | |
mrSize
|
float
|
Measurement-region scale multiplier (6.0 for SIFT, 1.0 for ORB). |
6.0
|
Example
feature = OpenCVFeatureKornia(cv2.SIFT_create(500)) timg = kornia.image_to_tensor(img, False).float() / 255. lafs, resps, descs = feature(timg)
Source code in kornia_moons/feature.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
forward(x, mask=None)
Detect and describe keypoints on a batched image tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Image tensor of shape :math: |
required |
mask
|
Optional detection mask, :math: |
None
|
Returns:
| Type | Description |
|---|---|
|
LAFs of shape :math: |
|
|
math: |
Source code in kornia_moons/feature.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
OpenCVDetectorWithAffNetKornia
Bases: Module
Combine an OpenCV detector with kornia's AffNet affine-shape refinement.
The wrapped detector locates keypoints on the numpy image, and kornia's
LAFAffNetShapeEstimator then refines the elliptical shape of each
LAF. Note that AffNet's pretrained weights are downloaded on first use,
and the original keypoint orientation is preserved after refinement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
opencv_detector
|
Any OpenCV detector exposing |
required | |
make_upright
|
If True, deduplicate keypoints and zero their angles. |
False
|
|
mrSize
|
float
|
Measurement-region scale multiplier (6.0 for SIFT, 1.0 for ORB). |
6.0
|
max_kpts
|
Keep at most this many of the highest-response keypoints,
applied whether or not |
-1
|
Example
detector = OpenCVDetectorWithAffNetKornia(cv2.SIFT_create(500)) timg = kornia.image_to_tensor(img, False).float() / 255. lafs, resps = detector(timg)
Source code in kornia_moons/feature.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
forward(x, mask=None)
Detect keypoints and refine their affine shape with AffNet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Image tensor of shape :math: |
required |
mask
|
Optional detection mask, :math: |
None
|
Returns:
| Type | Description |
|---|---|
|
LAFs of shape :math: |
Source code in kornia_moons/feature.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
to_numpy_image(img)
Load or convert an image into an RGB numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Union[str, array, Tensor]
|
Image file path, |
required |
Returns:
| Type | Description |
|---|---|
|
The image as an |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
FileNotFoundError
|
If |
Source code in kornia_moons/feature.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
to_torch(x)
Convert a Python list or numpy array to a torch tensor, passing tensors through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[List, array, Tensor]
|
List, numpy array, or torch tensor to convert. |
required |
Returns:
| Type | Description |
|---|---|
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in kornia_moons/feature.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
to_np(array)
Convert a tensor or sequence to a numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Union[List, Tuple, ndarray, Tensor]
|
List, tuple, numpy array, or torch tensor to convert. Tensors are detached and moved to CPU before conversion. |
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in kornia_moons/feature.py
78 79 80 81 82 83 84 85 86 87 88 89 90 | |
laf_from_opencv_kpts(kpts, mrSize=6.0, device=torch.device('cpu'), with_resp=False)
Convert OpenCV keypoints into kornia local affine frames (LAFs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kpts
|
List[KeyPoint]
|
List of N OpenCV keypoints. Keypoints with |
required |
mrSize
|
float
|
Measurement-region scale multiplier applied to the keypoint size. Use 6.0 for SIFT-like detectors and 1.0 for ORB-like detectors, matching the OpenCV description-region conventions. |
6.0
|
device
|
device
|
Device to place the output tensors on. |
device('cpu')
|
with_resp
|
bool
|
If True, also return the keypoint responses. |
False
|
Returns:
| Type | Description |
|---|---|
Union[Tensor, Tuple[Tensor, Tensor]]
|
LAFs of shape :math: |
Union[Tensor, Tuple[Tensor, Tensor]]
|
a tuple of the LAFs and responses of shape :math: |
Example
img = cv2.imread('data/strahov.png') kps, descs = cv2.ORB_create(500).detectAndCompute(img, None) lafs, resp = laf_from_opencv_kpts(kps, mrSize=1.0, with_resp=True)
Source code in kornia_moons/feature.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
opencv_kpts_from_laf(lafs, mrSize=1.0, resps=None)
Convert kornia local affine frames (LAFs) back to OpenCV keypoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lafs
|
Tensor
|
LAFs of shape :math: |
required |
mrSize
|
float
|
Measurement-region scale multiplier to divide out of the LAF
scale. Must match the |
1.0
|
resps
|
Optional[Tensor]
|
Optional keypoint responses of shape :math: |
None
|
Returns:
| Type | Description |
|---|---|
List[KeyPoint]
|
List of N OpenCV keypoints. |
Note
A LAF does not store the OpenCV octave and class_id fields,
so keypoints converted back get the defaults (octave=0,
class_id=-1). OpenCV descriptor extractors still work on such
keypoints.
Example
lafs, resp = laf_from_opencv_kpts(kps, mrSize=1.0, with_resp=True) kps_back = opencv_kpts_from_laf(lafs, 1.0, resp)
Source code in kornia_moons/feature.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
laf_from_opencv_ORB_kpts(kpts, device=torch.device('cpu'), with_resp=False)
Convert ORB keypoints into kornia LAFs using the ORB mrSize convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kpts
|
List[KeyPoint]
|
List of N OpenCV ORB keypoints. |
required |
device
|
device
|
Device to place the output tensors on. |
device('cpu')
|
with_resp
|
bool
|
If True, also return the keypoint responses. |
False
|
Returns:
| Type | Description |
|---|---|
Union[Tensor, Tuple[Tensor, Tensor]]
|
LAFs of shape :math: |
Union[Tensor, Tuple[Tensor, Tensor]]
|
a tuple of the LAFs and responses of shape :math: |
Source code in kornia_moons/feature.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
laf_from_opencv_SIFT_kpts(kpts, device=torch.device('cpu'), with_resp=False)
Convert SIFT keypoints into kornia LAFs using the SIFT mrSize convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kpts
|
List[KeyPoint]
|
List of N OpenCV SIFT keypoints. |
required |
device
|
device
|
Device to place the output tensors on. |
device('cpu')
|
with_resp
|
bool
|
If True, also return the keypoint responses. |
False
|
Returns:
| Type | Description |
|---|---|
Union[Tensor, Tuple[Tensor, Tensor]]
|
LAFs of shape :math: |
Union[Tensor, Tuple[Tensor, Tensor]]
|
a tuple of the LAFs and responses of shape :math: |
Source code in kornia_moons/feature.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
opencv_SIFT_kpts_from_laf(lafs, resps=None)
Convert kornia LAFs to OpenCV keypoints using the SIFT mrSize convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lafs
|
LAFs of shape :math: |
required | |
resps
|
Optional[Tensor]
|
Optional keypoint responses of shape :math: |
None
|
Returns:
| Type | Description |
|---|---|
|
List of N OpenCV keypoints. |
Source code in kornia_moons/feature.py
199 200 201 202 203 204 205 206 207 208 209 | |
opencv_ORB_kpts_from_laf(lafs, resps=None)
Convert kornia LAFs to OpenCV keypoints using the ORB mrSize convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lafs
|
LAFs of shape :math: |
required | |
resps
|
Optional[Tensor]
|
Optional keypoint responses of shape :math: |
None
|
Returns:
| Type | Description |
|---|---|
|
List of N OpenCV keypoints. |
Source code in kornia_moons/feature.py
211 212 213 214 215 216 217 218 219 220 221 | |
cv2_matches_from_kornia(match_dists, match_idxs)
Convert kornia match distances and indexes to a list of cv2.DMatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
match_dists
|
Tensor
|
Match distances of shape :math: |
required |
match_idxs
|
Tensor
|
Match indexes (query, train) of shape :math: |
required |
Returns:
| Type | Description |
|---|---|
List[DMatch]
|
List of N |
Example
dists, idxs = kornia.feature.match_nn(descs1, descs2) cv2_matches = cv2_matches_from_kornia(dists, idxs)
Source code in kornia_moons/feature.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
kornia_matches_from_cv2(cv2_matches, device=torch.device('cpu'))
Convert a list of cv2.DMatch to kornia match distance and index tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cv2_matches
|
List of N |
required | |
device
|
Device to place the output tensors on. |
device('cpu')
|
Returns:
| Type | Description |
|---|---|
|
Tuple of match distances of shape :math: |
|
|
indexes (query, train) of shape :math: |
Example
cv2_matches = cv2_matches_from_kornia(match_dists, match_idxs) match_dists_back, match_idxs_back = kornia_matches_from_cv2(cv2_matches)
Source code in kornia_moons/feature.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
make_keypoints_upright(kpts)
Deduplicate keypoints by response and zero their orientations.
Keypoints are considered duplicates when they share the same response
as the previous keypoint in the input list. Note that this mutates the
input keypoints in place (setting angle = 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kpts
|
List of OpenCV keypoints, assumed sorted by response. |
required |
Returns:
| Type | Description |
|---|---|
|
The deduplicated, upright keypoints sorted by response, descending. |
Source code in kornia_moons/feature.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
kornia_moons.viz
Visualization helpers for local features and matches.
Drawing kornia LAFs over images, tentative/inlier matches between image pairs (with optional epipolar lines or reprojected corners), plain point matches from detector-free matchers such as LoFTR, epipolar errors, and SOLD2-style line segments.
visualize_LAF(img, LAF, img_idx=0, color='r', linewidth=1, draw_ori=True, fig=None, ax=None, return_fig_ax=False, **kwargs)
Draw local affine frames (LAFs) over an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Batched image tensor of shape :math: |
required | |
LAF
|
LAFs of shape :math: |
required | |
img_idx
|
Index of the image in the batch to draw on. |
0
|
|
color
|
Matplotlib color for the LAF outlines. |
'r'
|
|
linewidth
|
Line width of the LAF outlines. |
1
|
|
draw_ori
|
If True, also draw the orientation line of each LAF. |
True
|
|
fig
|
Optional existing matplotlib figure to draw on. |
None
|
|
ax
|
Optional existing matplotlib axes to draw on. |
None
|
|
return_fig_ax
|
If True, return the figure and axes instead of None. |
False
|
|
**kwargs
|
Extra keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple of |
Example
lafs, resp = laf_from_opencv_kpts(kps, mrSize=1.0, with_resp=True) visualize_LAF(image_to_tensor(img, False), lafs, 0, 'y', draw_ori=False)
Source code in kornia_moons/viz.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
epilines_to_start_end_points(epi, h, w)
Clip epipolar lines to their image-boundary start/end points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epi
|
Epipolar line coefficients |
required | |
h
|
Image height. |
required | |
w
|
Image width. |
required |
Returns:
| Type | Description |
|---|---|
|
Stacked start and end points of shape :math: |
|
|
|
Source code in kornia_moons/viz.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
draw_LAF_matches(lafs1, lafs2, tent_idxs, img1, img2, inlier_mask=None, draw_dict={'inlier_color': (0.2, 1, 0.2), 'tentative_color': (0.8, 0.8, 0), 'feature_color': (0.2, 0.5, 1), 'vertical': False}, Fm=None, H=None, fig=None, ax=None, return_fig_ax=False)
This function draws LAFs, tentative matches, inliers epipolar lines (if F is provided), and image1 corners reprojection into image 2 (if H is provided)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lafs1
|
LAFs of image 1, shape :math: |
required | |
lafs2
|
LAFs of image 2, shape :math: |
required | |
tent_idxs
|
Tentative match indexes (query, train) of shape :math: |
required | |
img1
|
First image, path/tensor/numpy array. |
required | |
img2
|
Second image, path/tensor/numpy array. |
required | |
inlier_mask
|
Optional boolean array/list of length M marking inliers
among |
None
|
|
draw_dict
|
Drawing options. Keys: |
{'inlier_color': (0.2, 1, 0.2), 'tentative_color': (0.8, 0.8, 0), 'feature_color': (0.2, 0.5, 1), 'vertical': False}
|
|
Fm
|
Optional[array]
|
Optional fundamental matrix of shape :math: |
None
|
H
|
Optional[array]
|
Optional homography of shape :math: |
None
|
fig
|
Optional existing matplotlib figure to draw on. |
None
|
|
ax
|
Optional
|
Optional existing matplotlib axes to draw on. |
None
|
return_fig_ax
|
If True, return the figure and axes instead of None. |
False
|
Returns:
| Type | Description |
|---|---|
|
Tuple of |
Example
match_dists, match_idxs = kornia.feature.match_snn(descs1, descs2, 0.98) draw_LAF_matches(lafs1, lafs2, match_idxs, img1, img2, mask, ... draw_dict={"inlier_color": (0.2, 1, 0.2), ... "tentative_color": (0.8, 0.8, 0), ... "feature_color": None, "vertical": False}, H=H)
Source code in kornia_moons/viz.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
draw_point_matches(pts1, pts2, img1, img2, inlier_mask=None, draw_dict={'inlier_color': (0.2, 1, 0.2), 'tentative_color': (0.8, 0.8, 0), 'vertical': False}, Fm=None, H=None, fig=None, ax=None, return_fig_ax=False)
Draw already-corresponded point matches, as produced by detector-free matchers such as LoFTR, LightGlue, or DISK.
Point i of pts1 is matched to point i of pts2; the points
are wrapped into unit-scale upright LAFs and drawn with
:func:draw_LAF_matches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts1
|
Matched points in image 1, array/tensor of shape :math: |
required | |
pts2
|
Matched points in image 2, array/tensor of shape :math: |
required | |
img1
|
First image, path/tensor/numpy array. |
required | |
img2
|
Second image, path/tensor/numpy array. |
required | |
inlier_mask
|
Optional boolean array/list of length N marking inliers. |
None
|
|
draw_dict
|
Drawing options, see :func: |
{'inlier_color': (0.2, 1, 0.2), 'tentative_color': (0.8, 0.8, 0), 'vertical': False}
|
|
Fm
|
Optional[array]
|
Optional fundamental matrix of shape :math: |
None
|
H
|
Optional[array]
|
Optional homography of shape :math: |
None
|
fig
|
Optional existing matplotlib figure to draw on. |
None
|
|
ax
|
Optional
|
Optional existing matplotlib axes to draw on. |
None
|
return_fig_ax
|
If True, return the figure and axes instead of None. |
False
|
Returns:
| Type | Description |
|---|---|
|
Tuple of |
Example
out = KF.LoFTR(pretrained='outdoor')({"image0": timg1, "image1": timg2}) mkpts0 = out['keypoints0'].cpu().numpy() mkpts1 = out['keypoints1'].cpu().numpy() Fm, inliers = cv2.findFundamentalMat(mkpts0, mkpts1, cv2.USAC_MAGSAC, 0.5) draw_point_matches(mkpts0, mkpts1, img1, img2, inliers, Fm=Fm)
Source code in kornia_moons/viz.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
draw_LAF_matches_from_result_dict(result_dict, img1, img2, draw_dict={'inlier_color': (0.2, 1, 0.2), 'tentative_color': (0.8, 0.8, 0), 'feature_color': (0.2, 0.5, 1), 'vertical': False})
Draw matches from a result dictionary produced by a matching pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_dict
|
Dictionary with keys |
required | |
img1
|
First image, path/tensor/numpy array. |
required | |
img2
|
Second image, path/tensor/numpy array. |
required | |
draw_dict
|
Drawing options, see :func: |
{'inlier_color': (0.2, 1, 0.2), 'tentative_color': (0.8, 0.8, 0), 'feature_color': (0.2, 0.5, 1), 'vertical': False}
|
Returns:
| Type | Description |
|---|---|
|
None. Forwards to :func: |
Source code in kornia_moons/viz.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
draw_LAF_inliers_perspective_repjojected(lafs1, lafs2, tent_idxs, img1, img2, inlier_mask=None, draw_dict={'inlier_color': (0.2, 1, 0.2), 'reprojected_color': (0.2, 0.5, 1), 'vertical': False}, H=None, fig=None, ax=None, return_fig_ax=False)
This function draws tentative matches and inliers given the homography H
Note that the function name keeps its original typo
(repjojected) for backward compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lafs1
|
LAFs of image 1, shape :math: |
required | |
lafs2
|
LAFs of image 2, shape :math: |
required | |
tent_idxs
|
Tentative match indexes (query, train) of shape :math: |
required | |
img1
|
First image, path/tensor/numpy array. |
required | |
img2
|
Second image, path/tensor/numpy array. |
required | |
inlier_mask
|
Boolean array/list of length M marking inliers among
|
None
|
|
draw_dict
|
Drawing options. Keys: |
{'inlier_color': (0.2, 1, 0.2), 'reprojected_color': (0.2, 0.5, 1), 'vertical': False}
|
|
H
|
array
|
Homography of shape :math: |
None
|
fig
|
Optional existing matplotlib figure to draw on. |
None
|
|
ax
|
Optional
|
Optional existing matplotlib axes to draw on. |
None
|
return_fig_ax
|
If True, return the figure and axes instead of None. |
False
|
Returns:
| Type | Description |
|---|---|
|
Tuple of |
Source code in kornia_moons/viz.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
draw_epipolar_errors_in_single_image(kp1, kp2, Fm1to2, img, draw_dict={'error_color': (1, 0.2, 0.2), 'feature_color': (0.2, 0.5, 1), 'figsize': (10, 10), 'markersize': 8}, img_index=2, ax=None, title=None)
This function draws epipolar errors in single image
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kp1
|
array
|
Keypoints in image 1, array of shape :math: |
required |
kp2
|
array
|
Keypoints in image 2, array of shape :math: |
required |
Fm1to2
|
array
|
Fundamental matrix mapping points from image 1 to image 2,
of shape :math: |
required |
img
|
Image to draw on (the one indexed by |
required | |
draw_dict
|
Drawing options. Keys: |
{'error_color': (1, 0.2, 0.2), 'feature_color': (0.2, 0.5, 1), 'figsize': (10, 10), 'markersize': 8}
|
|
img_index
|
int
|
Which image (1 or 2) |
2
|
ax
|
Optional
|
Optional existing matplotlib axes to draw on. |
None
|
title
|
Optional plot title. |
None
|
Returns:
| Type | Description |
|---|---|
|
The matplotlib axes the errors were drawn on. |
Source code in kornia_moons/viz.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
plot_images(imgs, titles=None, cmaps='gray', dpi=100, size=6, pad=0.5)
Plot a horizontal strip of images and establish the figure that
:func:plot_lines and :func:plot_color_line_matches draw on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
imgs
|
List of NumPy or PyTorch images, RGB :math: |
required | |
titles
|
Optional list of strings, as titles for each image. |
None
|
|
cmaps
|
Colormap, or list of colormaps (one per image), used for monochrome images. |
'gray'
|
|
dpi
|
Figure resolution in dots per inch. |
100
|
|
size
|
Width in inches allotted per image; the figure height is |
6
|
|
pad
|
Padding passed to |
0.5
|
Returns:
| Type | Description |
|---|---|
|
None. The created figure and axes become the current matplotlib |
|
|
figure, ready for :func: |
Source code in kornia_moons/viz.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
plot_lines(lines, line_colors='orange', point_colors='cyan', ps=4, lw=2, indices=(0, 1))
Plot line segments and their endpoints on the current figure's axes.
Must be called after :func:plot_images, which creates the figure and
axes this function draws on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
List of arrays of shape :math: |
required | |
line_colors
|
Color, or list of colors (one per image), for the line segments. |
'orange'
|
|
point_colors
|
Color, or list of colors (one per image), for the endpoints. |
'cyan'
|
|
ps
|
Size of the endpoint markers, in points. |
4
|
|
lw
|
Line width, in points. |
2
|
|
indices
|
Indexes of the current figure's axes to draw the lines on. |
(0, 1)
|
Returns:
| Type | Description |
|---|---|
|
None. The lines and points are added to the existing axes in place. |
Source code in kornia_moons/viz.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
plot_color_line_matches(lines, lw=2, indices=(0, 1))
Plot matched line segments on the current figure's axes, giving each match its own color.
Must be called after :func:plot_images, which creates the figure and
axes this function draws on. Used to visualize SOLD2-style line matches
between two images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
List of arrays of shape :math: |
required | |
lw
|
Line width, in points. |
2
|
|
indices
|
Indexes of the current figure's axes to draw the lines on. |
(0, 1)
|
Returns:
| Type | Description |
|---|---|
|
None. The lines are added to the existing axes in place. |
Source code in kornia_moons/viz.py
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | |