資源簡介
在YUV420中,一個像素點對應一個Y,一個2X2的小方塊對應一個U和V。對于所有YUV420圖像,它們的Y值排列是完全相同的,因為只有Y的圖像就是灰度圖像。這個代碼可以從YUV視頻中提取每一幀畫面保存成圖片。

代碼片段和文件信息
//?testDemo.cpp?:?定義控制臺應用程序的入口點。
//
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?“yuv.h“
using?namespace?std;
int?main()
{
const?int?YUV_WIDTH=832;
const?int?YUV_HEIGTH?=?480;
string?strVideoName?=?“E:/test/BasketballDrill_832x480_50.yuv“;
string?strTxtName?=?“E:/test/BasketballDrill_832x480_50.txt“;
//?cv::VideoCapture?myVideoReader(strVideoName.c_str());
struct?YUV_Capture?myYUVReader;
????enum?YUV_ReturnValue?tmpRet;
FILE?*inYUVFile?=?fopen(strVideoName.c_str()?“rb“);
ifstream?myTxtReader(strTxtName.c_str());
assert(myTxtReader.is_open());
//?open?YUV?file
tmpRet?=?YUV_init(inYUVFile?YUV_WIDTH?YUV_HEIGTH?&myYUVReader);
assert(tmpRet?==?YUV_OK);
string?strBuf;
int?iVideoIdx?=?-1;
while(!myTxtReader.eof()){
vector?tmpLst(6?0);
for(int?iCur=0;?iCur<6;?iCur++){
myTxtReader?>>?tmpLst[iCur];
myTxtReader?>>?strBuf;?//?for?the?commm
}
IplImage?*bgr?=?cvCreateImage(cvSize(YUV_WIDTH?YUV_HEIGTH)?IPL_DEPTH_8U?3);
if(tmpLst[0]?!=?iVideoIdx){
tmpRet?=?YUV_read(&myYUVReader);
assert(tmpRet?==?YUV_OK);
cvCvtColor(myYUVReader.ycrcb?bgr?CV_YCrCb2BGR);
//?move?to?the?next?frame
iVideoIdx?++;
}
//?hold?the?image?frame
cv::Mat?inData(bgr);
//?get?the?rectangluar
cv::Rect?tmpCU?=?cv::Rect(cv::Point(tmpLst[1]?tmpLst[2])?cv::Size(tmpLst[3]?tmpLst[3]));
cv::Mat?subMat?=?inData(tmpCU).clone();
//?save?the?CU?image
cv::imwrite(“E:/test/1.jpg“?subMat);
//?testing?work
cv::imshow(“test“?subMat);
cv::waitKey(0);
}
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????95744??2016-08-18?17:04??testDemo\Debug\testDemo.exe
?????文件????????406??2016-08-18?16:29??testDemo\Debug\testDemo.exe.manifest
?????文件?????682120??2016-08-18?17:04??testDemo\Debug\testDemo.ilk
?????文件????1649664??2016-08-18?17:04??testDemo\Debug\testDemo.pdb
?????文件???????1254??2016-08-18?17:04??testDemo\testDemo\Debug\cl.command.1.tlog
?????文件??????36142??2016-08-18?17:04??testDemo\testDemo\Debug\CL.read.1.tlog
?????文件????????888??2016-08-18?17:04??testDemo\testDemo\Debug\CL.write.1.tlog
?????文件??????????2??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件??????????2??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件??????????2??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件??????????2??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件??????????2??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件??????????2??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件???????2808??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件???????3106??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件????????630??2016-08-18?17:04??testDemo\testDemo\Debug\li
?????文件????????414??2016-08-18?17:04??testDemo\testDemo\Debug\mt.command.1.tlog
?????文件????????264??2016-08-18?17:04??testDemo\testDemo\Debug\mt.read.1.tlog
?????文件????????264??2016-08-18?17:04??testDemo\testDemo\Debug\mt.write.1.tlog
?????文件????????762??2016-08-18?16:29??testDemo\testDemo\Debug\testDemo.Build.CppClean.log
?????文件????????381??2016-08-18?17:04??testDemo\testDemo\Debug\testDemo.exe.intermediate.manifest
?????文件?????????58??2016-08-18?17:04??testDemo\testDemo\Debug\testDemo.lastbuildstate
?????文件???????2022??2016-08-18?17:04??testDemo\testDemo\Debug\testDemo.log
?????文件?????305838??2016-08-18?17:04??testDemo\testDemo\Debug\testDemo.obj
?????文件????????707??2016-08-18?16:50??testDemo\testDemo\Debug\testDemo.vcxprojResolveAssemblyReference.cache
?????文件??????????0??2016-08-18?16:29??testDemo\testDemo\Debug\testDemo.write.1.tlog
?????文件?????642048??2016-08-18?17:04??testDemo\testDemo\Debug\vc100.idb
?????文件?????937984??2016-08-18?17:04??testDemo\testDemo\Debug\vc100.pdb
?????文件??????91644??2016-08-18?16:51??testDemo\testDemo\Debug\yuv.obj
?????文件???????1766??2016-08-18?17:04??testDemo\testDemo\testDemo.cpp
............此處省略17個文件信息
評論
共有 條評論