26 #include <boost/regex.hpp>
28 using boost::regex_match;
31 #include <boost/algorithm/string.hpp>
44 namespace po = boost::program_options;
59 , m_lutz_window_size(0)
60 , m_bfs_max_delta(1000)
61 , m_ml_threshold(0.9) {}
64 return { {
"Detection image", {
66 "Segmentation algorithm to be used (LUTZ, TILES or ML (a ONNX-format model must be provided))"},
68 "Disables filtering"},
72 "Lutz sliding window size (0=disable)"},
74 "BFS algorithm max source x/y size (default=1000)"},
76 "ONNX model to use with machine learning segmentation"},
78 "Probability threshold for ML detection"},
84 if (algorithm_name ==
"LUTZ") {
86 }
else if (algorithm_name ==
"BFS") {
88 }
else if (algorithm_name ==
"ML") {
89 #ifdef WITH_ML_SEGMENTATION
102 if (filter_filename !=
"") {
117 throw Elements::Exception() <<
"Machine learning segmentation requested but no ONNX model was provided";
127 convolution_kernel->setValue(0,0, 1);
128 convolution_kernel->setValue(0,1, 2);
129 convolution_kernel->setValue(0,2, 1);
131 convolution_kernel->setValue(1,0, 2);
132 convolution_kernel->setValue(1,1, 4);
133 convolution_kernel->setValue(1,2, 2);
135 convolution_kernel->setValue(2,0, 1);
136 convolution_kernel->setValue(2,1, 2);
137 convolution_kernel->setValue(2,2, 1);
139 return std::make_shared<BackgroundConvolution>(convolution_kernel,
true);
162 segConfigLogger.
info() <<
"Loaded segmentation filter: " <<
filename <<
" height: " << convolution_kernel->getHeight() <<
" width: " << convolution_kernel->getWidth();
165 return std::make_shared<BackgroundConvolution>(convolution_kernel,
true);
170 line_stream >> conv >> norm_type;
171 if (conv !=
"CONV") {
174 if (norm_type ==
"NORM") {
177 else if (norm_type ==
"NONORM") {
184 template <
typename T>
187 while (line_stream.
good()) {
188 line_stream >> value;
202 enum class LoadState {
208 LoadState state = LoadState::STATE_START;
209 bool normalize =
false;
211 unsigned int kernel_width = 0;
213 while (file.
good()) {
218 if (line.
size() == 0) {
225 case LoadState::STATE_START:
227 state = LoadState::STATE_FIRST_LINE;
229 case LoadState::STATE_FIRST_LINE:
231 kernel_width = kernel_data.
size();
232 state = LoadState::STATE_OTHER_LINES;
234 case LoadState::STATE_OTHER_LINES:
241 auto kernel_height = kernel_data.
size() / kernel_width;
245 segConfigLogger.
info() <<
"Loaded segmentation filter: " <<
filename <<
" width: " << convolution_kernel->getWidth() <<
" height: " << convolution_kernel->getHeight();
248 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)