为什么 InputOutputArray 在构造函数中采用 const Mat& 引用?

Why does InputOutputArray take a const Mat& reference in the constructor?

本文关键字:Mat const 引用 InputOutputArray 构造函数 为什么      更新时间:2023-10-16

InputOutputArray 的构造函数采用 const cv::Mat&in 构造函数,这意味着编译时没有任何警告或错误。

为什么 InputOutputArray 采用 const Mat 引用。我理解为什么 InputArray 采用 const 引用,但 OutputArray 真的不应该

void this_shouldnt_compile(const cv::Mat& mat) { 
    // const, so the header should not be modifiable
    // but the data is
    putText(mat, "some text", cvPoint(0,10), 
               FONT_HERSHEY_COMPLEX_SMALL, 0.8, 
               cvScalar({0,255,0}), 1, CV_AA);
}

所以cv::_InputOutputArray::_InputOutputArray (const Mat & m)的构造函数确实存在

通过查看 https://github.com/opencv/opencv/issues/7298 似乎

  1. 对基础数据的"访问锁"在编译时和运行时都不可用。控制这一点是开发人员的责任">

  2. "...可能没有真正的解决方案(即使使用 C++17(">

  3. "像这样的问题在C++是众所周知的,并不是OpenCV独有的。