c++ open cv 中YUV422怎么转raw
时间: 2023-07-16 15:16:58 浏览: 122
将YUV422图像转换为原始(RAW)图像需要进行以下步骤:
1. 对于每个像素,从YUV422中提取Y值。
2. 对于每两个像素,从YUV422中提取U和V值。
3. 将U和V值插入到相邻的像素中,得到RGB值。
4. 将RGB值写入原始图像。
下面是一个示例代码:
```
// 读取YUV422图像
cv::Mat yuv422_image = cv::imread("input.yuv", cv::IMREAD_UNCHANGED);
// 创建原始图像
cv::Mat raw_image(yuv422_image.rows, yuv422_image.cols, CV_8UC3);
// 将YUV422转换为原始图像
for (int i = 0; i < yuv422_image.rows; i++) {
for (int j = 0; j < yuv422_image.cols; j += 2) {
// 提取Y值
uint8_t y1 = yuv422_image.at<uint8_t>(i, j);
uint8_t y2 = yuv422_image.at<uint8_t>(i, j + 1);
// 提取U和V值
uint8_t u = yuv422_image.at<uint8_t>(i, j + 1);
uint8_t v = yuv422_image.at<uint8_t>(i, j + 3);
// 计算RGB值
int r1 = y1 + 1.13983 * (v - 128);
int g1 = y1 - 0.39465 * (u - 128) - 0.58060 * (v - 128);
int b1 = y1 + 2.03211 * (u - 128);
int r2 = y2 + 1.13983 * (v - 128);
int g2 = y2 - 0.39465 * (u - 128) - 0.58060 * (v - 128);
int b2 = y2 + 2.03211 * (u - 128);
// 写入原始图像
raw_image.at<cv::Vec3b>(i, j)[0] = r1;
raw_image.at<cv::Vec3b>(i, j)[1] = g1;
raw_image.at<cv::Vec3b>(i, j)[2] = b1;
raw_image.at<cv::Vec3b>(i, j + 1)[0] = r2;
raw_image.at<cv::Vec3b>(i, j + 1)[1] = g2;
raw_image.at<cv::Vec3b>(i, j + 1)[2] = b2;
}
}
// 保存原始图像
cv::imwrite("output.raw", raw_image);
```
阅读全文