Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::Mat img(400, 400, CV_8UC3);

// fill by white

img = cv::Scalar(255, 255, 255);

// change the pixel

int x = 50; int y = 100;

img.data[(y * img.size().width + x) * 3] = 0; // r

img.data[(y * img.size().width + x) * 3+1] = 0; //g

img.data[(y * img.size().width + x) * 3+2] = 0; //b

// write

cv::imwrite("myimg.png", img);

// open

cv::Mat opened = cv::imread("myimg.png");

cv::imshow("opened", opened);

cv::waitKey(0);