尝试设置cv :: Mat的像素值时抛出分段错误

时间:2014-10-05 07:08:14

标签: c++ opencv

我的代码:

int main()
{
    cv::Mat origin = cv::imread("../resources/Slide2.JPG");

    for(int c = 0; c != origin.cols; ++c)
        for(int r = 0; r != origin.rows; ++r)
            origin.at<cv::Vec3b>(c,r) = {3,3,3};

    cv::imshow("test",origin);
    cv::waitKey();

    return 0;
}

The image file

调试时,它被Mat::release() mat.hpp中的inline void Mat::release() { if( refcount && CV_XADD(refcount, -1) == 1 ) deallocate(); data = datastart = dataend = datalimit = 0; size.p[0] = 0; refcount = 0; } 停留:

{{1}}

这里发生了什么?如何解决?

1 个答案:

答案 0 :(得分:1)

您必须在r来电中切换c.at()

origin.at<cv::Vec3b>(r, c) = {3,3,3};