26#include <boost/regex.hpp>
27#include <boost/algorithm/string.hpp>
37using boost::regex_match;
41namespace po = boost::program_options;
56 , m_lutz_window_size(0)
57 , m_bfs_max_delta(1000)
58 , m_ml_threshold(0.9) {}
61 return { {
"Detection image", {
63 "Segmentation algorithm to be used (LUTZ, TILES or ML (a ONNX-format model must be provided))"},
69 "Lutz sliding window size (0=disable)"},
71 "BFS algorithm max source x/y size (default=1000)"},
73 "ONNX model to use with machine learning segmentation"},
75 "Probability threshold for ML detection"},
81 if (algorithm_name ==
"LUTZ") {
83 }
else if (algorithm_name ==
"BFS") {
85 }
else if (algorithm_name ==
"ML") {
86#ifdef WITH_ML_SEGMENTATION
97 if (filter_filename !=
"") {
114 throw Elements::Exception() <<
"Machine learning segmentation requested but no ONNX model was provided";
121 convolution_kernel->setValue(0,0, 1);
122 convolution_kernel->setValue(0,1, 2);
123 convolution_kernel->setValue(0,2, 1);
125 convolution_kernel->setValue(1,0, 2);
126 convolution_kernel->setValue(1,1, 4);
127 convolution_kernel->setValue(1,2, 2);
129 convolution_kernel->setValue(2,0, 1);
130 convolution_kernel->setValue(2,1, 2);
131 convolution_kernel->setValue(2,2, 1);
133 return std::make_shared<BackgroundConvolution>(convolution_kernel,
true);
139 if (filename.length() >= fits_ending.
length()
140 && filename.compare (filename.length() - fits_ending.
length(), fits_ending.
length(), fits_ending)==0) {
156 segConfigLogger.
info() <<
"Loaded segmentation filter: " << filename <<
" height: " << convolution_kernel->getHeight() <<
" width: " << convolution_kernel->getWidth();
159 return std::make_shared<BackgroundConvolution>(convolution_kernel,
true);
164 line_stream >> conv >> norm_type;
165 if (conv !=
"CONV") {
168 if (norm_type ==
"NORM") {
171 else if (norm_type ==
"NONORM") {
181 while (line_stream.
good()) {
182 line_stream >> value;
196 enum class LoadState {
202 LoadState state = LoadState::STATE_START;
203 bool normalize =
false;
205 size_t kernel_width = 0;
207 while (file.
good()) {
212 if (line.
size() == 0) {
219 case LoadState::STATE_START:
221 state = LoadState::STATE_FIRST_LINE;
223 case LoadState::STATE_FIRST_LINE:
225 kernel_width = kernel_data.
size();
226 state = LoadState::STATE_OTHER_LINES;
228 case LoadState::STATE_OTHER_LINES:
235 if (kernel_width == 0) {
238 auto kernel_height = kernel_data.
size() / kernel_width;
242 segConfigLogger.
info() <<
"Loaded segmentation filter: " << filename <<
" width: " << convolution_kernel->getWidth() <<
" height: " << convolution_kernel->getHeight();
245 return std::make_shared<BackgroundConvolution>(convolution_kernel, normalize);
static Logging getLogger(const std::string &name="")
void info(const std::string &logMessage)
T regex_replace(T... args)