Ask Your Question
0

How to create and read image using open CV

asked 2014-01-10 19:35:36 -0600

updated 2014-01-11 04:18:14 -0600

berak gravatar image

How to create an 400 X 400 image using C/C++ and write RGB vlues to each pixel and save it and also how to read the saved image by pixel to pixel ? Any help would be appreciated

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-01-11 04:01:09 -0600

tenta4 gravatar image

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);

edit flag offensive delete link more

Comments

How can we loop in through to read each pixel by its RGB value and same way to write each RGB pixel ?

nooby2252 gravatar imagenooby2252 ( 2014-01-11 18:09:02 -0600 )edit

It's seems you beginner in programming, if you can't to implement a loop like for x {for y}

tenta4 gravatar imagetenta4 ( 2014-01-13 05:50:11 -0600 )edit

Question Tools

Stats

Asked: 2014-01-10 19:35:36 -0600

Seen: 281 times

Last updated: Jan 11 '14