for (size_t y = 0; y < image.rows; y++) {//row_ptr為第y行的頭指針,unsigned char* row_ptr = image.ptr<unsigned char>(y);for (size_t x = 0; x < image.cols; x++) {//data_ptr: 指向待訪問像素unsigned char* data_ptr = &row_ptr[x*image.channels];//獲取待訪問像素下每個通道的數值for (int c = 0; c < image.channels; c++) {//上面鎖定了行和列,階下來就是便利每一個通道上的數據。unsigned char data = data_ptr[c];}}
}