File size: 4,296 Bytes
173dcbd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 66 67 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 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 | ---
title: "API Reference"
description: "Programmatic access to Image Matching WebUI functions"
---
# API Reference
Complete programmatic access to Image Matching WebUI functionality.
## Quick Start
```python
from imcui.api import ImageMatchingAPI
from imcui.ui import get_matcher_zoo
# Get available matchers
matchers = get_matcher_zoo()
# Initialize API
api = ImageMatchingAPI(conf=matchers["superpoint-lightglue"])
# Match two images
result = api(image0, image1)
```
## Core API
### ImageMatchingAPI
Main API class for image matching operations.
```python
from imcui.api import ImageMatchingAPI
api = ImageMatchingAPI(conf=matcher_config, device="cuda")
result = api(image0, image1)
```
**Parameters:**
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `conf` | dict | Yes | - | Matcher configuration |
| `device` | str | No | "cuda" | Device: "cuda", "cpu", "mps" |
**Returns:**
Dictionary containing:
- `keypoints0`, `keypoints1`: Detected keypoints
- `matches`: Pairwise matches
- `scores`: Confidence scores
- `H` (optional): Homography matrix (if RANSAC enabled)
## Matcher Utilities
### Get Available Matchers
```python
from imcui.ui import get_matcher_zoo
matchers = get_matcher_zoo()
print(f"Available: {list(matchers.keys())}")
```
### Get Model Names
```python
from imcui.ui import get_available_model_names
models = get_available_model_names()
```
## Matching Functions
### Run Matching
```python
from imcui.ui import run_matching
result = run_matching(
image0, image1,
matcher_name="superpoint-lightglue",
device="cuda"
)
```
### Run RANSAC
```python
from imcui.ui import run_ransac
filtered_matches = run_ransac(
kp0, kp1, matches,
ransac_method="CV2_USAC_MAGSAC",
threshold=8.0
)
```
### Filter Matches
```python
from imcui.ui import filter_matches
clean_matches = filter_matches(matches, scores, threshold=0.2)
```
## Geometry Functions
### Compute Geometry
```python
from imcui.ui import compute_geometry
H, mask = compute_geometry(
kp0, kp1, matches,
geometry_type="homography",
ransac_method="CV2_USAC_MAGSAC"
)
```
**Geometry Types:**
- `homography` - Planar scenes
- `fundamental` - Calibrated cameras
- `essential` - Stereo vision
## Visualization Functions
### Display Keypoints
```python
from imcui.ui import display_keypoints
result = display_keypoints(
image, keypoints,
color=(0, 255, 0)
)
```
### Display Matches
```python
from imcui.ui import display_matches
result = display_matches(
image0, image1,
kp0, kp1, matches,
color=(0, 255, 0)
)
```
### Plot Images
```python
from imcui.ui import plot_images
plot_images([img0, img1], titles=["Image 0", "Image 1"])
```
## Utility Functions
### Get Configuration Path
```python
from imcui import get_default_config_path
config_path = get_default_config_path()
```
### Get Data Path
```python
from imcui import get_example_data_path
data_path = get_example_data_path()
```
### Get Version
```python
from imcui import get_version
version = get_version()
```
## Model Caching
### ARC Size-Aware Cache
```python
from imcui.ui import ARCSizeAwareModelCache
cache = ARCSizeAwareModelCache()
model = cache.get_model("superpoint-lightglue")
```
### LRU Cache
```python
from imcui.ui import LRUModelCache
cache = LRUModelCache(max_size=10)
model = cache.get_model("loftr")
```
## Complete Example
```python
from imcui.api import ImageMatchingAPI
from imcui.ui import (
DEVICE,
get_matcher_zoo,
display_matches
)
import cv2
# Load images
img0 = cv2.imread("image0.jpg")
img1 = cv2.imread("image1.jpg")
# Get available matchers
matchers = get_matcher_zoo()
# Initialize API
api = ImageMatchingAPI(
conf=matchers["superpoint-lightglue"],
device=DEVICE
)
# Run matching
result = api(img0, img1)
# Visualize results
result_image = display_matches(
img0, img1,
result["keypoints0"],
result["keypoints1"],
result["matches"]
)
cv2.imwrite("matches.jpg", result_image)
```
<Note>
<strong>API Updates:</strong> All matching algorithms are maintained in the <a href="https://github.com/gmberton/vismatch">vismatch</a> repository. Check their documentation for the latest algorithms and features.
</Note>
|