-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer_vision_2fast_8cpp-example.htm
More file actions
216 lines (216 loc) · 19.5 KB
/
Copy pathcomputer_vision_2fast_8cpp-example.htm
File metadata and controls
216 lines (216 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!-- HTML header for doxygen 1.9.5-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-130950618-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-130950618-1');
</script>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.5"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>ArrayFire: computer_vision/fast.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="arrayfire.css" rel="stylesheet" type="text/css"/>
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
<link href="doxygen-awesome-sidebar-only.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript" src="doxygen-awesome-fragment-copy-button.js"></script>
<script type="text/javascript" src="doxygen-awesome-interactive-toc.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
DoxygenAwesomeInteractiveToc.init()
DoxygenAwesomeFragmentCopyButton.init()
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="2" cellpadding="2" width="100%">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><a href="index.htm"><img alt="Logo" src="arrayfire_logo.png"/></a></td>
</tr>
<tr id="projectrow">
<td>
<div id="projectbrief">A high-performance general-purpose compute library</div>
</td>
</tr>
<!--END !PROJECT_NAME-->
<div>
<td id="gsearch">
<script async src="https://cse.google.com/cse.js?cx=004356362924927882526:zup3ehe-7bs"></script>
<div class="gcse-search"></div>
</td>
</div>
</tr>
<tr>
<td>
<div id="togglediv"></div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part --><!-- Generated by Doxygen 1.9.5 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.htm"><span>Main Page</span></a></li>
<li><a href="tutorials.htm"><span>Tutorials</span></a></li>
<li><a href="modules.htm"><span>Functions</span></a></li>
<li><a href="releasenotes.htm"><span>Release Notes</span></a></li>
<li><a href="examples.htm"><span>Examples</span></a></li>
</ul>
</div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(document).ready(function(){initNavTree('computer_vision_2fast_8cpp-example.htm',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle"><div class="title">computer_vision/fast.cpp</div></div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/*******************************************************</span></div>
<div class="line"><span class="comment"> * Copyright (c) 2015, ArrayFire</span></div>
<div class="line"><span class="comment"> * All rights reserved.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * This file is distributed under 3-clause BSD license.</span></div>
<div class="line"><span class="comment"> * The complete license agreement can be obtained at:</span></div>
<div class="line"><span class="comment"> * http://arrayfire.com/licenses/BSD-3-Clause</span></div>
<div class="line"><span class="comment"> ********************************************************/</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <<a class="code" href="arrayfire_8h.htm">arrayfire.h</a>></span></div>
<div class="line"><span class="preprocessor">#include <cstdio></span></div>
<div class="line"><span class="preprocessor">#include <cstdlib></span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using namespace </span><a class="code hl_namespace" href="namespaceaf.htm">af</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> fast_demo(<span class="keywordtype">bool</span> console) {</div>
<div class="line"> <span class="comment">// Load image</span></div>
<div class="line"> <a id="_a0" name="_a0"></a><a class="code hl_class" href="classaf_1_1array.htm">array</a> img_color;</div>
<div class="line"> <span class="keywordflow">if</span> (console)</div>
<div class="line"> img_color = loadImage(ASSETS_DIR <span class="stringliteral">"/examples/images/square.png"</span>, <span class="keyword">true</span>);</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> img_color = loadImage(ASSETS_DIR <span class="stringliteral">"/examples/images/man.jpg"</span>, <span class="keyword">true</span>);</div>
<div class="line"> <span class="comment">// Convert the image from RGB to gray-scale</span></div>
<div class="line"> <a class="code hl_class" href="classaf_1_1array.htm">array</a> img = colorSpace(img_color, <a id="a1" name="a1"></a><a class="code hl_enumvalue" href="defines_8h.htm#ae1e32be35ff02f167999723d77153f0da2b379305db06eb19ff82ce7e85b7c4b1">AF_GRAY</a>, <a id="a2" name="a2"></a><a class="code hl_enumvalue" href="defines_8h.htm#ae1e32be35ff02f167999723d77153f0dad9c37bf4beee3f07b8b1aa4b887244e6">AF_RGB</a>);</div>
<div class="line"> <span class="comment">// For visualization in ArrayFire, color images must be in the [0.0f-1.0f]</span></div>
<div class="line"> <span class="comment">// interval</span></div>
<div class="line"> img_color /= 255.f;</div>
<div class="line"> </div>
<div class="line"> <a id="_a3" name="_a3"></a><a class="code hl_class" href="classaf_1_1features.htm">features</a> feat = fast(img, 20.0f, 9, <span class="keyword">true</span>, 0.05);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordtype">float</span>* h_x = feat.<a id="a4" name="a4"></a><a class="code hl_function" href="classaf_1_1features.htm#ae8070eab6da9f4d42c3f7b2c219f2f8d">getX</a>().<a id="a5" name="a5"></a><a class="code hl_function" href="classaf_1_1array.htm#a44a7a503b21a96e6bb16636227ae5e35">host</a><<span class="keywordtype">float</span>>();</div>
<div class="line"> <span class="keywordtype">float</span>* h_y = feat.<a id="a6" name="a6"></a><a class="code hl_function" href="classaf_1_1features.htm#ad4ae029d57eb27f8e4f781ca7887b3b2">getY</a>().<a class="code hl_function" href="classaf_1_1array.htm#a44a7a503b21a96e6bb16636227ae5e35">host</a><<span class="keywordtype">float</span>>();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Draw draw_len x draw_len crosshairs where the corners are</span></div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">int</span> draw_len = 3;</div>
<div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> f = 0; f < feat.<a id="a7" name="a7"></a><a class="code hl_function" href="classaf_1_1features.htm#ad8e831cca66465642b24a1b1f6416ea1">getNumFeatures</a>(); f++) {</div>
<div class="line"> <span class="keywordtype">int</span> x = h_x[f];</div>
<div class="line"> <span class="keywordtype">int</span> y = h_y[f];</div>
<div class="line"> img_color(y, <a id="_a8" name="_a8"></a><a class="code hl_class" href="classaf_1_1seq.htm">seq</a>(x - draw_len, x + draw_len), 0) = 0.f;</div>
<div class="line"> img_color(y, <a class="code hl_class" href="classaf_1_1seq.htm">seq</a>(x - draw_len, x + draw_len), 1) = 1.f;</div>
<div class="line"> img_color(y, <a class="code hl_class" href="classaf_1_1seq.htm">seq</a>(x - draw_len, x + draw_len), 2) = 0.f;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Draw vertical line of (draw_len * 2 + 1) pixels centered on the</span></div>
<div class="line"> <span class="comment">// corner Set only the first channel to 1 (green lines)</span></div>
<div class="line"> img_color(<a class="code hl_class" href="classaf_1_1seq.htm">seq</a>(y - draw_len, y + draw_len), x, 0) = 0.f;</div>
<div class="line"> img_color(<a class="code hl_class" href="classaf_1_1seq.htm">seq</a>(y - draw_len, y + draw_len), x, 1) = 1.f;</div>
<div class="line"> img_color(<a class="code hl_class" href="classaf_1_1seq.htm">seq</a>(y - draw_len, y + draw_len), x, 2) = 0.f;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> freeHost(h_x);</div>
<div class="line"> freeHost(h_y);</div>
<div class="line"> </div>
<div class="line"> printf(<span class="stringliteral">"Features found: %zu\n"</span>, feat.<a class="code hl_function" href="classaf_1_1features.htm#ad8e831cca66465642b24a1b1f6416ea1">getNumFeatures</a>());</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span> (!console) {</div>
<div class="line"> <a id="_a9" name="_a9"></a><a class="code hl_class" href="classaf_1_1Window.htm">af::Window</a> wnd(<span class="stringliteral">"FAST Feature Detector"</span>);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Previews color image with green crosshairs</span></div>
<div class="line"> <span class="keywordflow">while</span> (!wnd.<a id="a10" name="a10"></a><a class="code hl_function" href="group__gfx__func__window.htm#ga46143fd6de3be9ab9951f140d3ae8c2f">close</a>()) wnd.<a id="a11" name="a11"></a><a class="code hl_function" href="group__gfx__func__draw.htm#gaed174450be6db4dfa5ef65b7baccbe57">image</a>(img_color);</div>
<div class="line"> } <span class="keywordflow">else</span> {</div>
<div class="line"> <a id="a12" name="a12"></a><a class="code hl_define" href="util_8h.htm#a6de8e7f9eb3914d1cea66e55e7b791d3">af_print</a>(feat.<a class="code hl_function" href="classaf_1_1features.htm#ae8070eab6da9f4d42c3f7b2c219f2f8d">getX</a>());</div>
<div class="line"> <a class="code hl_define" href="util_8h.htm#a6de8e7f9eb3914d1cea66e55e7b791d3">af_print</a>(feat.<a class="code hl_function" href="classaf_1_1features.htm#ad4ae029d57eb27f8e4f781ca7887b3b2">getY</a>());</div>
<div class="line"> }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv) {</div>
<div class="line"> <span class="keywordtype">int</span> device = argc > 1 ? atoi(argv[1]) : 0;</div>
<div class="line"> <span class="keywordtype">bool</span> console = argc > 2 ? argv[2][0] == <span class="charliteral">'-'</span> : <span class="keyword">false</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">try</span> {</div>
<div class="line"> <a id="a13" name="a13"></a><a class="code hl_function" href="group__device__func__set.htm#gad7c36828c21e7efc06a067bbc47d8d3b">af::setDevice</a>(device);</div>
<div class="line"> <a id="a14" name="a14"></a><a class="code hl_function" href="group__device__func__info.htm#ga3e22b6ff6e0940bb31577bea2863ca27">af::info</a>();</div>
<div class="line"> printf(<span class="stringliteral">"** ArrayFire FAST Feature Detector Demo **\n\n"</span>);</div>
<div class="line"> fast_demo(console);</div>
<div class="line"> </div>
<div class="line"> } <span class="keywordflow">catch</span> (<a id="_a15" name="_a15"></a><a class="code hl_class" href="classaf_1_1exception.htm">af::exception</a>& ae) {</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">"%s\n"</span>, ae.<a id="a16" name="a16"></a><a class="code hl_function" href="classaf_1_1exception.htm#aa884ff67408851f00e50cf971a4dfd05">what</a>());</div>
<div class="line"> <span class="keywordflow">throw</span>;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="aarrayfire_8h_htm"><div class="ttname"><a href="arrayfire_8h.htm">arrayfire.h</a></div></div>
<div class="ttc" id="aclassaf_1_1Window_htm"><div class="ttname"><a href="classaf_1_1Window.htm">af::Window</a></div><div class="ttdoc">Window object to render af::arrays.</div><div class="ttdef"><b>Definition:</b> <a href="graphics_8h_source.htm#l00037">graphics.h:37</a></div></div>
<div class="ttc" id="aclassaf_1_1array_htm"><div class="ttname"><a href="classaf_1_1array.htm">af::array</a></div><div class="ttdoc">A multi dimensional data container.</div><div class="ttdef"><b>Definition:</b> <a href="array_8h_source.htm#l00037">array.h:37</a></div></div>
<div class="ttc" id="aclassaf_1_1array_htm_a44a7a503b21a96e6bb16636227ae5e35"><div class="ttname"><a href="classaf_1_1array.htm#a44a7a503b21a96e6bb16636227ae5e35">af::array::host</a></div><div class="ttdeci">T * host() const</div><div class="ttdoc">Copy array data to host and return host pointer.</div></div>
<div class="ttc" id="aclassaf_1_1exception_htm"><div class="ttname"><a href="classaf_1_1exception.htm">af::exception</a></div><div class="ttdoc">An ArrayFire exception class.</div><div class="ttdef"><b>Definition:</b> <a href="exception_8h_source.htm#l00021">exception.h:22</a></div></div>
<div class="ttc" id="aclassaf_1_1exception_htm_aa884ff67408851f00e50cf971a4dfd05"><div class="ttname"><a href="classaf_1_1exception.htm#aa884ff67408851f00e50cf971a4dfd05">af::exception::what</a></div><div class="ttdeci">virtual const char * what() const</div><div class="ttdoc">Returns an error message for the exception in a string format.</div><div class="ttdef"><b>Definition:</b> <a href="exception_8h_source.htm#l00046">exception.h:46</a></div></div>
<div class="ttc" id="aclassaf_1_1features_htm"><div class="ttname"><a href="classaf_1_1features.htm">af::features</a></div><div class="ttdoc">Represents a feature returned by a feature detector.</div><div class="ttdef"><b>Definition:</b> <a href="features_8h_source.htm#l00024">features.h:24</a></div></div>
<div class="ttc" id="aclassaf_1_1features_htm_ad4ae029d57eb27f8e4f781ca7887b3b2"><div class="ttname"><a href="classaf_1_1features.htm#ad4ae029d57eb27f8e4f781ca7887b3b2">af::features::getY</a></div><div class="ttdeci">array getY() const</div><div class="ttdoc">Returns an af::array which represents the y locations of a feature.</div></div>
<div class="ttc" id="aclassaf_1_1features_htm_ad8e831cca66465642b24a1b1f6416ea1"><div class="ttname"><a href="classaf_1_1features.htm#ad8e831cca66465642b24a1b1f6416ea1">af::features::getNumFeatures</a></div><div class="ttdeci">size_t getNumFeatures() const</div><div class="ttdoc">Returns the number of features represented by this object.</div></div>
<div class="ttc" id="aclassaf_1_1features_htm_ae8070eab6da9f4d42c3f7b2c219f2f8d"><div class="ttname"><a href="classaf_1_1features.htm#ae8070eab6da9f4d42c3f7b2c219f2f8d">af::features::getX</a></div><div class="ttdeci">array getX() const</div><div class="ttdoc">Returns an af::array which represents the x locations of a feature.</div></div>
<div class="ttc" id="aclassaf_1_1seq_htm"><div class="ttname"><a href="classaf_1_1seq.htm">af::seq</a></div><div class="ttdoc">seq is used to create sequences for indexing af::array</div><div class="ttdef"><b>Definition:</b> <a href="seq_8h_source.htm#l00045">seq.h:46</a></div></div>
<div class="ttc" id="adefines_8h_htm_ae1e32be35ff02f167999723d77153f0da2b379305db06eb19ff82ce7e85b7c4b1"><div class="ttname"><a href="defines_8h.htm#ae1e32be35ff02f167999723d77153f0da2b379305db06eb19ff82ce7e85b7c4b1">AF_GRAY</a></div><div class="ttdeci">@ AF_GRAY</div><div class="ttdoc">Grayscale.</div><div class="ttdef"><b>Definition:</b> <a href="defines_8h_source.htm#l00343">defines.h:343</a></div></div>
<div class="ttc" id="adefines_8h_htm_ae1e32be35ff02f167999723d77153f0dad9c37bf4beee3f07b8b1aa4b887244e6"><div class="ttname"><a href="defines_8h.htm#ae1e32be35ff02f167999723d77153f0dad9c37bf4beee3f07b8b1aa4b887244e6">AF_RGB</a></div><div class="ttdeci">@ AF_RGB</div><div class="ttdoc">3-channel RGB</div><div class="ttdef"><b>Definition:</b> <a href="defines_8h_source.htm#l00344">defines.h:344</a></div></div>
<div class="ttc" id="agroup__device__func__info_htm_ga3e22b6ff6e0940bb31577bea2863ca27"><div class="ttname"><a href="group__device__func__info.htm#ga3e22b6ff6e0940bb31577bea2863ca27">af::info</a></div><div class="ttdeci">AFAPI void info()</div></div>
<div class="ttc" id="agroup__device__func__set_htm_gad7c36828c21e7efc06a067bbc47d8d3b"><div class="ttname"><a href="group__device__func__set.htm#gad7c36828c21e7efc06a067bbc47d8d3b">af::setDevice</a></div><div class="ttdeci">AFAPI void setDevice(const int device)</div><div class="ttdoc">Sets the current device.</div></div>
<div class="ttc" id="agroup__gfx__func__draw_htm_gaed174450be6db4dfa5ef65b7baccbe57"><div class="ttname"><a href="group__gfx__func__draw.htm#gaed174450be6db4dfa5ef65b7baccbe57">af::Window::image</a></div><div class="ttdeci">void image(const array &in, const char *title=NULL)</div><div class="ttdoc">Renders the input array as an image to the window.</div></div>
<div class="ttc" id="agroup__gfx__func__window_htm_ga46143fd6de3be9ab9951f140d3ae8c2f"><div class="ttname"><a href="group__gfx__func__window.htm#ga46143fd6de3be9ab9951f140d3ae8c2f">af::Window::close</a></div><div class="ttdeci">bool close()</div><div class="ttdoc">Check if window is marked for close.</div></div>
<div class="ttc" id="anamespaceaf_htm"><div class="ttname"><a href="namespaceaf.htm">af</a></div><div class="ttdef"><b>Definition:</b> <a href="algorithm_8h_source.htm#l00014">algorithm.h:15</a></div></div>
<div class="ttc" id="autil_8h_htm_a6de8e7f9eb3914d1cea66e55e7b791d3"><div class="ttname"><a href="util_8h.htm#a6de8e7f9eb3914d1cea66e55e7b791d3">af_print</a></div><div class="ttdeci">#define af_print(...)</div><div class="ttdef"><b>Definition:</b> <a href="util_8h_source.htm#l00148">util.h:148</a></div></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.9.3-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.5 </li>
</ul>
</div>
</body>
</html>