赞
踩
#include <opencv2/opencv.hpp> #include<opencv2/imgproc/imgproc.hpp> #include<iostream> using namespace std; using namespace cv; int main() { Mat Image; Mat yuvImg; Mat test_yuv; Image = imread("D:\\Profile\\Desktop\\1.jpg"); //原图 resize(Image, test_yuv, Size(656, 976)); int w = test_yuv.cols; int h = test_yuv.rows; int buflen = w * h ; unsigned char* yuvbuf = new unsigned char[buflen]; FILE* pfile=fopen("img.yuv", "wb");; cvtColor(test_yuv, yuvImg, COLOR_RGB2YUV_IYUV); imshow("yuv", yuvImg); //waitKey(); memcpy(yuvbuf, yuvImg.data, buflen * sizeof(unsigned char)); fwrite(yuvbuf, buflen * sizeof(unsigned char), 1, pfile); fclose(pfile); }
生成的文件 可以用yuvplayer 查看是否正确
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。