Convert grayscale to rgb c++
时间: 2023-09-19 13:11:41 浏览: 170
RGB2Gray.rar_grayscale_rgb to grayscale
To convert a grayscale image to an RGB image in C++, you can use the OpenCV library. Here is an example code snippet:
```c++
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
// Load the grayscale image
Mat gray_img = imread("grayscale_image.jpg", IMREAD_GRAYSCALE);
// Create a new RGB image
Mat rgb_img;
cvtColor(gray_img, rgb_img, COLOR_GRAY2RGB);
// Save the new RGB image
imwrite("rgb_image.jpg", rgb_img);
return 0;
}
```
In this example, we first load the grayscale image using the `imread()` function with the flag `IMREAD_GRAYSCALE`. Then, we create a new RGB image by converting the grayscale image to RGB using the `cvtColor()` function with the flag `COLOR_GRAY2RGB`. Finally, we save the new RGB image using the `imwrite()` function.
阅读全文