Skip to content

Semantic conflicts in cv::InputArray for std::array, float[] and std::vector #10614

@csukuangfj

Description

@csukuangfj
System information (version)
  • OpenCV => master
Detailed description

While converting

  • std::array<float, N>
  • std::vector<float>
  • float[]
    to cv::InputArray,
    std::array is treated as a column vector, see here
template<typename _Tp, std::size_t _Nm> inline
_InputArray::_InputArray(const std::array<_Tp, _Nm>& arr)
{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); }

Size(1,_Nm): 1 column, _Nm rows,
while float[] and std::vector<float> are treated as row vectors,
see here

template<typename _Tp> inline
_InputArray::_InputArray(const _Tp* vec, int n)
{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, vec, Size(n, 1)); }

Size(n,1): n columns, 1 row,
and here

return szb == szi ? Size((int)szb, 1) : Size((int)(szb/CV_ELEM_SIZE(flags)), 1);

Furthermore, when a std::vector<float> is used to
initialize a cv::Mat, it is considered as a column vector,
see here

template<typename _Tp> inline
Mat::Mat(const std::vector<_Tp>& vec, bool copyData)
    : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
      cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)

which confilcts with cv::InputArray::getMat, since it returns a row vector
when initialized with std::vector<float>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCcategory: corefutureThis issue can't be fixed during restrictions of the compatibility requirements

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions