This program shows how to scan image obiects in OpenCV(CV::Mat).
we take an inout image and divide the native color palette(255) with the input. Show C operator[] method, itertors and at function for on-the-fly item address calculation.
The example as follows:
int main()
{
help();
Mat img=imread("lena.jpg");
if(img.empty())
{
cout<<"There is no picture."<<endl;
return -1;
}
int nRows=img.rows;
int nCols=img.cols*img.channels();
int i,j;
uchar* p;
int N=100;
for(i=0;i<nRows;i++)
{
uchar* p=img.ptr<uchar>(i);
for(j=0;j<nCols;j++)
{
p[j]=p[j]/N*N;
}
}
namedWindow("image",1);
imshow("image",img);
waitKey();
return 0;
}
需要理解圖像怎麼存儲的,再去理解怎麼scan的。
run: