【问题标题】:Why does InputOutputArray take a const Mat& reference in the constructor?为什么 InputOutputArray 在构造函数中采用 const Mat& 引用?
【发布时间】:2018-07-13 09:33:33
【问题描述】:

InputOutputArray 的构造函数在构造函数中采用 const cv::Mat&,这意味着编译时不会出现任何警告或错误。

为什么 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);
}

【问题讨论】:

    标签: c++ opencv opencv3.3


    【解决方案1】:

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

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

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

    2. “...可能没有真正的解决方案(即使是c++17)”

    3. “诸如此类的问题在 C++ 中是众所周知的,并不是 OpenCV 独有的。”

    【讨论】:

    • 构造函数肯定存在——不知道为什么不设置为显式构造函数?
    • @rangerdanger 阅读答案的第二部分以获得解释:)
    猜你喜欢
    • 1970-01-01
    • 2015-05-17
    • 2012-06-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    相关资源
    最近更新 更多