1
2 /* 8kͼ--->2��4kͼ������FEC�ּ�У�� */
test029()3 void test029()
4 {
5 int srcW = 7680;
6 int srcH = 4320;
7 int dstW = 7680;
8 int dstH = 4320;
9 int margin = 256;
10
11 /* ȫͼ8k��ز��� */
12 CameraCoeff camCoeff;
13 camCoeff.a0 = -4628.92834904855135391699150204658508300781250000000000;
14 camCoeff.a2 = 0.00008439805632153267055031026222522427815420087427;
15 camCoeff.a3 = -0.00000000947972529654520536345924537060744774485954;
16 camCoeff.a4 = 0.00000000000276046059610868196196561020719728129884;
17 camCoeff.cx = (srcW - 1.0) * 0.5;
18 camCoeff.cy = (srcH - 1.0) * 0.5;
19 FecParams fecParams;
20 fecParams.correctX = 1; /* ˮƽx����У��: 1����У��, 0����У�� */
21 fecParams.correctY = 1; /* ��ֱy����У��: 1����У��, 0����У�� */
22 fecParams.saveMaxFovX = 1; /* ����ˮƽx�������FOV: 1������, 0�������� */
23 fecParams.isFecOld = 0; /* �Ƿ�ɰ�FEC: 1�����ǣ�0������ */
24 fecParams.saveMesh4bin = 0; /* �Ƿ�meshxi,xf,yi,yf4��bin�ļ�: 1������, 0�������� */
25 sprintf(fecParams.mesh4binPath, "../data_out/"); /* ����meshxi,xf,yi,yf4��bin�ļ��ĸ�Ŀ¼ */
26
27 /* ��ͼ4k��ز��� */
28 CameraCoeff camCoeff_left;
29 FecParams fecParams_left;
30 /* ��ͼ4k��ز��� */
31 CameraCoeff camCoeff_right;
32 FecParams fecParams_right;
33 /* LDCH��ز�����ʼ�� */
34 genFecMeshInit8kTo4k(srcW, srcH, dstW, dstH, margin, camCoeff, camCoeff_left, camCoeff_right, fecParams, fecParams_left, fecParams_right);
35 /* ӳ���buffer���� */
36 unsigned short *pMeshXI, *pMeshYI; /* X, Y�������� */
37 unsigned char *pMeshXF, *pMeshYF; /* X, Y������ */
38 mallocFecMesh(fecParams.meshSize4bin, &pMeshXI, &pMeshXF, &pMeshYI, &pMeshYF); /* ȫͼFECӳ���buffer���� */
39 unsigned short *pMeshXI_left, *pMeshYI_left; /* X, Y�������� */
40 unsigned char *pMeshXF_left, *pMeshYF_left; /* X, Y������ */
41 mallocFecMesh(fecParams_left.meshSize4bin, &pMeshXI_left, &pMeshXF_left, &pMeshYI_left, &pMeshYF_left); /* ��ͼFECӳ���buffer���� */
42 unsigned short *pMeshXI_right, *pMeshYI_right; /* X, Y�������� */
43 unsigned char *pMeshXF_right, *pMeshYF_right; /* X, Y������ */
44 mallocFecMesh(fecParams_right.meshSize4bin, &pMeshXI_right, &pMeshXF_right, &pMeshYI_right, &pMeshYF_right); /* ��ͼFECӳ���buffer���� */
45
46 /* �������ͼ��buffer���� */
47 /* ȫͼ */
48 unsigned long srcSize = (srcW * srcH) > (dstW * dstH) ? (srcW * srcH) : (dstW * dstH);
49 unsigned char *pImgY = new unsigned char[srcSize];
50 unsigned char *pImgUV = new unsigned char[srcSize];
51 unsigned char *pImgOut = new unsigned char[srcSize * 2];
52 /* ��ͼ */
53 int srcW_left = srcW * 0.5 + margin;
54 int srcH_left = srcH;
55 int dstW_left = srcW * 0.5 + margin;
56 int dstH_left = srcH;
57 unsigned long srcSize_left = (srcW_left * srcH_left) > (dstW_left * dstH_left) ? (srcW_left * srcH_left) : (dstW_left * dstH_left);
58 unsigned char *pImgY_left = new unsigned char[srcSize_left];
59 unsigned char *pImgUV_left = new unsigned char[srcSize_left];
60 unsigned char *pImgOut_left = new unsigned char[srcSize_left * 2];
61 /* ��ͼ */
62 int srcW_right = srcW * 0.5 + margin;
63 int srcH_right = srcH;
64 int dstW_right = srcW * 0.5 + margin;
65 int dstH_right = srcH;
66 unsigned long srcSize_right = (srcW_right * srcH_right) > (dstW_right * dstH_right) ? (srcW_right * srcH_right) : (dstW_right * dstH_right);
67 unsigned char *pImgY_right = new unsigned char[srcSize_right];
68 unsigned char *pImgUV_right = new unsigned char[srcSize_right];
69 unsigned char *pImgOut_right = new unsigned char[srcSize_right * 2];
70
71 /* ��ȡ����ͼ�� */
72 char srcYuvPath[512] = "../data_in/image/group_023_imx415_2.8mm_7680x4320_half/imx415_2.8mm_full_7680x4320_08.nv12";
73 readYUV(srcYuvPath, srcW, srcH, 0, NULL, pImgY, pImgUV);
74 char srcYuvPath_left[512] = "../data_in/image/group_023_imx415_2.8mm_7680x4320_half/imx415_2.8mm_left_4096x4320_08.nv12";
75 readYUV(srcYuvPath_left, srcW_left, srcH_left, 0, NULL, pImgY_left, pImgUV_left);
76 char srcYuvPath_right[512] = "../data_in/image/group_023_imx415_2.8mm_7680x4320_half/imx415_2.8mm_right_4096x4320_08.nv12";
77 readYUV(srcYuvPath_right, srcW_right, srcH_right, 0, NULL, pImgY_right, pImgUV_right);
78
79 /* ����FECӳ�������У�� */
80 int level = 0; /* level��Χ: 0-255 */
81 int levelValue[] = { 0,64,128,192,255 };
82 //for (level = 0; level <= 0; level = level + 1)
83 for (int levelIdx = 0; levelIdx < 5; ++levelIdx)
84 {
85 level = levelValue[levelIdx];
86 printf("level = %d\n", level);
87
88 /* ��ͼ����FECУ�� */
89 bool success_left = genFECMeshNLevel(fecParams_left, camCoeff_left, level, pMeshXI_left, pMeshXF_left, pMeshYI_left, pMeshYF_left); /* ���ɶ�ӦУ��level��FECӳ��� */
90 FEC_Cmodel_4bin(srcW_left, srcH_left, dstW_left, dstH_left, pImgY_left, pImgUV_left,
91 pMeshXI_left, pMeshXF_left, pMeshYI_left, pMeshYF_left, pImgOut_left, 0, 0, 0, 0, 0, 0); /* ����FEC */
92 cv::Mat dstImgBGR_left; /* ���� */
93 NV12toRGB(pImgOut_left, dstW_left, dstH_left, dstImgBGR_left);
94 char dstBmpPath_left[256];
95 sprintf(dstBmpPath_left, "../data_out/fec_left_%dx%d_level%03d.bmp", dstW_left, dstH_left, level);
96 cv::imwrite(dstBmpPath_left, dstImgBGR_left);
97
98 /* ��ͼ����FECУ�� */
99 bool success_right = genFECMeshNLevel(fecParams_right, camCoeff_right, level, pMeshXI_right, pMeshXF_right, pMeshYI_right, pMeshYF_right); /* ���ɶ�ӦУ��level��FECӳ��� */
100 FEC_Cmodel_4bin(srcW_right, srcH_right, dstW_right, dstH_right, pImgY_right, pImgUV_right,
101 pMeshXI_right, pMeshXF_right, pMeshYI_right, pMeshYF_right, pImgOut_right, 0, 0, 0, 0, 0, 0); /* ����FEC */
102 cv::Mat dstImgBGR_right; /* ���� */
103 NV12toRGB(pImgOut_right, dstW_right, dstH_right, dstImgBGR_right);
104 char dstBmpPath_right[256];
105 sprintf(dstBmpPath_right, "../data_out/fec_right_%dx%d_level%03d.bmp", dstW_right, dstH_right, level);
106 cv::imwrite(dstBmpPath_right, dstImgBGR_right);
107
108 /* ��֤: ȫͼ����FECУ�� */
109 bool success_full = genFECMeshNLevel(fecParams, camCoeff, level, pMeshXI, pMeshXF, pMeshYI, pMeshYF); /* ���ɶ�ӦУ��level��FECӳ��� */
110 FEC_Cmodel_4bin(srcW, srcH, dstW, dstH, pImgY, pImgUV,
111 pMeshXI, pMeshXF, pMeshYI, pMeshYF, pImgOut, 0, 0, 0, 0, 0, 0); /* ����FEC */
112 cv::Mat dstImgBGR_full; /* ���� */
113 NV12toRGB(pImgOut, dstW, dstH, dstImgBGR_full);
114 char dstBmpPath_full[256];
115 sprintf(dstBmpPath_full, "../data_out/fec_full_%dx%d_level%03d.bmp", dstW, dstH, level);
116 cv::imwrite(dstBmpPath_full, dstImgBGR_full);
117
118 /* ��֤: ��ͼFEC��� + ��ͼFEC��� ---> ƴ�ӵ�ȫͼ��� */
119 cv::Mat dstImgBGR_stitch = cv::Mat(dstH, dstW, CV_8UC3);
120 dstImgBGR_left(cv::Range(0, dstH_left), cv::Range(0, dstW_left - margin)).copyTo(dstImgBGR_stitch(cv::Range(0, dstH), cv::Range(0, dstW * 0.5)));
121 dstImgBGR_right(cv::Range(0, dstH_left), cv::Range(margin, dstW_right)).copyTo(dstImgBGR_stitch(cv::Range(0, dstH), cv::Range(dstW * 0.5, dstW)));
122 char dstBmpPath_stitch[256];
123 sprintf(dstBmpPath_stitch, "../data_out/fec_stitch_%dx%d_level%03d.bmp", dstW, dstH, level);
124 cv::imwrite(dstBmpPath_stitch, dstImgBGR_stitch);
125 }
126 /* ȫͼ����ڴ��ͷźͷ���ʼ�� */
127 delete[] pImgY;
128 delete[] pImgUV;
129 delete[] pImgOut;
130 freeFecMesh(pMeshXI, pMeshXF, pMeshYI, pMeshYF); /* �ڴ��ͷ� */
131 genFecMeshDeInit(fecParams); /* ����ʼ�� */
132
133 /* ��ͼ����ڴ��ͷźͷ���ʼ�� */
134 delete[] pImgY_left;
135 delete[] pImgUV_left;
136 delete[] pImgOut_left;
137 freeFecMesh(pMeshXI_left, pMeshXF_left, pMeshYI_left, pMeshYF_left); /* �ڴ��ͷ� */
138 genFecMeshDeInit(fecParams_left); /* ����ʼ�� */
139
140 /* ��ͼ����ڴ��ͷźͷ���ʼ�� */
141 delete[] pImgY_right;
142 delete[] pImgUV_right;
143 delete[] pImgOut_right;
144 freeFecMesh(pMeshXI_right, pMeshXF_right, pMeshYI_right, pMeshYF_right); /* �ڴ��ͷ� */
145 genFecMeshDeInit(fecParams_right); /* ����ʼ�� */
146
147
148 }