Conversation
- 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
alalek
left a comment
There was a problem hiding this comment.
/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') |
There was a problem hiding this comment.
This extra change is necessary after #20618 (list -> tuple)
(or change self.assertEqual(arr0 + arr1, out) below)
/cc @VadimLevin
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
this block merge changes looks ok also
There was a problem hiding this comment.
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
...| 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*/); |
There was a problem hiding this comment.
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.
|
👍 |
#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