Skip to content

Commit 538fd42

Browse files
committed
Add test for Scalar arguments at CommandLineParser
1 parent 130546e commit 538fd42

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

doc/tutorials/dnn/dnn_yolo/dnn_yolo.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Execute with image or video file:
3737

3838
@code{.bash}
3939

40-
$ example_dnn_object_detection --config=[PATH-TO-DARKNET]/cfg/yolo.cfg --model=[PATH-TO-DARKNET]/yolo.weights --classes=object_detection_classes_pascal_voc.txt --width=416 --height=416 --scale=0.00392 --input[PATH-TO-IMAGE-OR-VIDEO-FILE]
40+
$ example_dnn_object_detection --config=[PATH-TO-DARKNET]/cfg/yolo.cfg --model=[PATH-TO-DARKNET]/yolo.weights --classes=object_detection_classes_pascal_voc.txt --width=416 --height=416 --scale=0.00392 --input=[PATH-TO-IMAGE-OR-VIDEO-FILE]
4141

4242
@endcode
4343

modules/core/test/test_utils.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,26 @@ TEST(AutoBuffer, allocate_test)
261261
EXPECT_EQ(6u, abuf.size());
262262
}
263263

264+
TEST(CommandLineParser, testScalar)
265+
{
266+
static const char * const keys3 =
267+
"{ s0 | 3 4 5 | default scalar }"
268+
"{ s1 | | single value scalar }"
269+
"{ s2 | | two values scalar (default with zeros) }"
270+
"{ s3 | | three values scalar }"
271+
"{ s4 | | four values scalar }"
272+
"{ s5 | | five values scalar }";
273+
274+
const char* argv[] = {"<bin>", "--s1=1.1", "--s3=1.1 2.2 3",
275+
"--s4=-4.2 1 0 3", "--s5=5 -4 3 2 1"};
276+
const int argc = 5;
277+
CommandLineParser parser(argc, argv, keys3);
278+
EXPECT_EQ(parser.get<Scalar>("s0"), Scalar(3, 4, 5));
279+
EXPECT_EQ(parser.get<Scalar>("s1"), Scalar(1.1));
280+
EXPECT_EQ(parser.get<Scalar>("s2"), Scalar(0));
281+
EXPECT_EQ(parser.get<Scalar>("s3"), Scalar(1.1, 2.2, 3));
282+
EXPECT_EQ(parser.get<Scalar>("s4"), Scalar(-4.2, 1, 0, 3));
283+
EXPECT_EQ(parser.get<Scalar>("s5"), Scalar(5, -4, 3, 2));
284+
}
285+
264286
}} // namespace

modules/dnn/include/opencv2/dnn/all_layers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
153153
*/
154154

155155
int inputNameToIndex(String inputName);
156-
int outputNameToIndex(String outputName);
156+
int outputNameToIndex(const String& outputName);
157157
};
158158

159159
/** @brief Classical recurrent layer

modules/dnn/include/opencv2/dnn/dnn.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
222222
/** @brief Returns index of output blob in output array.
223223
* @see inputNameToIndex()
224224
*/
225-
CV_WRAP virtual int outputNameToIndex(String outputName);
225+
CV_WRAP virtual int outputNameToIndex(const String& outputName);
226226

227227
/**
228228
* @brief Ask layer if it support specific backend for doing computations.
@@ -704,7 +704,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
704704
* @ref readNetFromTorch or @ref readNetFromDarknet. An order of @p model and @p config
705705
* arguments does not matter.
706706
*/
707-
CV_EXPORTS_W Net readNet(String model, String config = "", String framework = "");
707+
CV_EXPORTS_W Net readNet(const String& model, const String& config = "", const String& framework = "");
708708

709709
/** @brief Loads blob which was serialized as torch.Tensor object of Torch7 framework.
710710
* @warning This function has the same limitations as readNetFromTorch().

modules/dnn/src/dnn.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ struct DataLayer : public Layer
398398
void forward(std::vector<Mat*>&, std::vector<Mat>&, std::vector<Mat> &) {}
399399
void forward(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals) {}
400400

401-
int outputNameToIndex(String tgtName)
401+
int outputNameToIndex(const String& tgtName)
402402
{
403403
int idx = (int)(std::find(outNames.begin(), outNames.end(), tgtName) - outNames.begin());
404404
return (idx < (int)outNames.size()) ? idx : -1;
@@ -2513,7 +2513,7 @@ int Layer::inputNameToIndex(String)
25132513
return -1;
25142514
}
25152515

2516-
int Layer::outputNameToIndex(String)
2516+
int Layer::outputNameToIndex(const String&)
25172517
{
25182518
return -1;
25192519
}
@@ -2805,9 +2805,11 @@ BackendWrapper::BackendWrapper(const Ptr<BackendWrapper>& base, const MatShape&
28052805

28062806
BackendWrapper::~BackendWrapper() {}
28072807

2808-
Net readNet(String model, String config, String framework)
2808+
Net readNet(const String& _model, const String& _config, const String& _framework)
28092809
{
2810-
framework = framework.toLowerCase();
2810+
String framework = _framework.toLowerCase();
2811+
String model = _model;
2812+
String config = _config;
28112813
const std::string modelExt = model.substr(model.rfind('.') + 1);
28122814
const std::string configExt = config.substr(config.rfind('.') + 1);
28132815
if (framework == "caffe" || modelExt == "caffemodel" || configExt == "caffemodel" ||

modules/dnn/src/layers/recurrent_layers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ int LSTMLayer::inputNameToIndex(String inputName)
355355
return -1;
356356
}
357357

358-
int LSTMLayer::outputNameToIndex(String outputName)
358+
int LSTMLayer::outputNameToIndex(const String& outputName)
359359
{
360360
if (outputName.toLowerCase() == "h")
361361
return 0;

0 commit comments

Comments
 (0)