Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PointCloud
Flann
提交
a87a1f15
F
Flann
项目概览
PointCloud
/
Flann
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Flann
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a87a1f15
编写于
10月 28, 2009
作者:
M
Marius Muja
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Misc
上级
acaa0d95
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
81 addition
and
35 deletion
+81
-35
doc/manual.tex
doc/manual.tex
+3
-3
src/cpp/CMakeLists.txt
src/cpp/CMakeLists.txt
+1
-1
src/cpp/algorithms/kdtree_index.h
src/cpp/algorithms/kdtree_index.h
+3
-1
src/cpp/constants.h
src/cpp/constants.h
+1
-0
src/cpp/flann.cpp
src/cpp/flann.cpp
+21
-12
src/cpp/flann.h
src/cpp/flann.h
+6
-6
src/cpp/flann.hpp
src/cpp/flann.hpp
+26
-2
src/cpp/nn/index_testing.cpp
src/cpp/nn/index_testing.cpp
+1
-0
src/cpp/tests/CMakeLists.txt
src/cpp/tests/CMakeLists.txt
+4
-1
src/cpp/util/saving.cpp
src/cpp/util/saving.cpp
+1
-0
src/python/pyflann/bindings/flann_ctypes.py
src/python/pyflann/bindings/flann_ctypes.py
+4
-4
src/python/pyflann/command/run_test.py
src/python/pyflann/command/run_test.py
+9
-3
src/python/pyflann/io/npy_dataset.py
src/python/pyflann/io/npy_dataset.py
+1
-2
未找到文件。
doc/manual.tex
浏览文件 @
a87a1f15
...
...
@@ -279,12 +279,12 @@ must contain the following fields:
percentage of the approximate nearest-neighbor searches that return the
exact nearest-neighbor. Using a higher value for this parameter gives
more
accurate results, but the search
ing
takes longer. The optimum value
accurate results, but the search takes longer. The optimum value
usually
depends on the application.
\item
[\texttt{build\_weight}]
- specifies the importance of the
index build time r
e
ported to the nearest-neighbor search time. In some
index build time r
a
ported to the nearest-neighbor search time. In some
applications it's acceptable for the index build step to take a long time
if the subsequent searches in the index can be performed very fast. In
other applications it's required that the index be build as fast as
...
...
@@ -342,7 +342,7 @@ convergence. This parameter is required only when the algorithm used is
centers when performing a kmeans clustering step. The possible values are
'random' (picks the initial cluster centers randomly), 'gonzales' (picks the
initial centers using the Gonzales algorithm) and 'kmeanspp' (picks the initial
centers using thealgorithm suggested in
\cite
{
arthur
_
kmeanspp
_
2007
}
). If this
centers using the
algorithm suggested in
\cite
{
arthur
_
kmeanspp
_
2007
}
). If this
parameters is omitted, the default value is 'random'.
\item
[\texttt{cb\_index}]
- this parameter (cluster boundary index) influences the
...
...
src/cpp/CMakeLists.txt
浏览文件 @
a87a1f15
...
...
@@ -87,7 +87,7 @@ INSTALL (
# )
INSTALL
(
FILES flann.h
constants
.h
FILES flann.h
flann.hpp constants.h util/matrix.h util/common.h util/random
.h
DESTINATION include
)
...
...
src/cpp/algorithms/kdtree_index.h
浏览文件 @
a87a1f15
...
...
@@ -34,6 +34,7 @@
#include <algorithm>
#include <map>
#include <cassert>
#include <cstring>
#include "heap.h"
#include "common.h"
...
...
@@ -175,8 +176,8 @@ public:
{
size_
=
dataset
.
rows
;
veclen_
=
dataset
.
cols
;
numTrees
=
params
.
trees
;
trees
=
new
Tree
[
numTrees
];
// get the parameters
...
...
@@ -306,6 +307,7 @@ public:
*/
void
findNeighbors
(
ResultSet
&
result
,
const
float
*
vec
,
const
SearchParams
&
searchParams
)
{
int
maxChecks
=
searchParams
.
checks
;
if
(
maxChecks
<
0
)
{
...
...
src/cpp/constants.h
浏览文件 @
a87a1f15
...
...
@@ -40,6 +40,7 @@ enum flann_algorithm_t {
KDTREE
=
1
,
KMEANS
=
2
,
COMPOSITE
=
3
,
KDTREE_MT
=
4
,
SAVED
=
254
,
AUTOTUNED
=
255
,
};
...
...
src/cpp/flann.cpp
浏览文件 @
a87a1f15
...
...
@@ -39,16 +39,15 @@
#include "object_factory.h"
// index types
#include "kdtree_index.h"
#include "kdtree_mt_index.h"
#include "kmeans_index.h"
#include "composite_index.h"
#include "linear_index.h"
#include "autotuned_index.h"
#include <typeinfo>
using
namespace
std
;
#include "flann.h"
#ifdef WIN32
...
...
@@ -83,6 +82,11 @@ NNIndex* KDTreeIndexParams::createIndex(const Matrix<float>& dataset) const
return
new
KDTreeIndex
(
dataset
,
*
this
);
}
NNIndex
*
KDTreeMTIndexParams
::
createIndex
(
const
Matrix
<
float
>&
dataset
)
const
{
return
new
KDTreeMTIndex
(
dataset
,
*
this
);
}
NNIndex
*
KMeansIndexParams
::
createIndex
(
const
Matrix
<
float
>&
dataset
)
const
{
return
new
KMeansIndex
(
dataset
,
*
this
);
...
...
@@ -127,6 +131,7 @@ public:
{
ParamsFactory
::
instance
().
register_
<
LinearIndexParams
>
(
LINEAR
);
ParamsFactory
::
instance
().
register_
<
KDTreeIndexParams
>
(
KDTREE
);
ParamsFactory
::
instance
().
register_
<
KDTreeMTIndexParams
>
(
KDTREE_MT
);
ParamsFactory
::
instance
().
register_
<
KMeansIndexParams
>
(
KMEANS
);
ParamsFactory
::
instance
().
register_
<
CompositeIndexParams
>
(
COMPOSITE
);
ParamsFactory
::
instance
().
register_
<
AutotunedIndexParams
>
(
AUTOTUNED
);
...
...
@@ -226,7 +231,7 @@ int hierarchicalClustering(const Matrix<float>& features, Matrix<float>& centers
using
namespace
flann
;
typedef
NNIndex
*
NN
IndexPtr
;
typedef
Index
*
IndexPtr
;
typedef
Matrix
<
float
>*
MatrixPtr
;
...
...
@@ -259,6 +264,7 @@ EXPORTED void flann_set_distance_type(flann_distance_t distance_type, int order)
EXPORTED
flann_index_t
flann_build_index
(
float
*
dataset
,
int
rows
,
int
cols
,
float
*
speedup
,
FLANNParameters
*
flann_params
)
{
try
{
init_flann_parameters
(
flann_params
);
if
(
flann_params
==
NULL
)
{
throw
FLANNException
(
"The flann_params argument must be non-null"
);
...
...
@@ -295,7 +301,7 @@ EXPORTED int flann_save_index(flann_index_t index_ptr, char* filename)
}
EXPORTED
FLANN_INDEX
flann_load_index
(
char
*
filename
,
float
*
dataset
,
int
rows
,
int
cols
)
EXPORTED
flann_index_t
flann_load_index
(
char
*
filename
,
float
*
dataset
,
int
rows
,
int
cols
)
{
try
{
Index
*
index
=
new
Index
(
Matrix
<
float
>
(
rows
,
cols
,
dataset
),
SavedIndexParams
(
filename
));
...
...
@@ -357,7 +363,7 @@ EXPORTED int flann_find_nearest_neighbors_index(flann_index_t index_ptr, float*
}
EXPORTED
int
flann_radius_search
(
FLANN_INDEX
index_ptr
,
EXPORTED
int
flann_radius_search
(
flann_index_t
index_ptr
,
float
*
query
,
int
*
indices
,
float
*
dists
,
...
...
@@ -390,7 +396,7 @@ EXPORTED int flann_radius_search(FLANN_INDEX index_ptr,
}
EXPORTED
int
flann_free_index
(
FLANN_INDEX
index_ptr
,
FLANNParameters
*
flann_params
)
EXPORTED
int
flann_free_index
(
flann_index_t
index_ptr
,
FLANNParameters
*
flann_params
)
{
try
{
init_flann_parameters
(
flann_params
);
...
...
@@ -437,7 +443,7 @@ EXPORTED void compute_ground_truth_float(float* dataset, int dshape[], float* te
}
EXPORTED
float
test_with_precision
(
FLANN_INDEX
index_ptr
,
float
*
dataset
,
int
dshape
[],
float
*
testset
,
int
tshape
[],
int
*
matches
,
int
mshape
[],
EXPORTED
float
test_with_precision
(
flann_index_t
index_ptr
,
float
*
dataset
,
int
dshape
[],
float
*
testset
,
int
tshape
[],
int
*
matches
,
int
mshape
[],
int
nn
,
float
precision
,
int
*
checks
,
int
skip
=
0
)
{
assert
(
dshape
[
1
]
==
tshape
[
1
]);
...
...
@@ -447,8 +453,10 @@ EXPORTED float test_with_precision(FLANN_INDEX index_ptr, float* dataset, int ds
if
(
index_ptr
==
NULL
)
{
throw
FLANNException
(
"Invalid index"
);
}
NNIndexPtr
index
=
(
NNIndexPtr
)
index_ptr
;
return
test_index_precision
(
*
index
,
Matrix
<
float
>
(
dshape
[
0
],
dshape
[
1
],
dataset
),
Matrix
<
float
>
(
tshape
[
0
],
tshape
[
1
],
testset
),
IndexPtr
index
=
(
IndexPtr
)
index_ptr
;
NNIndex
*
nn_index
=
index
->
index
();
return
test_index_precision
(
*
nn_index
,
Matrix
<
float
>
(
dshape
[
0
],
dshape
[
1
],
dataset
),
Matrix
<
float
>
(
tshape
[
0
],
tshape
[
1
],
testset
),
Matrix
<
int
>
(
mshape
[
0
],
mshape
[
1
],
matches
),
precision
,
*
checks
,
nn
,
skip
);
}
catch
(
runtime_error
&
e
)
{
logger
.
error
(
"Caught exception: %s
\n
"
,
e
.
what
());
...
...
@@ -456,7 +464,7 @@ EXPORTED float test_with_precision(FLANN_INDEX index_ptr, float* dataset, int ds
}
}
EXPORTED
float
test_with_checks
(
FLANN_INDEX
index_ptr
,
float
*
dataset
,
int
dshape
[],
float
*
testset
,
int
tshape
[],
int
*
matches
,
int
mshape
[],
EXPORTED
float
test_with_checks
(
flann_index_t
index_ptr
,
float
*
dataset
,
int
dshape
[],
float
*
testset
,
int
tshape
[],
int
*
matches
,
int
mshape
[],
int
nn
,
int
checks
,
float
*
precision
,
int
skip
=
0
)
{
assert
(
dshape
[
1
]
==
tshape
[
1
]);
...
...
@@ -466,8 +474,9 @@ EXPORTED float test_with_checks(FLANN_INDEX index_ptr, float* dataset, int dshap
if
(
index_ptr
==
NULL
)
{
throw
FLANNException
(
"Invalid index"
);
}
NNIndexPtr
index
=
(
NNIndexPtr
)
index_ptr
;
return
test_index_checks
(
*
index
,
Matrix
<
float
>
(
dshape
[
0
],
dshape
[
1
],
dataset
),
Matrix
<
float
>
(
tshape
[
0
],
tshape
[
1
],
testset
),
IndexPtr
index
=
(
IndexPtr
)
index_ptr
;
NNIndex
*
nn_index
=
index
->
index
();
return
test_index_checks
(
*
nn_index
,
Matrix
<
float
>
(
dshape
[
0
],
dshape
[
1
],
dataset
),
Matrix
<
float
>
(
tshape
[
0
],
tshape
[
1
],
testset
),
Matrix
<
int
>
(
mshape
[
0
],
mshape
[
1
],
matches
),
checks
,
*
precision
,
nn
,
skip
);
}
catch
(
runtime_error
&
e
)
{
logger
.
error
(
"Caught exception: %s
\n
"
,
e
.
what
());
...
...
src/cpp/flann.h
浏览文件 @
a87a1f15
...
...
@@ -111,7 +111,7 @@ Params:
Returns: the newly created index or a number <0 for error
*/
LIBSPEC
FLANN_INDEX
flann_build_index
(
float
*
dataset
,
LIBSPEC
flann_index_t
flann_build_index
(
float
*
dataset
,
int
rows
,
int
cols
,
float
*
speedup
,
...
...
@@ -128,7 +128,7 @@ LIBSPEC FLANN_INDEX flann_build_index(float* dataset,
* @param filename The filename the index should be saved to
* @return Returns 0 on success, negative value on error.
*/
LIBSPEC
int
flann_save_index
(
FLANN_INDEX
index_id
,
LIBSPEC
int
flann_save_index
(
flann_index_t
index_id
,
char
*
filename
);
...
...
@@ -141,7 +141,7 @@ LIBSPEC int flann_save_index(FLANN_INDEX index_id,
* @param cols Dataset columns
* @return
*/
LIBSPEC
FLANN_INDEX
flann_load_index
(
char
*
filename
,
LIBSPEC
flann_index_t
flann_load_index
(
char
*
filename
,
float
*
dataset
,
int
rows
,
int
cols
);
...
...
@@ -192,7 +192,7 @@ Params:
Returns: zero or a number <0 for error
*/
LIBSPEC
int
flann_find_nearest_neighbors_index
(
FLANN_INDEX
index_id
,
LIBSPEC
int
flann_find_nearest_neighbors_index
(
flann_index_t
index_id
,
float
*
testset
,
int
trows
,
int
*
indices
,
...
...
@@ -217,7 +217,7 @@ LIBSPEC int flann_find_nearest_neighbors_index(FLANN_INDEX index_id,
* a higher search speedup at the cost of potentially not returning all the
* neighbours in the specified radius.
*/
LIBSPEC
int
flann_radius_search
(
FLANN_INDEX
index_ptr
,
/* the index */
LIBSPEC
int
flann_radius_search
(
flann_index_t
index_ptr
,
/* the index */
float
*
query
,
/* query point */
int
*
indices
,
/* array for storing the indices found (will be modified) */
float
*
dists
,
/* similar, but for storing distances */
...
...
@@ -236,7 +236,7 @@ Params:
Returns: zero or a number <0 for error
*/
LIBSPEC
int
flann_free_index
(
FLANN_INDEX
index_id
,
LIBSPEC
int
flann_free_index
(
flann_index_t
index_id
,
struct
FLANNParameters
*
flann_params
);
/**
...
...
src/cpp/flann.hpp
浏览文件 @
a87a1f15
...
...
@@ -59,8 +59,8 @@ public:
static
IndexParams
*
createFromParameters
(
const
FLANNParameters
&
p
);
void
fromParameters
(
const
FLANNParameters
&
p
)
{};
void
toParameters
(
FLANNParameters
&
p
)
{
};
v
irtual
v
oid
fromParameters
(
const
FLANNParameters
&
p
)
{};
v
irtual
v
oid
toParameters
(
FLANNParameters
&
p
)
{
};
};
struct
LinearIndexParams
:
public
IndexParams
{
...
...
@@ -91,6 +91,28 @@ struct KDTreeIndexParams : public IndexParams {
};
struct
KDTreeMTIndexParams
:
public
IndexParams
{
KDTreeMTIndexParams
(
int
trees_
=
4
)
:
trees
(
trees_
)
{};
int
trees
;
// number of randomized trees to use (for kdtree)
NNIndex
*
createIndex
(
const
Matrix
<
float
>&
dataset
)
const
;
void
fromParameters
(
const
FLANNParameters
&
p
)
{
trees
=
p
.
trees
;
}
void
toParameters
(
FLANNParameters
&
p
)
{
p
.
algorithm
=
KDTREE_MT
;
p
.
trees
=
trees
;
};
};
struct
KMeansIndexParams
:
public
IndexParams
{
KMeansIndexParams
(
int
branching_
=
32
,
int
iterations_
=
11
,
flann_centers_init_t
centers_init_
=
CENTERS_RANDOM
,
float
cb_index_
=
0.2
)
:
...
...
@@ -236,6 +258,8 @@ public:
int
veclen
()
const
;
int
size
()
const
;
NNIndex
*
index
()
{
return
nnIndex
;
}
};
...
...
src/cpp/nn/index_testing.cpp
浏览文件 @
a87a1f15
...
...
@@ -37,6 +37,7 @@
#include <algorithm>
#include <math.h>
#include <cstring>
namespace
flann
...
...
src/cpp/tests/CMakeLists.txt
浏览文件 @
a87a1f15
...
...
@@ -10,7 +10,10 @@
ADD_EXECUTABLE
(
flann_test flann_test.cc
)
TARGET_LINK_LIBRARIES
(
flann_test flann
)
INSTALL
(
TARGETS flann_test
TARGETS
flann_test
RUNTIME DESTINATION bin
)
src/cpp/util/saving.cpp
浏览文件 @
a87a1f15
...
...
@@ -32,6 +32,7 @@
#include "saving.h"
#include "nn_index.h"
#include <cstdio>
#include <cstring>
namespace
flann
{
...
...
src/python/pyflann/bindings/flann_ctypes.py
浏览文件 @
a87a1f15
...
...
@@ -115,7 +115,7 @@ class FLANNParameters(CustomStructure):
'random_seed'
:
-
1
}
_translation_
=
{
"algorithm"
:
{
"linear"
:
0
,
"kdtree"
:
1
,
"kmeans"
:
2
,
"composite"
:
3
,
"autotuned"
:
255
,
"default"
:
1
},
"algorithm"
:
{
"linear"
:
0
,
"kdtree"
:
1
,
"kmeans"
:
2
,
"composite"
:
3
,
"
kdtree_mt"
:
1
,
"
autotuned"
:
255
,
"default"
:
1
},
"centers_init"
:
{
"random"
:
0
,
"gonzales"
:
1
,
"kmeanspp"
:
2
,
"default"
:
0
},
"log_level"
:
{
"none"
:
0
,
"fatal"
:
1
,
"error"
:
2
,
"warning"
:
3
,
"info"
:
4
,
"default"
:
2
}
}
...
...
@@ -233,7 +233,7 @@ flann.compute_ground_truth_float.argtypes = [
flann
.
test_with_precision
.
restype
=
c_float
flann
.
test_with_precision
.
argtypes
=
[
c_void_p
,
FLANN_INDEX
,
ndpointer
(
float32
,
ndim
=
2
,
flags
=
'aligned, c_contiguous'
),
# dataset
c_int
*
2
,
# dshape
ndpointer
(
float32
,
ndim
=
2
,
flags
=
'aligned, c_contiguous'
),
# testset
...
...
@@ -249,7 +249,7 @@ flann.test_with_precision.argtypes = [
flann
.
test_with_checks
.
restype
=
c_float
flann
.
test_with_checks
.
argtypes
=
[
c_void_p
,
FLANN_INDEX
,
ndpointer
(
float32
,
ndim
=
2
,
flags
=
'aligned, c_contiguous'
),
# dataset
c_int
*
2
,
# dshape
ndpointer
(
float32
,
ndim
=
2
,
flags
=
'aligned, c_contiguous'
),
# testset
...
...
@@ -391,7 +391,7 @@ class FLANN:
dists
=
empty
(
(
nqpts
,
num_neighbors
),
dtype
=
float32
)
self
.
__flann_parameters
.
update
(
kwargs
)
flann
.
flann_find_nearest_neighbors
(
pts
,
npts
,
dim
,
qpts
,
nqpts
,
result
,
dists
,
num_neighbors
,
pointer
(
self
.
__flann_parameters
))
...
...
src/python/pyflann/command/run_test.py
浏览文件 @
a87a1f15
...
...
@@ -79,17 +79,23 @@ class RunTestCommand(BaseCommand):
print
'Reading input dataset from'
,
self
.
options
.
input_file
dataset
=
read
(
self
.
options
.
input_file
)
import
time
print
'Creating index'
start_time
=
time
.
clock
()
flann
=
FLANN
(
log_level
=
self
.
options
.
log_level
)
flann
.
build_index
(
dataset
,
algorithm
=
self
.
options
.
algorithm
,
trees
=
self
.
options
.
trees
,
branching
=
self
.
options
.
branching
,
iterations
=
self
.
options
.
max_iterations
,
centers_init
=
self
.
options
.
centers_init
)
iterations
=
self
.
options
.
max_iterations
,
centers_init
=
self
.
options
.
centers_init
)
print
'Index creation took'
,
time
.
clock
()
-
start_time
print
'Reading test dataset from'
,
self
.
options
.
test_file
testset
=
read
(
self
.
options
.
test_file
)
print
'Reading ground truth from matches from'
,
self
.
options
.
test
_file
print
'Reading ground truth from matches from'
,
self
.
options
.
match
_file
matches
=
read
(
self
.
options
.
match_file
,
dtype
=
int
)
if
len
(
matches
.
shape
)
==
1
:
matches
.
shape
=
(
matches
.
shape
[
0
],
1
)
if
self
.
options
.
precision
>
0
:
checks
,
time
=
test_with_precision
(
flann
,
dataset
,
testset
,
matches
,
self
.
options
.
precision
,
self
.
options
.
nn
)
else
:
...
...
src/python/pyflann/io/npy_dataset.py
浏览文件 @
a87a1f15
...
...
@@ -46,7 +46,6 @@ def read(filename, dtype = numpy.float32):
tmp
=
numpy
.
save
except
:
raise
FLANNException
(
"Format not supported. You need at least numpy version 1.1"
)
data
=
numpy
.
load
(
filename
)
data
=
numpy
.
load
(
filename
)
return
data
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录