1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Semantic segmentation sample.

This commit is contained in:
Dmitry Kurtaev
2018-03-06 19:29:23 +03:00
parent f2440ceae6
commit 130546e1d9
13 changed files with 418 additions and 353 deletions
+13 -25
View File
@@ -1,5 +1,4 @@
#include <fstream>
#include <iostream>
#include <sstream>
#include <opencv2/dnn.hpp>
@@ -17,17 +16,17 @@ const char* keys =
"{ framework f | | Optional name of an origin framework of the model. Detect it automatically if it does not set. }"
"{ classes | | Optional path to a text file with names of classes. }"
"{ mean | | Preprocess input image by subtracting mean values. Mean values should be in BGR order and delimited by spaces. }"
"{ scale | 1 | Preprocess input image by multiplying on a scale factor. }"
"{ width | -1 | Preprocess input image by resizing to a specific width. }"
"{ height | -1 | Preprocess input image by resizing to a specific height. }"
"{ rgb | | Indicate that model works with RGB input images instead BGR ones. }"
"{ backend | 0 | Choose one of computation backends: "
"0: default C++ backend, "
"1: Halide language (http://halide-lang.org/), "
"2: Intel's Deep Learning Inference Engine (https://software.seek.intel.com/deep-learning-deployment)}"
"{ target | 0 | Choose one of target computation devices: "
"0: CPU target (by default),"
"1: OpenCL }";
"{ scale | 1 | Preprocess input image by multiplying on a scale factor. }"
"{ width | | Preprocess input image by resizing to a specific width. }"
"{ height | | Preprocess input image by resizing to a specific height. }"
"{ rgb | | Indicate that model works with RGB input images instead BGR ones. }"
"{ backend | 0 | Choose one of computation backends: "
"0: default C++ backend, "
"1: Halide language (http://halide-lang.org/), "
"2: Intel's Deep Learning Inference Engine (https://software.seek.intel.com/deep-learning-deployment)}"
"{ target | 0 | Choose one of target computation devices: "
"0: CPU target (by default),"
"1: OpenCL }";
using namespace cv;
using namespace dnn;
@@ -45,7 +44,9 @@ int main(int argc, char** argv)
}
float scale = parser.get<float>("scale");
Scalar mean = parser.get<Scalar>("mean");
bool swapRB = parser.get<bool>("rgb");
CV_Assert(parser.has("width"), parser.has("height"));
int inpWidth = parser.get<int>("width");
int inpHeight = parser.get<int>("height");
String model = parser.get<String>("model");
@@ -54,19 +55,6 @@ int main(int argc, char** argv)
int backendId = parser.get<int>("backend");
int targetId = parser.get<int>("target");
// Parse mean values.
Scalar mean;
if (parser.has("mean"))
{
std::istringstream meanStr(parser.get<String>("mean"));
std::vector<float> meanValues;
float val;
while (meanStr >> val)
meanValues.push_back(val);
CV_Assert(meanValues.size() == 3);
mean = Scalar(meanValues[0], meanValues[1], meanValues[2]);
}
// Open file with classes names.
if (parser.has("classes"))
{