Skip to content

Commit 80492d6

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 172c539 + a079acc commit 80492d6

14 files changed

+1949
-121
lines changed

cmake/OpenCVCompilerDefenses.cmake

-8
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,3 @@ endif()
8787
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OPENCV_LINKER_DEFENSES_FLAGS_COMMON}" )
8888
set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${OPENCV_LINKER_DEFENSES_FLAGS_COMMON}" )
8989
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCV_LINKER_DEFENSES_FLAGS_COMMON}" )
90-
91-
if(CV_GCC OR CV_CLANG)
92-
foreach(flags
93-
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG
94-
CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG)
95-
string(REPLACE "-O3" "-O2" ${flags} "${${flags}}")
96-
endforeach()
97-
endif()

doc/opencv.bib

+8
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,14 @@ @inproceedings{forstner1987fast
13011301
pages={281--305},
13021302
year={1987}
13031303
}
1304+
@article{Bolelli2021,
1305+
title={One DAG to Rule Them All},
1306+
author={Bolelli, Federico and Allegretti, Stefano and Grana, Costantino},
1307+
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
1308+
year={2021},
1309+
publisher={IEEE},
1310+
doi = {10.1109/TPAMI.2021.3055337}
1311+
}
13041312
@inproceedings{liao2020real,
13051313
author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang},
13061314
title={Real-time Scene Text Detection with Differentiable Binarization},

modules/dnn/src/layers/flatten_layer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class FlattenLayerImpl CV_FINAL : public FlattenLayer
107107
{
108108
outputShapeVec.push_back(inputs[0][i]);
109109
}
110-
CV_Assert(outputShapeVec.size() <= 4);
111110

112111
outputs.resize(inputs.size(), outputShapeVec);
113112

modules/dnn/src/onnx/onnx_importer.cpp

+52-5
Original file line numberDiff line numberDiff line change
@@ -2023,20 +2023,67 @@ void ONNXImporter::parseSqueeze(LayerParams& layerParams, const opencv_onnx::Nod
20232023
addLayer(layerParams, node_proto);
20242024
}
20252025

2026-
void ONNXImporter::parseFlatten(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
2026+
void ONNXImporter::parseFlatten(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto_)
20272027
{
2028+
opencv_onnx::NodeProto node_proto = node_proto_;
20282029
CV_CheckEQ(node_proto.input_size(), 1, "");
2030+
int axis_ = layerParams.get<int>("axis", 1);
20292031
if (constBlobs.find(node_proto.input(0)) != constBlobs.end())
20302032
{
20312033
Mat input = getBlob(node_proto, 0);
2032-
int axis = normalize_axis(layerParams.get<int>("axis", 1), input.dims);
2034+
int axis = normalize_axis(axis_, input.dims);
20332035

2034-
std::vector<int> out_size(&input.size[0], &input.size[0] + axis);
2035-
out_size.push_back(input.total(axis));
2036-
Mat output = input.reshape(1, out_size);
2036+
int out_size[2] = {1, 1};
2037+
for (int i = 0; i < axis; ++i)
2038+
{
2039+
out_size[0] *= input.size[i];
2040+
}
2041+
for (int i = axis; i < input.dims; ++i)
2042+
{
2043+
out_size[1] *= input.size[i];
2044+
}
2045+
2046+
Mat output = input.reshape(1, 2, out_size);
20372047
addConstant(layerParams.name, output);
20382048
return;
20392049
}
2050+
IterShape_t shapeIt = outShapes.find(node_proto.input(0));
2051+
CV_Assert(shapeIt != outShapes.end());
2052+
MatShape inpShape = shapeIt->second;
2053+
int axis = normalize_axis(axis_, inpShape.size());
2054+
2055+
if (axis == 0 || axis == inpShape.size())
2056+
{
2057+
LayerParams reshapeLp;
2058+
reshapeLp.name = layerParams.name + "/reshape";
2059+
reshapeLp.type = "Reshape";
2060+
CV_Assert(layer_id.find(reshapeLp.name) == layer_id.end());
2061+
2062+
inpShape.insert(axis == 0 ? inpShape.begin() : inpShape.end(), 1);
2063+
reshapeLp.set("dim", DictValue::arrayInt(&inpShape[0], inpShape.size()));
2064+
2065+
opencv_onnx::NodeProto proto;
2066+
proto.add_input(node_proto.input(0));
2067+
proto.add_output(reshapeLp.name);
2068+
addLayer(reshapeLp, proto);
2069+
node_proto.set_input(0, reshapeLp.name);
2070+
axis += 1;
2071+
}
2072+
2073+
LayerParams first_pass;
2074+
first_pass.name = layerParams.name + "/flatten";
2075+
CV_Assert(layer_id.find(first_pass.name) == layer_id.end());
2076+
first_pass.type = "Flatten";
2077+
first_pass.set("axis", 0);
2078+
first_pass.set("end_axis", axis - 1);
2079+
2080+
opencv_onnx::NodeProto proto;
2081+
proto.add_input(node_proto.input(0));
2082+
proto.add_output(first_pass.name);
2083+
addLayer(first_pass, proto);
2084+
2085+
layerParams.set("axis", 1);
2086+
node_proto.set_input(0, first_pass.name);
20402087
addLayer(layerParams, node_proto);
20412088
}
20422089

modules/dnn/test/test_onnx_conformance_layer_filter__halide_denylist.inl.hpp

-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@
5353
"test_elu",
5454
"test_elu_default",
5555
"test_exp",
56-
"test_flatten_axis0",
57-
"test_flatten_axis2",
58-
"test_flatten_axis3",
59-
"test_flatten_negative_axis1",
60-
"test_flatten_negative_axis2",
61-
"test_flatten_negative_axis4",
6256
"test_floor",
6357
"test_leakyrelu",
6458
"test_leakyrelu_default",

modules/dnn/test/test_onnx_conformance_layer_filter__openvino.inl.hpp

+6-18
Original file line numberDiff line numberDiff line change
@@ -629,35 +629,23 @@ CASE(test_eyelike_with_dtype)
629629
CASE(test_eyelike_without_dtype)
630630
// no filter
631631
CASE(test_flatten_axis0)
632-
#if INF_ENGINE_VER_MAJOR_EQ(2021040000)
633-
SKIP;
634-
#endif
632+
// no filter
635633
CASE(test_flatten_axis1)
636634
// no filter
637635
CASE(test_flatten_axis2)
638-
#if INF_ENGINE_VER_MAJOR_EQ(2021040000)
639-
SKIP;
640-
#endif
636+
// no filter
641637
CASE(test_flatten_axis3)
642-
#if INF_ENGINE_VER_MAJOR_EQ(2021040000)
643-
SKIP;
644-
#endif
638+
// no filter
645639
CASE(test_flatten_default_axis)
646640
// no filter
647641
CASE(test_flatten_negative_axis1)
648-
#if INF_ENGINE_VER_MAJOR_EQ(2021040000)
649-
SKIP;
650-
#endif
642+
// no filter
651643
CASE(test_flatten_negative_axis2)
652-
#if INF_ENGINE_VER_MAJOR_EQ(2021040000)
653-
SKIP;
654-
#endif
644+
// no filter
655645
CASE(test_flatten_negative_axis3)
656646
// no filter
657647
CASE(test_flatten_negative_axis4)
658-
#if INF_ENGINE_VER_MAJOR_EQ(2021040000)
659-
SKIP;
660-
#endif
648+
// no filter
661649
CASE(test_floor)
662650
// no filter
663651
CASE(test_floor_example)

modules/dnn/test/test_onnx_conformance_layer_filter_opencv_all_denylist.inl.hpp

-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@
4343
"test_castlike_STRING_to_FLOAT_expanded",
4444
"test_concat_1d_axis_negative_1",
4545
"test_div_uint8", // output type mismatch
46-
"test_flatten_axis0",
47-
"test_flatten_axis2",
48-
"test_flatten_axis3",
49-
"test_flatten_negative_axis1",
50-
"test_flatten_negative_axis2",
51-
"test_flatten_negative_axis4",
5246
"test_logsoftmax_default_axis",
5347
"test_maxpool_2d_dilations",
5448
"test_maxpool_2d_same_lower",

modules/imgproc/include/opencv2/imgproc.hpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ enum ConnectedComponentsTypes {
405405

406406
//! connected components algorithm
407407
enum ConnectedComponentsAlgorithmsTypes {
408-
CCL_DEFAULT = -1, //!< BBDT @cite Grana2010 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both BBDT and SAUF.
408+
CCL_DEFAULT = -1, //!< Spaghetti @cite Bolelli2019 algorithm for 8-way connectivity, Spaghetti4C @cite Bolelli2021 algorithm for 4-way connectivity.
409409
CCL_WU = 0, //!< SAUF @cite Wu2009 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for SAUF.
410410
CCL_GRANA = 1, //!< BBDT @cite Grana2010 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both BBDT and SAUF.
411-
CCL_BOLELLI = 2, //!< Spaghetti @cite Bolelli2019 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity.
411+
CCL_BOLELLI = 2, //!< Spaghetti @cite Bolelli2019 algorithm for 8-way connectivity, Spaghetti4C @cite Bolelli2021 algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both Spaghetti and Spaghetti4C.
412412
CCL_SAUF = 3, //!< Same as CCL_WU. It is preferable to use the flag with the name of the algorithm (CCL_SAUF) rather than the one with the name of the first author (CCL_WU).
413413
CCL_BBDT = 4, //!< Same as CCL_GRANA. It is preferable to use the flag with the name of the algorithm (CCL_BBDT) rather than the one with the name of the first author (CCL_GRANA).
414414
CCL_SPAGHETTI = 5, //!< Same as CCL_BOLELLI. It is preferable to use the flag with the name of the algorithm (CCL_SPAGHETTI) rather than the one with the name of the first author (CCL_BOLELLI).
@@ -3858,9 +3858,10 @@ image with 4 or 8 way connectivity - returns N, the total number of labels [0, N
38583858
represents the background label. ltype specifies the output label image type, an important
38593859
consideration based on the total number of labels or alternatively the total number of pixels in
38603860
the source image. ccltype specifies the connected components labeling algorithm to use, currently
3861-
Grana (BBDT) and Wu's (SAUF) @cite Wu2009 algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes
3862-
for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.
3863-
This function uses parallel version of both Grana and Wu's algorithms if at least one allowed
3861+
Bolelli (Spaghetti) @cite Bolelli2019, Grana (BBDT) @cite Grana2010 and Wu's (SAUF) @cite Wu2009 algorithms
3862+
are supported, see the #ConnectedComponentsAlgorithmsTypes for details. Note that SAUF algorithm forces
3863+
a row major ordering of labels while Spaghetti and BBDT do not.
3864+
This function uses parallel version of the algorithms if at least one allowed
38643865
parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs.
38653866
38663867
@param image the 8-bit single-channel image to be labeled
@@ -3890,9 +3891,10 @@ image with 4 or 8 way connectivity - returns N, the total number of labels [0, N
38903891
represents the background label. ltype specifies the output label image type, an important
38913892
consideration based on the total number of labels or alternatively the total number of pixels in
38923893
the source image. ccltype specifies the connected components labeling algorithm to use, currently
3893-
Grana's (BBDT) and Wu's (SAUF) @cite Wu2009 algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes
3894-
for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.
3895-
This function uses parallel version of both Grana and Wu's algorithms (statistics included) if at least one allowed
3894+
Bolelli (Spaghetti) @cite Bolelli2019, Grana (BBDT) @cite Grana2010 and Wu's (SAUF) @cite Wu2009 algorithms
3895+
are supported, see the #ConnectedComponentsAlgorithmsTypes for details. Note that SAUF algorithm forces
3896+
a row major ordering of labels while Spaghetti and BBDT do not.
3897+
This function uses parallel version of the algorithms (statistics included) if at least one allowed
38963898
parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs.
38973899
38983900
@param image the 8-bit single-channel image to be labeled

modules/imgproc/src/color_lab.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -2979,9 +2979,9 @@ struct RGB2Luvfloat
29792979
for( ; i < n; i++, src += scn, dst += 3 )
29802980
{
29812981
float R = src[0], G = src[1], B = src[2];
2982-
R = std::min(std::max(R, 0.f), 1.f);
2983-
G = std::min(std::max(G, 0.f), 1.f);
2984-
B = std::min(std::max(B, 0.f), 1.f);
2982+
R = clip(R);
2983+
G = clip(G);
2984+
B = clip(B);
29852985
if( gammaTab )
29862986
{
29872987
R = splineInterpolate(R*gscale, gammaTab, GAMMA_TAB_SIZE);
@@ -3205,9 +3205,9 @@ struct Luv2RGBfloat
32053205
float G = X*C3 + Y*C4 + Z*C5;
32063206
float B = X*C6 + Y*C7 + Z*C8;
32073207

3208-
R = std::min(std::max(R, 0.f), 1.f);
3209-
G = std::min(std::max(G, 0.f), 1.f);
3210-
B = std::min(std::max(B, 0.f), 1.f);
3208+
R = clip(R);
3209+
G = clip(G);
3210+
B = clip(B);
32113211

32123212
if( gammaTab )
32133213
{

0 commit comments

Comments
 (0)