简体   繁体   中英

OpenCV how to imwrite a RGB image

How do I write a RGB image with the function cv::imwrite() ? So far all my attempts lead into writing a BGR image instead.

My matrix object is a cv::Mat .

The cv::imwrite() function correctly writes an image file if the input cv::Mat is in BGR order (which is the case if you let OpenCV create it). If you created the image by yourself, you have to convert the color ordering before, for example by calling as suggested by bamboove cv::cvtColor(in, out, CV_RGB2BGR); if you created an RGB image.

(Pay attention to the color conversion code, it's slightly different from bamboon's.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM