Skip to content

(4.x) Merge 3.4#20642

Merged
alalek merged 14 commits intoopencv:masterfrom
alalek:merge-3.4
Sep 2, 2021
Merged

(4.x) Merge 3.4#20642
alalek merged 14 commits intoopencv:masterfrom
alalek:merge-3.4

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Sep 1, 2021

#20511 from wjj19950828:add_humanseg_support_0806
#20573 from rogday:onnx_scale_fix
#20618 from VadimLevin:dev/vlevin/fix-vector-conversion
#20622 from diablodale:fix20544-nodiscard
#20633 from alalek:ocl_dumpValue_handle_null
#20635 from alalek:issue_20559
#20646 from VadimLevin:dev/vlevin/fix-vector-conversion

Previous "Merge 3.4": #20626

Details
buildworker:Win64 OpenCL=windows-2
#buildworker:Custom=linux-1,linux-2,linux-4,linux-6
buildworker:Docs=linux-4,linux-6
build_image:Docs=docs-js:18.04
build_image:Custom=javascript
buildworker:Custom=linux-4,linux-6
Xbuild_image:Custom=javascript-simd
#build_image:Custom=powerpc64le
#build_image:Custom=ubuntu-openvino-2019r3.0:16.04
#build_image:Custom=ubuntu-openvino-2020.3.0:16.04
#build_image:Custom=ubuntu-openvino-2020.4.0:16.04
#build_image:Custom=ubuntu-openvino-2021.1.0:20.04
#build_image:Custom=ubuntu-openvino-2021.2.0:20.04
#build_image:Custom=ubuntu-openvino-2021.3.0:20.04
#build_image:Custom=ubuntu-openvino-2021.4.0:20.04
#buildworker:Custom=linux-1
#build_image:Custom=ubuntu-vulkan:16.04
#buildworker:Custom=linux-4
#build_image:Custom=fedora:28
#build_image:Custom=ubuntu-cuda:16.04
#build_image:Custom=ubuntu-clang:18.04
#build_image:Custom=ubuntu:20.04
#buildworker:Custom=linux-1
#build_image:Custom=javascript-simd
#build_image:Custom=mips64el
#build_image:Custom Mac=openvino-2019r3.0
#build_image:Custom Mac=openvino-2020.3.0
Xbuild_image:Custom Mac=openvino-2020.4.0
Xbuild_image:Custom Mac=openvino-2021.1.0
Xbuild_image:Custom Mac=openvino-2021.2.0
Xbuild_image:Custom Mac=openvino-2021.3.0
build_image:Custom Mac=openvino-2021.4.0
#build_image:Custom Win=openvino-2019r3.0
#build_image:Custom Win=openvino-2020.3.0
Xbuild_image:Custom Win=openvino-2020.4.0
Xbuild_image:Custom Win=openvino-2021.1.0
Xbuild_image:Custom Win=openvino-2021.2.0
Xbuild_image:Custom Win=openvino-2021.3.0
build_image:Custom Win=openvino-2021.4.0
test_bigdata:Custom Win=1
test_filter:Custom Win=*
test_modules=dnn,python2,python3,java
test_opencl:Custom Win=OFF
build_contrib:Custom Win=OFF
#build_image:Custom Win=msvs2017
#build_image:Custom Win=msvs2019
test_modules:Custom Mac=dnn,java,python3

rogday and others added 11 commits August 18, 2021 19:22
- includes workaround for preprocessor non-compliance
- enable attribute syntax checking in msvc
- NULL is used for allocation of workgroup local variables
- it is a hint and it should not block kernel execution
`PyObject*` to `std::vector<T>` conversion logic:
- If user passed Numpy Array
  - If array is planar and T is a primitive type (doesn't require
    constructor call) that matches with the element type of array, then
    copy element one by one with the respect of the step between array
    elements. If compiler is lucky (or brave enough) copy loop can be
    vectorized.
    For classes that require constructor calls this path is not
    possible, because we can't begin an object lifetime without hacks.
  - Otherwise fall-back to general case
- Otherwise - execute the general case:
  If PyObject* corresponds to Sequence protocol - iterate over the
  sequence elements and invoke the appropriate `pyopencv_to` function.

`std::vector<T>` to `PyObject*` conversion logic:
- If `std::vector<T>` is empty - return empty tuple.
- If `T` has a corresponding `Mat` `DataType` than return
  Numpy array instance of the matching `dtype` e.g.
  `std::vector<cv::Rect>` is returned as `np.ndarray` of shape `Nx4` and
  `dtype=int`.
  This branch helps to optimize further evaluations in user code.
- Otherwise - execute the general case:
  Construct a tuple of length N = `std::vector::size` and insert
  elements one by one.

Unnecessary functions were removed and code was rearranged to allow
compiler select the appropriate conversion function specialization.
…_0806

* support PPSeg model for dnn module

* fixed README for CI

* add test case

* fixed bug

* deal with comments

* rm dnn_model_runner

* update test case

* fixed bug for testcase

* update testcase
Copy link
Copy Markdown
Member Author

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @VadimLevin @diablodale Please take a look on this merge to OpenCV 4.x branch

arr0 = [(2, 2), 2.0]
arr1 = [3, 'str']
arr0 = ((2, 2), 2.0)
arr1 = (3, 'str')
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra change is necessary after #20618 (list -> tuple)

(or change self.assertEqual(arr0 + arr1, out) below)

/cc @VadimLevin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe: self.assertSequenceEqual(arr0 + arr1, out) would be better. Example:

        from itertools import chain
        a = [1, 2, [1, 2]]
        b = ['str', (2, 2)]
        res = tuple(chain(a, b))
        b[0] = 'a' # This modification is required to fail assertion below
        self.assertSequenceEqual(a + b, res)

reports

AssertionError: Sequences differ: [1, 2, [1, 2], 'a', (2, 2)] != (1, 2, [1, 2], 'str', (2, 2))

First differing element 3:
'a'
'str'

  • [1, 2, [1, 2], 'a', (2, 2)]
  • (1, 2, [1, 2], 'str', (2, 2))

static UMat diag(const UMat& d, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat diag(const UMat& d) { return diag(d, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
CV_NODISCARD_STD static UMat diag(const UMat& d, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
CV_NODISCARD_STD static UMat diag(const UMat& d) { return diag(d, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved CV_NODISCARD_STD conflicts from patch #20622

/cc @diablodale

BTW, why nodiscard flag is missing for methods above, like

UMat diag(int d=0) const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having CV_NODISCARD_STD on UMat diag(int d=0) was a style choice. diag is a member function, not a static factory. Static factories have the "feature" that they can be called using class::factory or var.factory which contributes to discarding errors.

There are hundreds/thousands of APIs in opencv that create an object and return it. Technically... nodiscard could be put on all of them. But that is overkill and not really the intention of [[nodiscard]]. For this first PR effort, I focused on the static factories that create new independent objects. There may be future opportunities on some constructors (like those that do locking), but that wasn't the focus on this first effort. For example, I could put nodicard on the UMat constructors, but it is harder to make a discarding error with UMat constructor...compared to a discarding error with UMat::zeros

The one exception was member functions clone(). Those were already marked and therefore I want to maintain the same functionality on them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block merge changes looks ok also

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git show <merge commit sha> can show conflicting changes:

Details
commit 5aa7435d2537e677611390b530e31b3b204773a3 (HEAD -> merge-3.4, github/test_contrib, github/merge-3.4)
Merge: c11195d5e3 7c23ec90a9
Author: Alexander Alekhin <alexander.a.alekhin@gmail.com>
Date:   Thu Sep 2 15:24:04 2021 +0000

    Merge remote-tracking branch 'upstream/3.4' into merge-3.4

diff --cc modules/core/include/opencv2/core/mat.hpp
index 6768be7683,fdcb8fc817..1ef0eb5a02
--- a/modules/core/include/opencv2/core/mat.hpp
+++ b/modules/core/include/opencv2/core/mat.hpp
@@@ -2451,11 -2469,10 +2451,11 @@@ public
      //!  <0 - a diagonal from the lower half)
      UMat diag(int d=0) const;
      //! constructs a square diagonal matrix which main diagonal is vector "d"
-     static UMat diag(const UMat& d, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat diag(const UMat& d) { return diag(d, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
 -    CV_NODISCARD_STD static UMat diag(const UMat& d);
++    CV_NODISCARD_STD static UMat diag(const UMat& d, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat diag(const UMat& d) { return diag(d, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
  
      //! returns deep copy of the matrix, i.e. the data is copied
-     UMat clone() const CV_NODISCARD;
+     CV_NODISCARD_STD UMat clone() const;
      //! copies the matrix content to "m".
      // It calls m.create(this->size(), this->type()).
      void copyTo( OutputArray m ) const;
@@@ -2486,22 -2503,14 +2486,22 @@@
      double dot(InputArray m) const;
  
      //! Matlab-style matrix initialization
-     static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat zeros(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat zeros(int rows, int cols, int type) { return zeros(rows, cols, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
-     static UMat zeros(Size size, int type) { return zeros(size, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
-     static UMat zeros(int ndims, const int* sz, int type) { return zeros(ndims, sz, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
-     static UMat ones(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat ones(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat ones(int rows, int cols, int type) { return ones(rows, cols, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
-     static UMat ones(Size size, int type) { return ones(size, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
-     static UMat ones(int ndims, const int* sz, int type) { return ones(ndims, sz, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
-     static UMat eye(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat eye(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
-     static UMat eye(int rows, int cols, int type) { return eye(rows, cols, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
-     static UMat eye(Size size, int type) { return eye(size, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
 -    CV_NODISCARD_STD static UMat zeros(int rows, int cols, int type);
 -    CV_NODISCARD_STD static UMat zeros(Size size, int type);
 -    CV_NODISCARD_STD static UMat zeros(int ndims, const int* sz, int type);
 -    CV_NODISCARD_STD static UMat ones(int rows, int cols, int type);
 -    CV_NODISCARD_STD static UMat ones(Size size, int type);
 -    CV_NODISCARD_STD static UMat ones(int ndims, const int* sz, int type);
 -    CV_NODISCARD_STD static UMat eye(int rows, int cols, int type);
 -    CV_NODISCARD_STD static UMat eye(Size size, int type);
++    CV_NODISCARD_STD static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat zeros(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat zeros(int rows, int cols, int type) { return zeros(rows, cols, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
++    CV_NODISCARD_STD static UMat zeros(Size size, int type) { return zeros(size, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
++    CV_NODISCARD_STD static UMat zeros(int ndims, const int* sz, int type) { return zeros(ndims, sz, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
++    CV_NODISCARD_STD static UMat ones(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat ones(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat ones(int rows, int cols, int type) { return ones(rows, cols, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
++    CV_NODISCARD_STD static UMat ones(Size size, int type) { return ones(size, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
++    CV_NODISCARD_STD static UMat ones(int ndims, const int* sz, int type) { return ones(ndims, sz, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
++    CV_NODISCARD_STD static UMat eye(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat eye(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
++    CV_NODISCARD_STD static UMat eye(int rows, int cols, int type) { return eye(rows, cols, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
++    CV_NODISCARD_STD static UMat eye(Size size, int type) { return eye(size, type, USAGE_DEFAULT); }  // OpenCV 5.0: remove abi compatibility overload
  
      //! allocates new matrix data unless the matrix already has specified size and type.
      // previous data is unreferenced if needed.
diff --cc modules/core/include/opencv2/core/matx.hpp
index 45d8a97f34,f25c8bce57..3c92e3a21d
--- a/modules/core/include/opencv2/core/matx.hpp
+++ b/modules/core/include/opencv2/core/matx.hpp
@@@ -140,13 -142,15 +140,13 @@@ public
           _Tp v12, _Tp v13, _Tp v14, _Tp v15); //!< 1x16, 4x4 or 16x1 matrix
      explicit Matx(const _Tp* vals); //!< initialize from a plain array
  
 -#ifdef CV_CXX11
      Matx(std::initializer_list<_Tp>); //!< initialize from an initializer list
 -#endif
  
-     static Matx all(_Tp alpha);
-     static Matx zeros();
-     static Matx ones();
-     static Matx eye();
-     static Matx diag(const diag_type& d);
+     CV_NODISCARD_STD static Matx all(_Tp alpha);
+     CV_NODISCARD_STD static Matx zeros();
+     CV_NODISCARD_STD static Matx ones();
+     CV_NODISCARD_STD static Matx eye();
+     CV_NODISCARD_STD static Matx diag(const diag_type& d);
      /** @brief Generates uniformly distributed random numbers
      @param a Range boundary.
      @param b The other range boundary (boundaries don't have to be ordered, the lower boundary is inclusive,
diff --cc modules/core/src/bindings_utils.cpp
...

@VadimLevin
Copy link
Copy Markdown
Contributor

@alalek Should #20646 be included to this merge too from the beginning?

static UMat eye(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat eye(int rows, int cols, int type) { return eye(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
static UMat eye(Size size, int type) { return eye(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
CV_NODISCARD_STD static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of merge changes looks ok. After merge, I will review/make PR on the 4.x codebase looking for static factories that are unique to 4.x.

@alalek
Copy link
Copy Markdown
Member Author

alalek commented Sep 2, 2021

👍

@alalek alalek merged commit 5aa7435 into opencv:master Sep 2, 2021
@alalek alalek mentioned this pull request Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants