Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kmkolasinski/fast-bfmatcher
https://github.com/kmkolasinski/fast-bfmatcher
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kmkolasinski/fast-bfmatcher
- Owner: kmkolasinski
- License: mit
- Created: 2021-12-20T06:54:31.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-12T02:23:38.000Z (over 2 years ago)
- Last Synced: 2024-09-30T05:28:51.448Z (about 1 month ago)
- Language: Jupyter Notebook
- Size: 966 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fast-bfmatcher
Faster implementation of the OpenCV BFMatcher(cv2.NORM_L2) matcher for image keypoint
matching## Usage
* CC stands for Cross-Check
* RT stands for ratio test i.e. Lowe's ratio test proposed in the original SIFT paper```python
import os
import cv2# set number of threads for BLIS, must be set
# before import, cannot be change later
os.environ["BLIS_NUM_THREADS"] = "4"# running benchmarks
from fast_bfmatcher import FastL2RTBFMatcher, FastL2CCBFMatcher, FastL2RTCCBFMatchersift = cv2.SIFT_create()
_, des1 = sift.detectAndCompute(image1, None)
_, des2 = sift.detectAndCompute(image2, None)fast_matcher_rt = FastL2RTBFMatcher(ratio=0.7)
fast_matcher_cc = FastL2CCBFMatcher() # cross check matcher
fast_matcher_rt_cc = FastL2RTCCBFMatcher(ratio=0.7) # cross check and ratio testfs_match = fast_matcher_rt.match(des1, des2)
cv_match = fast_matcher_cc.match(des1, des2)# match contains indices and distances
fs_match.indices, fs_match.distances```
# Installation
```bash
# (recommended) to build BLIS on the host machine
pip install git+https://github.com/kmkolasinski/fast-bfmatcher
# to install pip prebuild package
pip install fast-bfmatcher
```# Information
* Speed up is achieved thanks to fast [blis](https://github.com/flame/blis) library
* Optimized with SIMD instructions custom C implementations# Quick command to check speedup
```python
import os
import cv2# fix number of threads for BLIS, must be set
# before using this library, cannot be change
# later
os.environ["BLIS_NUM_THREADS"] = "4"# fix number of threads for numpy
os.environ["OMP_NUM_THREADS"] = "4"# fix number of threads for OpenCV
cv2.setNumThreads(4)import pandas as pd
from fast_bfmatcher.benchmark import benchmark_cc_rt_size_scan
from fast_bfmatcher.benchmark import benchmark_cc_matchersbenchmark_cc_matchers()
# to generate the plot above run this benchmark
metrics = benchmark_cc_rt_size_scan()
df = pd.DataFrame(metrics)
ax = df.set_index("size").plot(lw=2, colormap='jet', marker='.', markersize=10, figsize=(10, 5), fontsize=20)
ax.set_xlabel("Dim")
ax.set_ylabel("Time [ms]")```
# Building library locally
```bash
python setup.py build_ext --inplace
```# Testing
```bash
export BLIS_NUM_THREADS=8;
export OMP_NUM_THREADS=8
pytest -s
```