1

The constructor for an InputOutputArray takes a const cv::Mat&in the constructor, meaning this compiles without any warnings or errors.

Why does the InputOutputArray take a const Mat reference. I understand why the InputArray takes a const reference, but an OutputArray really should not

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);
}
4

1 回答 1

0

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

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

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

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

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

于 2018-02-02T20:32:50.023 回答