openbr.h
15.2 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright 2012 The MITRE Corporation *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef __OPENBR_H
#define __OPENBR_H
#include <openbr_export.h>
#ifdef __cplusplus
extern "C" {
#endif
/*!
* \defgroup c_sdk C SDK
* \brief High-level API for running algorithms and evaluating results. Wrappers are available for other programming languages.
*
* In order to provide a high-level interface that is usable from the command line and callable from other programming languages,
* the API is designed to operate at the "file system" level.
* In other words, arguments to many functions are file paths that specify either a source of input or a desired output.
* File extensions are relied upon to determine \em how files should be interpreted in the context of the function being called.
* The \ref cpp_plugin_sdk should be used if more fine-grained control is required.
*
* \code
* #include <openbr.h>
* \endcode
* <a href="http://www.cmake.org/">CMake</a> developers may wish to use <tt>share/openbr/cmake/OpenBRConfig.cmake</tt>.
*
* \section python_api Python API
* A Python API is available via <a href="http://www.swig.org/">SWIG</a>.
* \code
* $ ls include/br/python
* \endcode
*
* \section java_api Java API
* A Java API is available via <a href="http://www.swig.org/">SWIG</a>.
* \code
* $ ls include/br/java
* \endcode
*/
/*!
* \addtogroup c_sdk
* @{
*/
/*!
* \brief Wraps br::Context::about()
* \note \ref managed_return_value
* \see br_version
*/
BR_EXPORT const char *br_about();
/*!
* \brief Clusters one or more similarity matrices into a list of subjects.
*
* A similarity matrix is a type of br::Output. The current clustering algorithm is a simplified implementation of \cite zhu11.
* \param num_simmats Size of \c simmats.
* \param simmats Array of \ref simmat composing one large self-similarity matrix arranged in row major order.
* \param aggressiveness The higher the aggressiveness the larger the clusters. Suggested range is [0,10].
* \param csv The cluster results file to generate. Results are stored one row per cluster and use gallery indices.
*/
BR_EXPORT void br_cluster(int num_simmats, const char *simmats[], float aggressiveness, const char *csv);
/*!
* \brief Combines several equal-sized mask matrices.
* \param num_input_masks Size of \c input_masks
* \param input_masks Array of \ref mask to combine.
* All matrices must have the same dimensions.
* \param output_mask The file to contain the resulting \ref mask.
* \param method Either:
* - \c And - Ignore comparison if \em any input masks ignore.
* - \c Or - Ignore comparison if \em all input masks ignore.
* \note A comparison may not be simultaneously identified as both a genuine and an impostor by different input masks.
* \see br_make_mask
*/
BR_EXPORT void br_combine_masks(int num_input_masks, const char *input_masks[], const char *output_mask, const char *method);
/*!
* \brief Compares each template in the query gallery to each template in the target gallery.
* \param target_gallery The br::Gallery file whose templates make up the columns of the output.
* \param query_gallery The br::Gallery file whose templates make up the rows of the output.
* A value of '.' reuses the target gallery as the query gallery.
* \param output Optional br::Output file to contain the results of comparing the templates.
* The default behavior is to print scores to the terminal.
* \see br_enroll
*/
BR_EXPORT void br_compare(const char *target_gallery, const char *query_gallery, const char *output = "");
/*!
* \brief Computes the confusion matrix for a dataset at a particular threshold.
*
* <a href="http://en.wikipedia.org/wiki/Confusion_matrix">Wikipedia Explanation</a>
* \param file <tt>.csv</tt> file created using \ref br_eval.
* \param score The similarity score to threshold at.
* \param[out] true_positives The true positive count.
* \param[out] false_positives The false positive count.
* \param[out] true_negatives The true negative count.
* \param[out] false_negatives The false negative count.
*/
BR_EXPORT void br_confusion(const char *file, float score,
int *true_positives, int *false_positives, int *true_negatives, int *false_negatives);
/*!
* \brief Converts a <i>.csv</i> file to/from a \ref simmat or \ref mask.
* \param input_matrix The input matrix.
* \param output_matrix The output matrix.
*/
BR_EXPORT void br_convert(const char *input_matrix, const char *output_matrix);
/*!
* \brief Constructs template(s) from an input.
* \param input The br::Input set of images to enroll.
* \param gallery The br::Gallery file to contain the enrolled templates.
* By default the gallery will be held in memory and \em input can used as a gallery in \ref br_compare.
* \see br_enroll_n
*/
BR_EXPORT void br_enroll(const char *input, const char *gallery = "");
/*!
* \brief Convenience function for enrolling multiple inputs.
* \see br_enroll
*/
BR_EXPORT void br_enroll_n(int num_inputs, const char *inputs[], const char *gallery = "");
/*!
* \brief Creates a \c .csv file containing performance metrics from evaluating the similarity matrix using the mask matrix.
* \param simmat The \ref simmat to use.
* \param mask The \ref mask to use.
* \param csv Optional \c .csv file to contain performance metrics.
* \return True accept rate at a false accept rate of one in one hundred.
* \see br_plot
*/
BR_EXPORT float br_eval(const char *simmat, const char *mask, const char *csv = "");
/*!
* \brief Evaluates and prints classification accuracy to terminal.
* \param predicted_input The predicted br::Input.
* \param truth_input The ground truth br::Input.
* \see br_enroll
*/
BR_EXPORT void br_eval_classification(const char *predicted_input, const char *truth_input);
/*!
* \brief Evaluates and prints clustering accuracy to the terminal.
* \param csv The cluster results file.
* \param input The br::input used to generate the \ref simmat that was clustered.
* \see br_cluster
*/
BR_EXPORT void br_eval_clustering(const char *csv, const char *input);
/*!
* \brief Evaluates regression accuracy to disk.
* \param predicted_input The predicted br::Input.
* \param truth_input The ground truth br::Input.
* \see br_enroll
*/
BR_EXPORT void br_eval_regression(const char *predicted_input, const char *truth_input);
/*!
* \brief Wraps br::Context::finalize()
* \see br_initialize
*/
BR_EXPORT void br_finalize();
/*!
* \brief Perform score level fusion on similarity matrices.
* \param num_input_simmats Size of \em input_simmats.
* \param input_simmats Array of \ref simmat. All simmats must have the same dimensions.
* \param mask \ref mask used to indicate which, if any, values to ignore.
* \param normalization Valid options are:
* - \c None - No score normalization.
* - \c MinMax - Scores normalized to [0,1].
* - \c ZScore - Scores normalized to a standard normal curve.
* \param fusion Valid options are:
* - \c Min - Uses the minimum score.
* - \c Max - Uses the maximum score.
* - \c Sum - Sums the scores. Sums can also be weighted: <tt>SumW1:W2:...:Wn</tt>.
* - \c Replace - Replaces scores in the first matrix with scores in the second matrix when the mask is set.
* \param output_simmat \ref simmat to contain the fused scores.
*/
BR_EXPORT void br_fuse(int num_input_simmats, const char *input_simmats[], const char *mask,
const char *normalization, const char *fusion, const char *output_simmat);
/*!
* \brief Wraps br::Context::initialize()
* \see br_initialize_qt br_finalize
*/
BR_EXPORT void br_initialize(int argc, char *argv[], const char *sdk_path = "");
/*!
* \brief Wraps br::Context::initializeQt()
* \see br_initialize br_finalize
*/
BR_EXPORT void br_initialize_qt(const char *sdk_path = "");
/*!
* \brief Wraps br::IsClassifier()
*/
BR_EXPORT bool br_is_classifier(const char *algorithm);
/*!
* \brief Constructs a \ref mask from target and query inputs.
* \param target_input The target br::Input.
* \param query_input The query br::Input.
* \param mask The file to contain the resulting \ref mask.
* \see br_combine_masks
*/
BR_EXPORT void br_make_mask(const char *target_input, const char *query_input, const char *mask);
/*!
* \brief Returns the most recent line sent to stderr.
* \note \ref managed_return_value
* \see br_progress br_time_remaining
*/
BR_EXPORT const char *br_most_recent_message();
/*!
* \brief Returns names and parameters for the requested objects.
*
* Each object is \c \\n seperated. Arguments are seperated from the object name with a \c \\t.
* \param abstractions Regular expression of the abstractions to search.
* \param implementations Regular expression of the implementations to search.
* \param parameters Include parameters after object name.
* \note \ref managed_return_value
* \note This function uses Qt's <a href="http://doc.qt.digia.com/stable/qregexp.html">QRegExp</a> syntax.
*/
BR_EXPORT const char *br_objects(const char *abstractions = ".*", const char *implementations = ".*", bool parameters = true);
/*!
* \brief Renders performance figures for a set of <tt>.csv</tt> files.
*
* In order of their output, the figures are:
* -# Metadata table
* -# Detection Error Tradeoff (DET)
* -# Receiver Operating Characteristic (ROC)
* -# Score Distribution (SD) histogram
* -# True Accept Rate Bar Chart (BC)
* -# Cumulative Match Characteristic (CMC)
* -# False Accept Rate (FAR) curve
* -# False Reject Rate (FRR) curve
*
* Several files will be created:
* - <i>destination</i><tt>.R</tt> which is the auto-generated R script used to render the figures.
* - <i>destination</i><tt>.pdf</tt> which has all of the figures in one file (convenient for attaching in an email).
* - <i>destination</i><tt>_DET.pdf</tt>, ..., <i>destination</i><tt>_FAR.pdf</tt> which has each figure in a separate file (convenient for including in a presentation).
*
* \param num_files Number of <tt>.csv</tt> files.
* \param files <tt>.csv</tt> files created using \ref br_eval.
* \param destination Basename for the resulting figures.
* \param show Open <i>destination</i>.pdf using the system's default PDF viewer.
* \return Returns \c true on success. Returns false on a failure to compile the figures due to a missing, out of date, or incomplete \c R installation.
* \note
* - See \ref installing_r
* - End <i>destination</i> with <tt>.png</tt> to render as images.
* - Run <a href="http://stat.ethz.ch/R-manual/R-devel/library/utils/html/Rscript.html">Rcript</a> on <i>destination</i><tt>.R</tt> to recompile the figures.
* \see br_plot_metadata
*/
BR_EXPORT bool br_plot(int num_files, const char *files[], const char *destination, bool show = false);
/*!
* \brief Renders metadata figures for a set of <tt>.csv</tt> files with specified columns.
*
* Several files will be created:
* - <tt>PlotMetadata.R</tt> which is the auto-generated R script used to render the figures.
* - <tt>PlotMetadata.pdf</tt> which has all of the figures in one file (convenient for attaching in an email).
* - <i>column</i><tt>.pdf</tt>, ..., <i>column</i><tt>.pdf</tt> which has each figure in a separate file (convenient for including in a presentation).
*
* \param num_files Number of <tt>.csv</tt> files.
* \param files <tt>.csv</tt> files created by enrolling templates to <tt>.csv</tt> metadata files.
* \param columns ';' seperated list of columns to plot.
* \param show Open <tt>PlotMetadata.pdf</tt> using the system's default PDF viewer.
* \return See \ref br_plot
*/
BR_EXPORT bool br_plot_metadata(int num_files, const char *files[], const char *columns, bool show = false);
/*!
* \brief Wraps br::Context::progress()
* \see br_most_recent_message br_time_remaining
*/
BR_EXPORT float br_progress();
/*!
* \brief Read and parse a line from the terminal.
*
* Used by the \ref cli to implement \c -shell.
* Generally not useful otherwise.
* \param[out] argc argument count
* \param[out] argv argument list
* \note \ref managed_return_value
*/
BR_EXPORT void br_read_line(int *argc, const char ***argv);
/*!
* \brief Converts a simmat to a new output format.
* \param target_input The target br::Input used to make \em simmat.
* \param query_input The query br::Input used to make \em simmat.
* \param simmat The \ref simmat to reformat.
* \param output The br::Output to create.
*/
BR_EXPORT void br_reformat(const char *target_input, const char *query_input, const char *simmat, const char *output);
/*!
* \brief Wraps br::Context::scratchPath()
* \note \ref managed_return_value
* \see br_version
*/
BR_EXPORT const char *br_scratch_path();
/*!
* \brief Returns the full path to the root of the SDK.
* \note \ref managed_return_value
* \see br_initialize
*/
BR_EXPORT const char *br_sdk_path();
/*!
*\brief Wraps br::Context::setProperty()
*/
BR_EXPORT void br_set_property(const char *key, const char *value);
/*!
* \brief Wraps br::Context::timeRemaining()
* \see br_most_recent_message br_progress
*/
BR_EXPORT int br_time_remaining();
/*!
* \brief Trains the br::Transform and br::Comparer on the input.
* \param input The br::Input set of images to train on.
* \param model Optional string specifying the binary file to serialize training results to.
* The trained algorithm can be recovered by using this file as the algorithm.
* By default the trained algorithm will not be serialized to disk.
* \see br_train_n
*/
BR_EXPORT void br_train(const char *input, const char *model = "");
/*!
* \brief Convenience function for training on multiple inputs.
* \see br_train
*/
BR_EXPORT void br_train_n(int num_inputs, const char *inputs[], const char *model = "");
/*!
* \brief Wraps br::Context::version()
* \note \ref managed_return_value
* \see br_about br_scratch_path
*/
BR_EXPORT const char *br_version();
/*! @}*/
#ifdef __cplusplus
}
#endif
#endif // __OPENBR_H