#include "stdafx.h" #include <iostream> #include "Lvector.h" #include <vector> #include <stdio.h> #include <assert.h> #include "cv.h" #include "highgui.h" // #include <afx.h> using namespace std; //YV12 : 亮度(行×列) + U(行×列/4) + V(行×列/4) int main() { FILE *fp = fopen("aa.yv12","rb"); unsigned char * pBuffer = new unsigned char [704*576]; int len = 0; int i = 0; IplImage *pIplImage=cvCreateImage(cvSize(704,576),IPL_DEPTH_8U,1); //创建但通道的位深为8位的IplImage格式的图象 while (true) { len = fread(pBuffer,1,704*576,fp);//读取一桢Y分量的大小 if(pIplImage) { i++; memcpy(pIplImage->imageData,pBuffer,704*576);//pYData,nYSize char path[128] = {0}; sprintf(path,"%d_.jpg",i); cvSaveImage(path,pIplImage); } if (len == 0) { break; } fread(pBuffer,1,704*576/4,fp);//读取一桢U分量的大小,加这两句,就是为了把U、V分量去掉 fread(pBuffer,1,704*576/4,fp);//读取一桢V分量的大小 } cvReleaseImage(&pIplImage); fclose(fp); }
函数原型
memcpy
函数原型