Mat M;
M.creat(4,4,CV_8UC1); //创建矩阵
cout<<"M = "<<endl<<" "<<M<<endl<<endl;
M.ptr<uchar>(0)[0]=12,M.ptr<uchar>(0)[1]=32; //修改其中数据
cout<<"M = "<<endl<<" "<<M<<endl<<endl;
M.creat(4,4,CV_8UC1);
cout<<"M = "<<endl<<" "<<M<<endl<<endl;
M.creat(3,3,CV_8UC1);
cout<<"M = "<<endl<<" "<<M<<endl<<endl;
M.creat(5,5,CV_8UC1);
cout<<"M = "<<endl<<" "<<M<<endl<<endl;
使用creat函数,无法初始化,如果新的需求大于原来的内存,它才会重新分配内存区域。如下所示。