코드 3-10 행렬의 원소 값 참조 방법을 이용하여 원소 값 증가시키기 [ch03/MatOp]
01 void MatOp4() 02 { 03 Mat mat1 = Mat::zeros(3, 4, CV_8UC1); 04 05 for (int j = 0; j < mat1.rows; j++) { 06 for (int i = 0; i < mat1.cols; i++) { 07 mat1.at<uchar>(j, i)++; 08 } 09 } 10 11 for (int j = 0; j < mat1.rows; j++) { 12 uchar* p = mat1.ptr<uchar>(j); 13 for (int i = 0; i < mat1.cols; i++) { 14 p[i]++; 15 } 16 } 17 18 for (MatIterator_<uchar> it = mat1.begin<uchar>(); it != mat1.end<uchar>(); ++it) { 19 (*it)++; 20 } 21 22 cout << "mat1:\n" << mat1 << endl; 23 }