Skip to content

Commit 130546e

Browse files
committed
Semantic segmentation sample.
1 parent f2440ce commit 130546e

13 files changed

+418
-353
lines changed

modules/core/include/opencv2/core.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3159,7 +3159,7 @@ class CV_EXPORTS_W Algorithm
31593159

31603160
struct Param {
31613161
enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7,
3162-
UNSIGNED_INT=8, UINT64=9, UCHAR=11 };
3162+
UNSIGNED_INT=8, UINT64=9, UCHAR=11, SCALAR=12 };
31633163
};
31643164

31653165

@@ -3252,6 +3252,14 @@ template<> struct ParamType<uchar>
32523252
enum { type = Param::UCHAR };
32533253
};
32543254

3255+
template<> struct ParamType<Scalar>
3256+
{
3257+
typedef const Scalar& const_param_type;
3258+
typedef Scalar member_type;
3259+
3260+
enum { type = Param::SCALAR };
3261+
};
3262+
32553263
//! @} core_basic
32563264

32573265
} //namespace cv

modules/core/src/command_line_parser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ static void from_str(const String& str, int type, void* dst)
104104
ss >> *(double*)dst;
105105
else if( type == Param::STRING )
106106
*(String*)dst = str;
107+
else if( type == Param::SCALAR)
108+
{
109+
Scalar& scalar = *(Scalar*)dst;
110+
for (int i = 0; i < 4 && !ss.eof(); ++i)
111+
ss >> scalar[i];
112+
}
107113
else
108114
CV_Error(Error::StsBadArg, "unknown/unsupported parameter type");
109115

File renamed without changes.

samples/data/dnn/enet-classes.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Unlabeled
2+
Road
3+
Sidewalk
4+
Building
5+
Wall
6+
Fence
7+
Pole
8+
TrafficLight
9+
TrafficSign
10+
Vegetation
11+
Terrain
12+
Sky
13+
Person
14+
Rider
15+
Car
16+
Truck
17+
Bus
18+
Train
19+
Motorcycle
20+
Bicycle
File renamed without changes.
File renamed without changes.

samples/dnn/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
| GoogLeNet | `1.0` | `224x224` | `104 117 123` | BGR |
2121
| [SqueezeNet](https://github.com/DeepScale/SqueezeNet) | `1.0` | `227x227` | `0 0 0` | BGR |
2222

23+
### Semantic segmentation
24+
| Model | Scale | Size WxH| Mean subtraction | Channels order |
25+
|---------------|-------|-----------|--------------------|-------|
26+
| [ENet](https://github.com/e-lab/ENet-training) | `0.00392 (1/255)` | `1024x512` | `0 0 0` | RGB |
27+
| FCN8s | `1.0` | `500x500` | `0 0 0` | BGR |
28+
2329
## References
2430
* [Models downloading script](https://github.com/opencv/opencv_extra/blob/master/testdata/dnn/download_models.py)
2531
* [Configuration files adopted for OpenCV](https://github.com/opencv/opencv_extra/tree/master/testdata/dnn)
2632
* [How to import models from TensorFlow Object Detection API](https://github.com/opencv/opencv/wiki/TensorFlow-Object-Detection-API)
33+
* [Names of classes from different datasets](https://github.com/opencv/opencv/tree/master/samples/data/dnn)

samples/dnn/classification.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <fstream>
2-
#include <iostream>
32
#include <sstream>
43

54
#include <opencv2/dnn.hpp>
@@ -17,17 +16,17 @@ const char* keys =
1716
"{ framework f | | Optional name of an origin framework of the model. Detect it automatically if it does not set. }"
1817
"{ classes | | Optional path to a text file with names of classes. }"
1918
"{ mean | | Preprocess input image by subtracting mean values. Mean values should be in BGR order and delimited by spaces. }"
20-
"{ scale | 1 | Preprocess input image by multiplying on a scale factor. }"
21-
"{ width | -1 | Preprocess input image by resizing to a specific width. }"
22-
"{ height | -1 | Preprocess input image by resizing to a specific height. }"
23-
"{ rgb | | Indicate that model works with RGB input images instead BGR ones. }"
24-
"{ backend | 0 | Choose one of computation backends: "
25-
"0: default C++ backend, "
26-
"1: Halide language (http://halide-lang.org/), "
27-
"2: Intel's Deep Learning Inference Engine (https://software.seek.intel.com/deep-learning-deployment)}"
28-
"{ target | 0 | Choose one of target computation devices: "
29-
"0: CPU target (by default),"
30-
"1: OpenCL }";
19+
"{ scale | 1 | Preprocess input image by multiplying on a scale factor. }"
20+
"{ width | | Preprocess input image by resizing to a specific width. }"
21+
"{ height | | Preprocess input image by resizing to a specific height. }"
22+
"{ rgb | | Indicate that model works with RGB input images instead BGR ones. }"
23+
"{ backend | 0 | Choose one of computation backends: "
24+
"0: default C++ backend, "
25+
"1: Halide language (http://halide-lang.org/), "
26+
"2: Intel's Deep Learning Inference Engine (https://software.seek.intel.com/deep-learning-deployment)}"
27+
"{ target | 0 | Choose one of target computation devices: "
28+
"0: CPU target (by default),"
29+
"1: OpenCL }";
3130

3231
using namespace cv;
3332
using namespace dnn;
@@ -45,7 +44,9 @@ int main(int argc, char** argv)
4544
}
4645

4746
float scale = parser.get<float>("scale");
47+
Scalar mean = parser.get<Scalar>("mean");
4848
bool swapRB = parser.get<bool>("rgb");
49+
CV_Assert(parser.has("width"), parser.has("height"));
4950
int inpWidth = parser.get<int>("width");
5051
int inpHeight = parser.get<int>("height");
5152
String model = parser.get<String>("model");
@@ -54,19 +55,6 @@ int main(int argc, char** argv)
5455
int backendId = parser.get<int>("backend");
5556
int targetId = parser.get<int>("target");
5657

57-
// Parse mean values.
58-
Scalar mean;
59-
if (parser.has("mean"))
60-
{
61-
std::istringstream meanStr(parser.get<String>("mean"));
62-
std::vector<float> meanValues;
63-
float val;
64-
while (meanStr >> val)
65-
meanValues.push_back(val);
66-
CV_Assert(meanValues.size() == 3);
67-
mean = Scalar(meanValues[0], meanValues[1], meanValues[2]);
68-
}
69-
7058
// Open file with classes names.
7159
if (parser.has("classes"))
7260
{

samples/dnn/fcn_semsegm.cpp

Lines changed: 0 additions & 138 deletions
This file was deleted.

samples/dnn/object_detection.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <fstream>
2-
#include <iostream>
32
#include <sstream>
43

54
#include <opencv2/dnn.hpp>
@@ -54,23 +53,11 @@ int main(int argc, char** argv)
5453

5554
confThreshold = parser.get<float>("thr");
5655
float scale = parser.get<float>("scale");
56+
Scalar mean = parser.get<Scalar>("mean");
5757
bool swapRB = parser.get<bool>("rgb");
5858
int inpWidth = parser.get<int>("width");
5959
int inpHeight = parser.get<int>("height");
6060

61-
// Parse mean values.
62-
Scalar mean;
63-
if (parser.has("mean"))
64-
{
65-
std::istringstream meanStr(parser.get<String>("mean"));
66-
std::vector<float> meanValues;
67-
float val;
68-
while (meanStr >> val)
69-
meanValues.push_back(val);
70-
CV_Assert(meanValues.size() == 3);
71-
mean = Scalar(meanValues[0], meanValues[1], meanValues[2]);
72-
}
73-
7461
// Open file with classes names.
7562
if (parser.has("classes"))
7663
{

0 commit comments

Comments
 (0)