博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
flann
阅读量:4041 次
发布时间:2019-05-24

本文共 5559 字,大约阅读时间需要 18 分钟。

install flann and lz4 from github , uninstall the default ones.

sudo apt-get remove liblz4-dev

sudo apt-get remove libflann-dev

CMakeList.txt

cmake_minimum_required(VERSION 2.8)project(testFlann)file(GLOB srcs *.cpp *.hpp *.cc *.h)find_package(Flann REQUIRED)#find_package(HDF5 REQUIRED)include_directories(${FLANN_INCLUDE_DIRS})#include_directories(${HDF5_INCLUDE_DIRS})link_directories(${HDF5_LIBRARY_DIRS})add_executable(${PROJECT_NAME} ${srcs})target_link_libraries(${PROJECT_NAME} ${FLANN_LIBRARIES} lz4 )# ${HDF5_LIBRARIES}

main.cpp

//============================================================================// Name        : flann-knn-example.cpp// Author      : Shohei Yokoyama// Copyright   : Shizuoka University, Japan// Description : 1st step of your FLANN application.// Dependency  : FLANN http://people.cs.ubc.ca/~mariusm/index.php/FLANN/FLANN//             : Boost http://www.boost.org///             : (If win) MinGW & MSYS http://www.mingw.org/// License     : NYSL see http://www.kmonos.net/nysl/index.en.html//============================================================================#include 
#include
#include
#include
using namespace std;using namespace boost;int main(int argc, char** argv) { const int numResult = 2; const int numInput = 100; const int numQuery = 2; const int dimension = 2; const int maxValue = 255; const int minValue = 0; mt19937 gen(static_cast
(time(0))); uniform_smallint<> dst(minValue,maxValue); variate_generator
> rand(gen, dst); //Calculate the width of values ostringstream ss; ss << (numInput - 1); string s = ss.str(); int lnWidth = s.length(); // for line number ostringstream sss; sss << maxValue; s = sss.str(); int valWidth = s.length(); // for each values ostringstream ssss; ssss << numQuery; s = ssss.str(); int qWidth = s.length(); // for query number cout << "Target Data:" << endl; int targetData[(numInput * dimension)]; for (int i = 0; i < numInput; ++i) { cout.width(qWidth); cout.fill(' '); cout << ' '; cout << "#"; cout.width(lnWidth); cout.fill('0'); cout << i << "\t"; for (int j = 0; j < dimension; ++j) { targetData[i * dimension + j] = rand(); cout.width(valWidth); cout.fill(' '); cout << targetData[i * dimension + j] << "\t"; } cout << endl; } flann::Matrix
dataset(targetData, numInput, dimension); int queryData[dimension]; cout << endl << "Query:" << endl; for (int i = 0; i < numQuery; i++) { cout << "Q"; cout.width(qWidth); cout.fill('0'); cout << i; cout.width(lnWidth + 1); cout.fill(' '); cout << " " << "\t"; for (int j = 0; j < dimension; j++) { queryData[(i * dimension) + j] = rand(); cout.width(valWidth); cout.fill(' '); cout << queryData[(i * dimension) + j] << "\t"; } cout << endl; } flann::Matrix
query(queryData, numQuery, dimension); flann::Matrix
indices(new int[query.rows * numResult], query.rows, numResult); flann::Matrix
dists(new float[query.rows * numResult], query.rows, numResult); // construct an randomized kd-tree index using 4 kd-trees flann::Index
> index(dataset, flann::KDTreeIndexParams(8)); index.buildIndex(); // do a knn search, using 128 checks index.knnSearch(query, indices, dists, numResult, flann::SearchParams(128)); cout << endl; for (int q = 0; q < numQuery; q++) { for (int r = 0; r < numResult; r++) { cout << "Q"; cout.width(qWidth); cout.fill('0'); cout << q; cout << "#"; cout.width(lnWidth); cout.fill('0'); cout << indices[q][r] << "\t"; for (int j = 0; j < dimension; ++j) { cout.width(valWidth); cout.fill(' '); cout << dataset[indices[q][r]][j] << "\t"; } cout << "dist:" << dists[q][r] << endl; } } //delete[] dataset.ptr();// /delete[] query.ptr(); delete[] indices.ptr(); delete[] dists.ptr();// delete[] query.ptr();// delete[] dataset.ptr(); return 0;}
Target Data: #00    242  16  #01    210 243  #02    211 208  #03     65 180  #04    117 239  #05     52  70  #06    206 215  #07    176  45  #08     44 198  #09    170  11  #10    128 215  #11    205  59  #12     38 101  #13      6  80  #14    154 211  #15    111 225  #16    120  76  #17    244 130  #18    241 109  #19     41 182  #20      8 149  #21    207  34  #22     25 110  #23    142 102  #24     10 119  #25      0   5  #26    116  65  #27    239 134  #28     43 234  #29    225 103  #30     33 121  #31    130 130  #32    204 130  #33     53 132  #34    125 128  #35    231  35  #36     96 111  #37    199  56  #38    161 190  #39      5 224  #40    174 145  #41      6  29  #42     33 146  #43     65  41  #44    188 224  #45    207 139  #46    227  74  #47     20 245  #48     21 155  #49     36  68  #50    130 173  #51     74  93  #52    186 168  #53    102 129  #54     52 250  #55     21  49  #56     83 102  #57    255 186  #58    241 208  #59     78  29  #60     98 140  #61    185 173  #62    133   6  #63    183 195  #64     67  55  #65     27  19  #66    140  48  #67    250  88  #68    147 173  #69     62  26  #70     28 234  #71    136 107  #72    141 162  #73    203 226  #74    249 185  #75    165 162  #76     43 240  #77     54 173  #78     97  35  #79    225  39  #80    150  44  #81    134   1  #82     31 154  #83    132  40  #84     96 200  #85    234  38  #86     59 135  #87      0 141  #88    138 192  #89     34 177  #90    105  27  #91    127  81  #92     67 166  #93    162 131  #94    101 209  #95     23 171  #96    245 120  #97    226 201  #98    251 187  #99     22 225 Query:Q0      123 208 Q1       22  15 Q0#10   128 215 dist:74Q0#15   111 225 dist:433Q1#65    27  19 dist:41Q1#41     6  29 dist:452

转载地址:http://exxdi.baihongyu.com/

你可能感兴趣的文章
Returning a value from a function
查看>>
coursesa课程 Python 3 programming Functions can call other functions 函数调用另一个函数
查看>>
coursesa课程 Python 3 programming The while Statement
查看>>
course_2_assessment_6
查看>>
coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
查看>>
coursesa课程 Python 3 programming course_2_assessment_8 sorted练习题
查看>>
在unity中建立最小的shader(Minimal Shader)
查看>>
1.3 Debugging of Shaders (调试着色器)
查看>>
关于phpcms中模块_tag.class.php中的pc_tag()方法的含义
查看>>
vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
查看>>
linux安装usb wifi接收器
查看>>
补充自动屏蔽攻击ip
查看>>
谷歌走了
查看>>
多线程使用随机函数需要注意的一点
查看>>
getpeername,getsockname
查看>>
让我做你的下一行Code
查看>>
浅析:setsockopt()改善程序的健壮性
查看>>
关于对象赋值及返回临时对象过程中的构造与析构
查看>>
VS 2005 CRT函数的安全性增强版本
查看>>
SQL 多表联合查询
查看>>