Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Replace sift_roi binary by shared library and ctypes #193

Merged
merged 44 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a9a565d
[refactor] replace gdal python bindings with rasterio
carlodef Feb 22, 2019
c654396
[travis] update travis config to install rasterio instead of gdal pyt…
carlodef Feb 24, 2019
f0494ee
Merge branch 'master' into replace_osgeo_with_rasterio
carlodef Feb 25, 2019
e89b348
[refactor] replace piio with rasterio
carlodef Feb 25, 2019
d05de03
[bugfix] add missing import
carlodef Feb 25, 2019
cc1dc5b
check how does skipping existing behave on s2p_test.py
dumasl Feb 26, 2019
3c5a756
remove skip existing from s2p_test since it does have no impact at al…
dumasl Feb 26, 2019
5e8fb8c
REFAC: Start turning sift into a library
jmichel-otb Feb 26, 2019
b623940
Missing file
jmichel-otb Feb 26, 2019
b13119a
Return raw pointer instead of numpy array
jmichel-otb Feb 26, 2019
c7d8522
remove skip existing control instructions from s2p.py
dumasl Feb 26, 2019
337493a
remove end2end_cluster since step now has no meaning
dumasl Feb 26, 2019
c9abcfc
TEST: Fix bugs in sift test
jmichel-otb Feb 26, 2019
6223d56
ENH: Fix makefiles, write a separate numpy only function, and ensure …
jmichel-otb Feb 26, 2019
ae4429c
ENH: Remove the extra args option as it will not be supported anymore
jmichel-otb Feb 26, 2019
30cd412
ENH: Workaround the LD_LIBRARY_PATH issue, which is not required anymore
jmichel-otb Feb 26, 2019
472e6e8
ENH: Remove unused source file
jmichel-otb Feb 26, 2019
53763db
DOC: Add functions documentation in C part and update copyright notices
jmichel-otb Feb 26, 2019
f17622b
STY: autopep8
jmichel-otb Feb 26, 2019
fae00fc
BUG: Forgot to propagate removal of extra_params
jmichel-otb Feb 26, 2019
07635fd
steps are now always part of s2p process from top to bottom
dumasl Feb 26, 2019
57640eb
DOC/TEST: Update travis config and README.md with rasterio, filter ra…
jmichel-otb Feb 26, 2019
5d517fa
BUG: Wrong module short name
jmichel-otb Feb 26, 2019
6226f5a
force computation of global pointing corrections
dumasl Feb 26, 2019
24eb611
BUG: Fix rasterio windowing convention
jmichel-otb Feb 26, 2019
3c40826
BUG: Invert offset
dyoussef Feb 27, 2019
b1d117d
BUG: Forget clip roi to stay inside the image boundaries
dyoussef Feb 27, 2019
cfec24e
Merge pull request #195 from dumasl/feature_s2p_without_step
jmichel-otb Feb 28, 2019
9c8dcb8
Merge branch 'master' into replace_piio_with_rasterio
carlodef Mar 1, 2019
46252ab
Merge branch 'master' into replace_osgeo_with_rasterio
carlodef Mar 1, 2019
c9726d1
Merge pull request #192 from cmla/replace_piio_with_rasterio
carlodef Mar 1, 2019
b81a4ab
Merge branch 'master' into replace_osgeo_with_rasterio
carlodef Mar 1, 2019
dfa5be9
[hotfix] index error in utm_bbx use
gfacciol Mar 2, 2019
c305eee
[feature] (re)add c/egm96-15.pgm (needed by geographiclib.py)
dyoussef Mar 5, 2019
d11641c
[feature] remove irrelevant warnings and errors
dyoussef Mar 5, 2019
772ab91
Merge branch 'remove_skip_existing' of https://github.com/dumasl/s2p …
dyoussef Mar 5, 2019
da76a1c
Merge pull request #194 from dumasl/remove_skip_existing
dyoussef Mar 5, 2019
8d0a716
Merge branch 'refac_remove_sift_binary' of https://github.com/jmichel…
dyoussef Mar 5, 2019
69bca13
[refactor] factorize rasterio warnings filtering
carlodef Mar 5, 2019
d81966d
Merge pull request #191 from cmla/replace_osgeo_with_rasterio
carlodef Mar 5, 2019
0e431e3
REF: Remove unused file
jmichel-otb Mar 11, 2019
7b12beb
Merge pull request #200 from jmichel-otb/remove_viewgl
gfacciol Mar 12, 2019
a1eebe6
Merge branch 'refac_remove_sift_binary' of https://github.com/jmichel…
carlodef Mar 12, 2019
c9e8ec0
[refactor] rephrase AOI clip code and comments in sift.py
carlodef Mar 12, 2019
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew unlink gdal && (brew install gcc || brew link --overwrite gcc) && brew install geographiclib fftw; fi

install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pip install numpy utm bs4 requests; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pip install numpy rasterio utm bs4 requests; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}'); fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then wget http://www.kyngchaos.com/files/software/frameworks/GDAL_Complete-2.1.dmg; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then X=$(echo `hdiutil mount GDAL_Complete-2.1.dmg | tail -1 | awk '{$1=$2=""; print $0}'` | xargs -0 echo) && sudo installer -pkg "${X}/"GDAL\ Complete.pkg -target /; export PATH="/Library/Frameworks/GDAL.framework/Programs:$PATH"; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then pip2 install numpy utm bs4 requests; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then pip2 install numpy rasterio utm bs4 requests; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then pip2 install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}') --global-option build_ext --global-option=`gdal-config --cflags` --global-option build_ext --global-option=-L`gdal-config --prefix`/unix/lib/; fi

script:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Required dependencies (Ubuntu 16.04):

and

pip install utm bs4 lxml requests
pip install utm bs4 lxml requests rasterio

`gdal` version must be 2.1.0 or newer.

Expand Down
20 changes: 11 additions & 9 deletions c/sift/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
CXXFLAGS ?= -march=native -O3
override CXXFLAGS := $(CXXFLAGS) `gdal-config --cflags`
override CXXLIBS := $(CXXLIBS) `gdal-config --libs`
override CXXFLAGS := $(CXXFLAGS) -fPIC
override CXXLIBS := $(CXXLIBS)
override LDLIBS := $(LDLIBS) -lm

OBJ = sift_roi.o \
LibImages/LibImages.o \
OBJ = LibImages/LibImages.o \
LibSSE/LibSSE.o \
LibSift/KeyPoint.o \
LibSift/LibSift.o \
Expand All @@ -13,12 +12,15 @@ OBJ = sift_roi.o \
Utilities/Memory.o \
Utilities/Parameters.o \
Utilities/Time.o \
Utilities/Utilities.o \
Utilities/Utilities.o\
sift4ctypes.o \

all: sift_roi matching
LIB = libsift4ctypes.so

sift_roi: $(OBJ)
$(CXX) -o $@ $^ $(CXXLIBS)
all: $(LIB) matching

$(LIB): $(OBJ)
$(CXX) -fPIC -shared -o $@ $^

clean:
rm -f sift_roi matching $(OBJ)
rm -f $(LIB) matching $(OBJ)
80 changes: 80 additions & 0 deletions c/sift/sift4ctypes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (C) 2019, Julien Michel (CNES) <[email protected]>

#include <stdlib.h>

#include "Utilities/Parameters.h"
#include "LibImages/LibImages.h"
#include "LibSift/LibSift.h"

extern "C"{
/**
* This function is meant to be mapped to python using ctypes.
*
* It computes sifts points of input_buffer which is interpreted as a w x h image.
* Keypoints are returned as a linear buffer of float of size recordSize * nbRecords.
*
* This buffer is the responsibiliy of the caller and should be freed by her.
*/
float * sift(const float * input_buffer, const size_t w, const size_t h,
const float thresh_dog,
const unsigned int ss_noct,
const unsigned int ss_nspo,
unsigned int & recordSize,
unsigned int & nbRecords) {

// Derive Image from buffer
Image im(input_buffer, (const size_t) w, (const size_t) h, 1);

// prepare params object
Parameters params;
params.setDefaultValues();
params.set_thresh_dog(thresh_dog);
params.set_noct(ss_noct);
params.set_nspo(ss_nspo);

// run sift
Sift sift(params);
sift.computeKeyPoints(im);

// Compute the number of records
nbRecords = sift.m_keyPoints->size();

// Compute the record length
size_t descriptorSize = 0;
if(nbRecords > 0)
{
const KeyPoint * firstPoint = sift.m_keyPoints->front();
descriptorSize = firstPoint->getNbOri() * firstPoint->getNbHist() * firstPoint->getNbHist();
}
recordSize = descriptorSize + 4;

// Allocate output buffer
float * out = new float[recordSize*nbRecords];

// Fill output buffer with keypoints
std::list<KeyPoint*>::iterator key = sift.m_keyPoints->begin();
size_t currentPoint = 0;
for(;key != sift.m_keyPoints->end();++key,++currentPoint)
{
size_t currentIndex = recordSize*currentPoint;
out[currentIndex] = (*key)->getY();
out[currentIndex+1] = (*key)->getX();
out[currentIndex+2] = (*key)->getSigma();
out[currentIndex+3] = (*key)->getTheta();
for(unsigned int i = 0; i < descriptorSize;++i)
{
out[currentIndex+4+i] = (*key)->getPtrDescr()[i];
}
}
return out;
}
/**
* This function allows to free the float buffer from python.
*/
void delete_buffer(float * buffer)
{
if (buffer != NULL)
delete [] buffer;
}

}
120 changes: 0 additions & 120 deletions c/sift/sift_roi.cpp

This file was deleted.

12 changes: 7 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ endif
# names of source and destination directories
SRCDIR = c
BINDIR = bin
LIBDIR = lib

# default rule builds only the programs necessary for the test
default: $(BINDIR) homography sift imscript mgm mgm_multi piio tvl1 lsd
default: $(BINDIR) $(LIBDIR) homography sift imscript mgm mgm_multi piio tvl1 lsd

# the "all" rule builds four further correlators
all: default msmw3 sgbm mgm_multi
Expand All @@ -35,6 +36,8 @@ test: default
# make sure that the destination directory is built
$(BINDIR):
mkdir -p $(BINDIR)
$(LIBDIR):
mkdir -p $(LIBDIR)

#
# four standard "modules": homography, sift, mgm, and mgm_multi
Expand All @@ -46,9 +49,8 @@ homography: $(BINDIR)

sift: $(BINDIR)
$(MAKE) -j -C c/sift
cp c/sift/sift_roi $(BINDIR)
cp c/sift/matching $(BINDIR)

cp c/sift/libsift4ctypes.so $(LIBDIR)
cp c/sift/matching ${BINDIR}
mgm:
$(MAKE) -C 3rdparty/mgm
#cp 3rdparty/mgm/mgm $(BINDIR)
Expand Down Expand Up @@ -195,7 +197,7 @@ clean_homography:

clean_sift:
$(MAKE) -C c/sift clean
$(RM) $(BINDIR)/sift_roi
$(RM) $(LIBDIR)/libsift4ctypes.so
$(RM) $(BINDIR)/matching

clean_asift:
Expand Down
12 changes: 6 additions & 6 deletions s2p_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@ def unit_image_keypoints():
for i in range(test_kpts.shape[0]):
found = False
for j in range(ref_kpts.shape[0]):
dist = np.linalg.norm(test_kpts[i,0:1]-ref_kpts[j,0:1])
dist = np.linalg.norm(test_kpts[i,0:2]-ref_kpts[j,0:2])
if dist<dist_tol:
found = True
if not found:
print("KeyPoint not found: "+str((test_kpts[i,0:1])))
print("KeyPoint not found: "+str((test_kpts[i,0:2])))
nb_test_not_in_ref+=1

print(str(nb_test_not_in_ref)+" test kpts have no spatially close match in ref")

nb_ref_not_in_test = 0
for i in range(test_kpts.shape[0]):
for i in range(ref_kpts.shape[0]):
found = False
for j in range(ref_kpts.shape[0]):
dist = np.linalg.norm(test_kpts[i,0:1]-ref_kpts[j,0:1])
for j in range(test_kpts.shape[0]):
dist = np.linalg.norm(ref_kpts[i,0:2]-test_kpts[j,0:2])
if dist<dist_tol:
found = True
if not found:
print("KeyPoint not found: "+str((test_kpts[i,0:1])))
print("KeyPoint not found: "+str((test_kpts[i,0:2])))
nb_ref_not_in_test+=1

print(str(nb_ref_not_in_test)+" ref kpts have no spatially close match in test")
Expand Down
Loading