一些奇怪的原因,要处理yuv格式的数据,代码在下面,自己看注释吧。
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include "opencv2/imgproc/types_c.h"
using namespace cv;
using namespace std;
void read_from_yuv2rgb_mat() {
// 从test.yuv读取,得到rgb格式mat图像
std::string yuvpath = "test.yuv";
FILE* fp = NULL;
errno_t ret = fopen_s(&fp, yuvpath.c_str(), "rb");
if (ret)
{
printf("file does not exist\n");
}
int w = 1920; //你得知道图片的长宽高
int h = 1080;
int imageLength = h * w * 3 / 2;
cv::Mat img_yuv = cv::Mat(h * 3 / 2, w, CV_8UC1);
fread(img_yuv.data, sizeof(unsigned char), h * w, fp);
fread(img_yuv.data + h * w, sizeof(unsigned char), h * w / 4, fp);
fread(img_yuv.data + h * w