opencv/modules/python
Vadim Levin 16b9514543 feat: update conversion logic for std::vector<T> in Python bindings
`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.
2021-09-01 13:00:21 +03:00
..
bindings cmake: fix files order in Python bindings 2021-04-01 09:48:50 +00:00
package python(loader): add workaround to detect and patch sys.path[0] 2021-06-09 09:51:07 +00:00
python2 python: support standalone Python bindings build 2018-06-07 15:16:39 +03:00
python3 Limited API support for Python3 2019-06-11 15:15:49 +03:00
src2 feat: update conversion logic for std::vector<T> in Python bindings 2021-09-01 13:00:21 +03:00
test feat: update conversion logic for std::vector<T> in Python bindings 2021-09-01 13:00:21 +03:00
CMakeLists.txt cmake: fix missing project() warning in Python standalone builds 2020-03-12 14:29:31 +03:00
common.cmake cmake: handle empty CVPY_SUFFIX 2021-08-19 20:06:41 +00:00
python_loader.cmake fixes #16500 2020-02-20 11:10:12 +08:00
standalone.cmake python: update CMake install rules 2019-03-15 13:11:00 +03:00