opencv的MAT赋值方法

C++ Mat矩阵赋值方法,如下:

错误赋值方法:

Mat mat_=Mat::zeros(Size(width,height),CV_8UC1);
for(int i=0;i<height;i++)
    for(int j=0;j<width;j++)
    {
        mat_<uchar>(i,j)=value;
    }

 正确赋值方法:

Mat mat_=Mat::zeros(Size(width,height),CV_8UC1);
for(int i=0;i<height;i++)
    for(int j=0;j<width;j++)
    {
        mat_<uchar>(i,j)=value;
    }

三通道正确赋值方法:

mat_.at<Vec3b>(i,j)[0]=value;
mat_.at<Vec3b>(i,j)[1]=value;
mat_.at<Vec3b>(i,j)[2]=value;

 

 以上方法均来自原文:https://blog.csdn.net/Hello_Wendy/article/details/68486955

 

posted @ 2023-06-30 11:40  tangjunjun  阅读(108)  评论(0编辑  收藏  举报
https://rpc.cnblogs.com/metaweblog/tangjunjun