-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRuyi-convert-jpg2yuv.cpp
53 lines (44 loc) · 1.4 KB
/
Ruyi-convert-jpg2yuv.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv2/imgproc/imgproc_c.h>
using namespace cv;
int main(int argv, char **argc)
{
IplImage *pstImage = NULL;
IplImage *pstYUVImage = NULL;
FILE *fp = NULL;
pstImage = cvLoadImage("C://Users/Administrator/Desktop/abc/FaceNew/5.jpg", CV_LOAD_IMAGE_COLOR);
fp = fopen("C://Users/Administrator/Desktop/abc/FaceNew/5.yuv", "wb");
pstYUVImage = cvCreateImage(cvSize(pstImage->width, pstImage->height), IPL_DEPTH_8U, 3);
cvCvtColor(pstImage, pstYUVImage, CV_BGR2YUV);
for (int i = 0; i < pstImage->width * pstImage->height; i++)
{
//提取Y分量
fwrite(&pstYUVImage->imageData[i * 3], 1, 1, fp);
//提取U分量
//fwrite(&pstYUVImage->imageData[i*3+2], 1 , 1, fp);
//提取V分量
//fwrite(&pstYUVImage->imageData[i*3+1], 1 , 1, fp);
}
for (int i = 0; i < pstImage->height; i = i + 2)
{
for (int j = 0; j < pstImage->width; j = j + 2)
{
//提取U分量
fwrite(&pstYUVImage->imageData[3 * (i*pstImage->width + j) + 2], 1, 1, fp);
}
}
for (int i = 0; i < pstImage->height; i = i + 2)
{
for (int j = 0; j < pstImage->width; j = j + 2)
{
//提取V分量
fwrite(&pstYUVImage->imageData[3 * (i*pstImage->width + j) + 1], 1, 1, fp);
}
}
cvShowImage("Win", pstImage);
cvWaitKey(0);
cvReleaseImage(&pstImage);
cvReleaseImage(&pstYUVImage);
fclose(fp);
return 0;