YUV转为jpg图像的实现
作者:叶晚zd 时间:2021-07-26 09:18:29
调用opencv库,将yuv图像转为jpg图像。
代码如下:
# define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <iostream>
#include <fstream>
#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
int iWidth;
int iHeight;
int iFrameNum;
int iImageSize;
iWidth = 640;
iHeight = 480;
char *inputFileName = "640x480_YUV400.yuv";
FILE *fpIn;
if (fopen_s(&fpIn, inputFileName, "rb"))
{
cout << "File Open Failed!\n";
system("pause");
exit(1);
}
iImageSize = iWidth * iHeight;
unsigned char *InData = (unsigned char*)malloc(iImageSize * sizeof(unsigned char));
unsigned char *uvData = (unsigned char*)malloc(iImageSize / 2 * sizeof(unsigned char));//uv
memset(uvData, 128, iImageSize / 2);
Mat frameYUV(iHeight * 3 / 2, iWidth, CV_8UC1);
Mat frameBGR;
Mat frameRGB;
Mat frameYUV420;
char outName[128];
iFrameNum = 0;
while (1)
{
size_t size = fread(InData, sizeof(unsigned char), iImageSize, fpIn);
if (size == 0)
{
cout << "Read Frame Fail!\n";
system("pause");
break;
}
memcpy(frameYUV.data, InData, iImageSize);
memcpy(frameYUV.data + iImageSize, uvData, iImageSize / 2);
cvtColor(frameYUV, frameBGR, CV_YUV2BGR_I420);
cvtColor(frameBGR, frameRGB, CV_BGR2RGB);
imshow("video", frameRGB);
waitKey(1);
cout << iFrameNum++ << " Frame Processed\n";
sprintf(outName, "outFile/%d.jpg", iFrameNum);
imwrite(outName, frameRGB);
}
free(InData);
free(uvData);
fclose(fpIn);
return 0;
}
来源:https://blog.csdn.net/u013925378/article/details/82153377
标签:YUV,jpg图像
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python获取指定时间段内特定规律的日期列表
2021-02-09 02:16:25
![](https://img.aspxhome.com/file/2023/0/76930_0s.png)
ASP中Cookies集合使用方法详解
2007-09-14 10:16:00
Python调用百度OCR实现图片文字识别的示例代码
2021-04-07 14:21:50
![](https://img.aspxhome.com/file/2023/2/90502_0s.jpg)
利用python实现逐步回归
2023-10-05 19:24:27
![](https://img.aspxhome.com/file/2023/4/80584_0s.jpg)
Sql Server在安装时提示挂起的解决方法
2009-01-13 13:55:00
![](https://img.aspxhome.com/file/UploadPic/20091/200911419322531.jpg)
Python json读写方式和字典相互转化
2021-03-25 05:28:19
![](https://img.aspxhome.com/file/2023/0/85310_0s.png)
python matplotlib绘图,修改坐标轴刻度为文字的实例
2023-09-29 12:27:57
![](https://img.aspxhome.com/file/2023/7/62897_0s.jpg)
shtml网页SSI使用详解
2008-02-20 19:13:00
对python插入数据库和生成插入sql的示例讲解
2022-03-10 05:46:40
.NET反向代理组件YARP介绍
2023-07-23 02:29:45
![](https://img.aspxhome.com/file/2023/8/78088_0s.png)
Python基于回溯法子集树模板解决0-1背包问题实例
2021-02-02 08:57:54
![](https://img.aspxhome.com/file/2023/2/68482_0s.jpg)
tensorflow实现训练变量checkpoint的保存与读取
2023-12-15 18:10:33
![](https://img.aspxhome.com/file/2023/3/77003_0s.jpg)
python条件语句和while循环语句
2023-08-31 06:17:56
![](https://img.aspxhome.com/file/2023/1/62581_0s.png)
Python办公自动化之Excel(中)
2023-03-07 05:48:15
python怎么判断素数
2021-09-30 11:10:33
如何使用Python 打印各种三角形
2023-10-27 00:12:48
一个奇怪的CSS现象
2010-02-10 12:28:00
![](https://img.aspxhome.com/file/UploadPic/20102/10/y200921122655-79s.jpg)
HTML5拿什么取代Flash?
2010-05-10 20:37:00
轻松了解数据库计算机的概念和发展方向
2009-01-23 13:55:00
ASP实现文件直接下载的代码
2011-04-11 10:56:00