像素值读写
int main() {
Mat m(400, 400, CV_8U, Scalar(0));
for (int col = 0; col < 400; col++)
{
for (int row = 195; row < 205; row++) {
cout <<(int)( *(m.data + m.step[0] * row + m.step[1] * col) )<< "==>";
*(m.data + m.step[0] * row + m.step[1] * col) = 255;
cout << (int)(*(m.data + m.step[0] * row + m.step[1] * col)) << endl;
}
}
imshow("test1", m);
cvWaitKey();
return 0;
}
int main() {
Mat m = imread("C://Users//ely//Desktop//lena.jpg");
int *p_address;
Vec3i color;
for (int col = 20; col < 40; col++)
{
for (int row = 2; row < 20; row++)
{
color[0] = (int)(*(m.data + m.step[0] * row + m.step[1] * col));
color[0] = (int)(*(m.data + m.step[0] * row + m.step[1] * col+m.elemSize()));
color[0] = (int)(*(m.data + m.step[0] * row + m.step[1] * col + m.elemSize()*2));
cout << color[0] << "," << color[1] << "," << color[2] << "==>";
color[0] = 255;
color[1] = 0;
color[2] = 0;
*(m.data + m.step[0] * row + m.step[1] * col) = color[0];
*(m.data + m.step[0] * row + m.step[1] * col + m.elemSize()) = color[1];
*(m.data + m.step[0] * row + m.step[1] * col + m.elemSize() * 2) = color[2];
cout << (int)(*(m.data + m.step[0] * row + m.step[1] * col)) <<
(int)*(m.data + m.step[0] * row + m.step[1] * col + 1) <<
(int)*(m.data + m.step[0] * row + m.step[1] * col + 2) << endl;
}
}
imshow("canvas", m);
cvWaitKey();
return 0;
}