BALF is able to detect well localized and repeatable keypoints from both sharp and blurred images.
Install this repo using pip:
git clone https://github.com/ericzzj1989/BALF.git && cd BALF
python -m pip install -e .
Below we show how BALF, in combination with HardNet, can be used for feature extraction and matching on an image pair. You can also refer to the demo for more details.
from balf.utils import test_utils
from balf.configs import config
from balf.model import get_model
from demo import demo_match
from third_party.hardnet.hardnet_pytorch import HardNet
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
args, cfg = config.parse_test_config()
detector = get_model.load_model(cfg['model'])
_,_ = get_model.load_test_pretrained_model(model=detector, filename=args.ckpt_file)
detector = detector.eval().to(device)
descriptor = HardNet()
checkpoint_descriptor = torch.load(args.ckpt_descriptor_file, weights_only=True)
descriptor.load_state_dict(checkpoint_descriptor['state_dict'])
descriptor = descriptor.eval().to(device)
im_rgb1, im_gray1 = demo_match.load_im('media/im1.jpg')
im_rgb2, im_gray2 = demo_match.load_im('media/im2.jpg')
matches1, matches2 = demo_match.extract_matches(
args,
im_rgb1, im_gray1, im_rgb2, im_gray2,
detector, descriptor, device)
Image.fromarray(demo_match.draw_matches(im_rgb1, matches1, im_rgb2, matches2)).save("demo/matches.png")
To train BALF, refer to train.py
in balf.
Pretrained models are available here.
The author thanks Peidong Liu and Ben M. Chen for supporting.
If you find this code or paper useful, please cite:
@InProceedings{Zhao_2024_WACV,
author = {Zhao, Zhenjun},
title = {BALF: Simple and Efficient Blur Aware Local Feature Detector},
booktitle = {Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV)},
month = {January},
year = {2024},
pages = {3362-3372}
}
Contact Zhenjun Zhao for questions, comments and reporting bugs.