Olarik Surinta
Olarik Surinta

Reputation: 119

c OpenCV; How to convert 2-dimension array to IplImage?

I'm using the c-api and am new to OpenCV.

Assume I have 2-dimension array including; red[][], green[][], blue[][]. I would like to convert 3 of 2-d array to IplImage and save it to .png file. However, from my system I cannot use CvMat.

Could you help me solve this problem.

Thanks.

Upvotes: 0

Views: 966

Answers (1)

marol
marol

Reputation: 4074

If you're using C++, use C++ API:

cv::Mat image = cv::Mat::zeros(w,h, CV_8UC3);
for(int x=0;x<w;x++)
   for(int y=0;y<h;y++)
        image.at<cv::Vec3b>(y,x) = cv::Vec3b(red[x][y], blue[x][y], green[x][y]);
cv::imwrite("image.png", image);

But if you really want to have c-api, conversion from cv::Mat to IplImage works:

IplImage *frameConverted = new IplImage(image);

Remember about releasing memory if you don't need frameConverted anymore.

Upvotes: 2

Related Questions