Skip to content

Commit

Permalink
added support for both windows and unix
Browse files Browse the repository at this point in the history
  • Loading branch information
tejus-gupta committed Jan 1, 2018
1 parent e3e08c8 commit 2c4ae93
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ Images 0.6
Distributions 0.12
FixedPointNumbers 0.3
Compat 0.17
FLANN
NearestNeighbors
Distances
2 changes: 2 additions & 0 deletions src/ImageFeatures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module ImageFeatures
# package code goes here
using Images, ColorTypes, FixedPointNumbers, Distributions
using Compat
using FLANN, Distances
using NearestNeighbors

include("core.jl")
include("const.jl")
Expand Down
38 changes: 32 additions & 6 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,39 @@ function match_keypoints(keypoints_1::Keypoints, keypoints_2::Keypoints, desc_1,
l_key = keypoints_1
order = true
end
hamming_distances = [hamming_distance(s, l) for s in smaller, l in larger]

matches = Keypoints[]
for i in 1:length(smaller)
if any(hamming_distances[i, :] .< threshold)
id_min = indmin(hamming_distances[i, :])
push!(matches, order ? [l_key[id_min], s_key[i]] : [s_key[i], l_key[id_min]])
hamming_distances[:, id_min] = 1.0

ndims=length(larger[1])
n_large=length(larger)
n_small=length(smaller)

data=Matrix{Float64}(ndims, n_large);
for i in 1:ndims
for j in 1:n_large
data[i,j]=larger[j][i]?1:0
end
end

if is_windows() && Sys.WORD_SIZE==32
tree = KDTree(data, Cityblock())

for i in 1:n_small
idx, dist = NearestNeighbors.knn(tree, smaller[i], 1)
if dist[1]/ndims < threshold
id_min = idx[1]
push!(matches, order ? [l_key[id_min], s_key[i]] : [s_key[i], l_key[id_min]])
end
end
else
tree = flann(data, FLANNParameters(), Cityblock())

for i in 1:n_small
idx, dist = FLANN.knn(tree, Vector{Float64}(smaller[i]), 1)
if dist[1]/ndims < threshold
id_min = idx[1]
push!(matches, order ? [l_key[id_min], s_key[i]] : [s_key[i], l_key[id_min]])
end
end
end
matches
Expand Down

0 comments on commit 2c4ae93

Please sign in to comment.