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图像
0
投稿
猜你喜欢
Sql Server 和 Access 操作数据库结构Sql语句小结
2024-01-28 14:13:39
Go逃逸分析示例详解
2024-04-25 15:05:22
Java使用jdbc连接实现对MySQL增删改查操作的全过程
2024-01-27 05:07:51
Go 中 time.After 可能导致的内存泄露问题解析
2024-02-03 13:05:16
解决windows下python3使用multiprocessing.Pool出现的问题
2021-11-03 23:34:37
Python-copy()与deepcopy()区别详解
2021-06-20 15:00:41
python2 对excel表格操作完整示例
2022-08-27 00:35:06
Python命令行click参数用法解析
2023-07-30 14:01:20
一篇文章带你了解kali局域网攻击
2022-02-21 23:53:35
django的分页器Paginator 从django中导入类
2022-02-07 04:24:29
如何在ASP中使用SQL存储过程
2008-02-26 12:09:00
很有意思的SQL多行数据拼接
2024-01-28 02:08:56
mac下如何将python2.7改为python3
2023-12-07 17:14:43
用python爬取历史天气数据的方法示例
2022-10-30 21:28:42
Python如何获取多线程返回结果
2024-01-01 23:34:28
Python实现简单的可逆加密程序实例
2022-12-18 10:39:56
基于sqlserver的四种分页方式总结
2024-01-13 22:34:33
简单的Python动态可视化神器,编程小白也能上手
2021-05-28 09:59:27
mysql+Spring数据库隔离级别与性能分析
2024-01-15 00:46:58
OpenCV imread读取图片失败的问题及解决
2021-10-20 06:44:00