1. 下标Mat.at(i,j)
int getpixel1(Mat img) {
if (img.empty())
return -1;
for (int i = 0; i < img.rows; i++) {
for (int j = 0; j < img.cols; j++) {
img.at<Vec3b>(i, j)[0] = 255;
img.at<Vec3b>(i, j)[1] = 255;
img.at<Vec3b>(i, j)[2] = 255;
}
}
return 1;
}
2.指针遍历Mat::ptr
int getpixel2(Mat img) {
if (img.empty())
return -1;
// 将3通道转换为1通道
int nl = img.cols*img.channels();
for (int i = 0; i < img.rows; i++) {
uchar* p_rtr = img.ptr<uchar>(i);
for (int j = 0; j < nl; i++) {
p_rtr[j] = p_rtr[j]+1;
}
}
}