YUV轉(zhuǎn)為jpg圖像的實(shí)現(xiàn)
更新時(shí)間:2019年12月09日 15:31:25 作者:葉晚zd
今天小編就為大家分享一篇YUV轉(zhuǎn)為jpg圖像的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
調(diào)用opencv庫,將yuv圖像轉(zhuǎn)為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; }
以上這篇YUV轉(zhuǎn)為jpg圖像的實(shí)現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python實(shí)現(xiàn)IP代理批量采集的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Python實(shí)現(xiàn)IP代理批量采集,并檢測代理是否可用。文中的示例代碼講解詳細(xì),需要的可以參考一下2022-09-09Python實(shí)現(xiàn)SqlServer查詢結(jié)果并寫入多個Sheet頁的方法詳解
這篇文章主要為大家整理了兩個Python實(shí)現(xiàn)SqlServer查詢結(jié)果并寫入多個Sheet頁的方法,文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-12-12使用python將微信image下.dat文件解密為.png的方法
這篇文章主要介紹了使用python將微信image下.dat文件解密為.png的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11Python 利用Entrez庫篩選下載PubMed文獻(xiàn)摘要的示例
這篇文章主要介紹了Python 利用Entrez庫篩選下載PubMed文獻(xiàn)摘要的示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2020-11-11Django實(shí)現(xiàn)靜態(tài)文件緩存到云服務(wù)的操作方法
這篇文章主要介紹了Django實(shí)現(xiàn)靜態(tài)文件緩存到云服務(wù)的操作方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08