Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
hesaff
opencv
.ipynb_checkpoints
*.swp
40 changes: 35 additions & 5 deletions README → README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DESCRIPTION
# DESCRIPTION

This is an implementation of Hessian-Affine detector.

Expand All @@ -12,7 +12,37 @@ neighbourhood is normalized to a fixed size patch and SIFT
descriptor(Lowe 1999, Lowe 2004) computed.


IMPLEMENTATION
# IMPLEMENTATION

## Installing OpenCV
```
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 2154e62 # Checkout for 2.3.1 version commit point
mkdir build
cd build
# This old OpenCV may not support your recent GPU. Just disable it.
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=OFF ..
make -j8
sudo make install
```

## Build

```
cd hesaff
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
make
```

## Run

```
# Assume that libopencv_core.so.2.3 in in /usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
# Usage: hesaff image_name.ppm
hesaff oxford_001.ppm
```

Implementation depends on OpenCV (2.3.1+). Although, the code is
original, the affine iteration and normalization was derived from the
Expand All @@ -24,7 +54,7 @@ use of SIFT code, files siftdesc.cpp/siftdesc.h, in commercial
applications (see LICENSE.SIFT for details)


OUTPUT
# OUTPUT

The built binary rewrites output file: <input_image_name>.hesaff.sift

Expand All @@ -44,7 +74,7 @@ u1 v1 a1 b1 c1 d1(1) d1(2) d1(3) ... d1(N)
um vm am bm cm dm(1) dm(2) dm(3) ... dm(N)


PROPER USE
# PROPER USE

If you use this code, please refer to

Expand All @@ -53,4 +83,4 @@ Local Geometry for Large Scale Object Retrieval. In proceedings of
CVPR09. June 2009.

TBD: A reference to technical report describing the details and some
retrieval results will be placed here.
retrieval results will be placed here.
Binary file added sample/all_souls_000026.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,764 changes: 2,764 additions & 0 deletions sample/all_souls_000026.jpg.hesaff.sift

Large diffs are not rendered by default.

Binary file added sample/all_souls_000055.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,967 changes: 1,967 additions & 0 deletions sample/all_souls_000055.jpg.hesaff.sift

Large diffs are not rendered by default.

123 changes: 123 additions & 0 deletions util/Batch SIFT Extractor.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Batch SIFT Extractor\n",
"\n",
"## Requirement\n",
"\n",
"* Python3\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"print(os.getcwd())\n",
"# DATA_DIR_OXF5K = \"../../../data/oxf5k_images\" # 5062 images\n",
"# OUTPUT_DIR = \"../../../data/oxf5k_hesaff/\"\n",
"\n",
"# DATA_DIR_OXF100K = \"../data/oxford/oxc1_100k\" # The Flickr 100k dataset consists of 100071 images collected from Flickr by searching for popular Flickr tags. \n",
"# 5602 + 100071 = 105,673\n",
"\n",
"DATA_DIR_PAR6K = \"../../../data/paris6k_images\" # 6392 images\n",
"OUTPUT_DIR = \"../../../data/paris6k_hesaff/\"\n",
"\n",
"if not os.path.exists(OUTPUT_DIR):\n",
" os.mkdir(OUTPUT_DIR)\n",
"\n",
"def get_images(data_dir):\n",
" image_paths = []\n",
" for parent_dir, _, files in os.walk(data_dir):\n",
" # print(parent_dir)\n",
" for f in files:\n",
" # print(f)\n",
" if f[-4:] == \".jpg\":\n",
" image_paths.append(os.path.abspath(os.path.join(parent_dir, f)))\n",
" else:\n",
" print(\"skip:\", f)\n",
" # filenames = os.listdir(data_dir) \n",
" # image_paths = list(map(lambda x: os.path.join(data_dir, x), filenames))\n",
" return image_paths\n",
"\n",
"image_list = get_images(DATA_DIR_PAR6K)\n",
"# image_list = get_images(DATA_DIR_OXF5K)\n",
"# image_list = get_images(DATA_DIR_OXF5K) + get_images(DATA_DIR_OXF100K)\n",
"image_list.sort()\n",
"\n",
"for i in image_list[:5]:\n",
" print(i)\n",
"print(len(image_list))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import subprocess\n",
"from subprocess import CalledProcessError\n",
"import numpy as np\n",
"import shutil\n",
"# from tqdm import tqdm_notebook as tqdm\n",
"from tqdm import tqdm\n",
"\n",
"from multiprocessing import Pool\n",
"\n",
"def extract_sift(image_path):\n",
" try:\n",
" output = subprocess.check_output([\"../hesaff\", \"{}\".format(image_path)])\n",
" # print('stdout of hesaff:', output)\n",
" except CalledProcessError as e: \n",
" print(e)\n",
" print(\"output: {}\".format(e.output.decode('utf-8'))) \n",
" \n",
"\n",
"\n",
"def parallel_task(image_path):\n",
" extract_sift(image_path)\n",
" sift_file_path = image_path + \".hesaff.sift\"\n",
" sift_file_name = os.path.basename(sift_file_path)\n",
" shutil.move(sift_file_path, os.path.join(OUTPUT_DIR, sift_file_name))\n",
"\n",
"if __name__ == '__main__':\n",
" pool = Pool(processes=40)\n",
" for result in tqdm(pool.imap_unordered(parallel_task, image_list), total=len(image_list)):\n",
" pass\n",
" # features.append(result)\n",
" \n",
"# Timing history: 100k images took about 1h 20m for feature extraction. \n",
"\n",
"# hesaff speed: 31 images / sec, 32 ms / image"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading