#include "RkGenMeshVersion.h" #include "genMesh.h" #include "genMeshUtils.h" #include "Utils.h" #include "LdchApp.h" #include #ifdef WIN32 #include #include #endif #ifdef __cplusplus extern "C" { #endif #include "FecAppLib.h" #ifdef __cplusplus } #endif /* ²âÊÔFEC·Ö¼¶Ð£ÕýЧ¹û */ void test1() { int srcWidth, srcHeight; int dstWidth, dstHeight; /* ¾µÍ·²ÎÊý */ CameraCoeff camCoeff; /* imx415_2.88mm_3840x2160_ISP */ srcWidth = 3840; srcHeight = 2160; dstWidth = 3840; dstHeight = 2160; camCoeff.a0 = -2297.284245574242504517; camCoeff.a2 = 0.0001183387160889; camCoeff.a3 = 0.00000000621559354720; camCoeff.a4 = 0.00000000001194583141; camCoeff.cx = 1950.09945599999991827644; camCoeff.cy = 1124.36467200000015509431; /* imx415_2.88mm_3840x2160 */ //srcWidth = 3840; //srcHeight = 2160; //dstWidth = 3840; //dstHeight = 2160; //camCoeff.a0 = -2288.3964056645068012585397809743881225585937500000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0001189734940934424712666653278780870550690451636910438537597656250000000000000000000000000000000000; //camCoeff.a3 = 0.0000000054279366156211879180515005656904731212719639188435394316911697387695312500000000000000000000; //camCoeff.a4 = 0.0000000000122304699233774804266760321267817402703104168182335342862643301486968994140625000000000000; //camCoeff.cx = 1950.0996751827506159315817058086395263671875000000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 1123.5352222944213735900120809674263000488281250000000000000000000000000000000000000000000000000000000000; /* imx415_3.6mm_3840x2160_ISP */ //srcWidth = 3840; //srcHeight = 2160; //dstWidth = 3840; //dstHeight = 2160; //camCoeff.a0 = -2819.4072493821618081; //camCoeff.a2 = 0.0000316126581792; //camCoeff.a3 = 0.0000000688410142; //camCoeff.a4 = -0.0000000000130686; //camCoeff.cx = 1956.3909119999998438; //camCoeff.cy = 1140.6355200000000422; /* imx415_3.6mm_3840x2160 */ //srcWidth = 3840; //srcHeight = 2160; //dstWidth = 3840; //dstHeight = 2160; //camCoeff.a0 = -2701.5553345375383287318982183933258056640625000000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0000268969613364317018525725261346437378051632549613714218139648437500000000000000000000000000000000; //camCoeff.a3 = 0.0000000691847147285347339282183675053528038034755809349007904529571533203125000000000000000000000000; //camCoeff.a4 = -0.0000000000130627571989119925053445836944665276596611036552531004417687654495239257812500000000000000; //camCoeff.cx = 1957.1773439999999482097337022423744201660156250000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 1135.7418239999999514111550524830818176269531250000000000000000000000000000000000000000000000000000000000; /* imx347_4mm_2688x1520 */ //srcWidth = 2688; //srcHeight = 1520; //dstWidth = 2688; //dstHeight = 1520; //camCoeff.a0 = -1863.7984212819360436697024852037429809570312500000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0004710038222292998403434305387804670317564159631729125976562500000000000000000000000000000000000000; //camCoeff.a3 = -0.0000002932338849422447377658846635883893583240933367051184177398681640625000000000000000000000000000; //camCoeff.a4 = 0.0000000001512588833120702854166806930133210712385860574613616336137056350708007812500000000000000000; //camCoeff.cx = 1363.0740479999999479332473129034042358398437500000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 787.0316799999999375359038822352886199951171875000000000000000000000000000000000000000000000000000000000; /* OS04A10_4IR_2688x1520 */ //srcWidth = 2688; //srcHeight = 1520; //dstWidth = 2688; //dstHeight = 1520; //camCoeff.a0 = -1830.2636074851754983683349564671516418457031250000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0004237951284061040315917501253295540664112195372581481933593750000000000000000000000000000000000000; //camCoeff.a3 = -0.0000002507674855122118848025746917079770170744268398266285657882690429687500000000000000000000000000; //camCoeff.a4 = 0.0000000001272470035935948196069050985539572624916093701585850794799625873565673828125000000000000000; //camCoeff.cx = 1351.1178239999999277642928063869476318359375000000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 739.4860800000000153886503539979457855224609375000000000000000000000000000000000000000000000000000000000; /* OS04A10_6IR_2688x1520 */ //srcWidth = 2688; //srcHeight = 1520; //dstWidth = 2688; //dstHeight = 1520; //camCoeff.a0 = -2653.9299617503911576932296156883239746093750000000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0001171174803799108549888854935439042037614854052662849426269531250000000000000000000000000000000000; //camCoeff.a3 = -0.0000000150166870224219489918825648283248752612450971355428919196128845214843750000000000000000000000; //camCoeff.a4 = 0.0000000000087465891629053077103521832658175594581856371334538380324374884366989135742187500000000000; //camCoeff.cx = 1333.2695039999998698476701974868774414062500000000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 728.1043200000000297222868539392948150634765625000000000000000000000000000000000000000000000000000000000; /* s5kgm1sp_2mm_3840x2160 */ //srcWidth = 3840; //srcHeight = 2160; //dstWidth = 3840; //dstHeight = 2160; //camCoeff.a0 = -2218.1261186871761310612782835960388183593750000000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0001041174419821471223372016945418749855889473110437393188476562500000000000000000000000000000000000; //camCoeff.a3 = 0.0000000126660789198655226725038293366168429265883332845987752079963684082031250000000000000000000000; //camCoeff.a4 = -0.0000000000042910636667388937011160122430028583239564055062942315998952835798263549804687500000000000; //camCoeff.cx = 1941.4969974473960974137298762798309326171875000000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 1119.2980280068773026869166642427444458007812500000000000000000000000000000000000000000000000000000000000; /* DJI_test_4000x3000 */ //srcWidth = 4000; //srcHeight = 3000; //dstWidth = 4000; //dstHeight = 3000; //camCoeff.a0 = -1717.3398540219218375568743795156478881835937500000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0000979924653478899483540626169641996057180222123861312866210937500000000000000000000000000000000000; //camCoeff.a3 = -0.0000000365259026624921297930806668007724935520741382788401097059249877929687500000000000000000000000; //camCoeff.a4 = 0.0000000000221078478569051180847769663747939545943299588515174036729149520397186279296875000000000000; //camCoeff.cx = 2035.6544000000001233274815604090690612792968750000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 1515.2591999999999643478076905012130737304687500000000000000000000000000000000000000000000000000000000000; int srcSize = (srcWidth * srcHeight) > (dstWidth * dstHeight) ? (srcWidth * srcHeight) : (dstWidth * dstHeight); unsigned char *pImgY = new unsigned char[srcSize]; unsigned char *pImgUV = new unsigned char[srcSize]; unsigned char *pImgOut = new unsigned char[srcSize * 2]; /* ¶ÁyuvÎļþ */ char srcYuvPath[256]; sprintf(srcYuvPath, "../data_in/imx415_2.88mm_3840x2160/imx415_2.88mm_3840x2160_001.nv12"); /* imx415_2.88mm_3840x2160 */ //sprintf(srcYuvPath, "../data_in/imx415_2.88mm_3584x2016/imx415_2.88mm_3584x2016_001.nv12"); /* imx415_2.88mm_3584x2016 */ //sprintf(srcYuvPath, "../data_in/imx415_3.6mm_3840x2160/imx415_3.6mm_3840x2160_001.nv12"); /* imx415_3.6mm_3840x2160 */ //sprintf(srcYuvPath, "../data_in/imx347_4mm_2688x1520/imx347_4mm_2688x1520_006.nv12"); /* imx415_3.6mm_3840x2160 */ //sprintf(srcYuvPath, "../data_in/s5kgm1sp_2mm_3840x2160/s5kgm1sp_2mm_3840x2160_001.nv12"); /* s5kgm1sp_2mm_3840x2160 */ //sprintf(srcYuvPath, "../data_in/s5kgm1sp_2mm_3328x1872/s5kgm1sp_2mm_3328x1872_001.nv12"); /* s5kgm1sp_2mm_3328x1872 */ //sprintf(srcYuvPath, "../data_in/s5kgm1sp_2mm_3072x1728/s5kgm1sp_2mm_3072x1728_001.nv12"); /* s5kgm1sp_2mm_3072x1728 */ readNV12(srcYuvPath, srcWidth, srcHeight, pImgY, pImgUV); Rkclock rkclock; /* Éú³ÉFECÓ³Éä±íÏà¹ØµÄ²ÎÊý */ FecParams fecParams; fecParams.correctX = 1; /* ˮƽx·½ÏòУÕý: 1´ú±íУÕý, 0´ú±í²»Ð£Õý */ fecParams.correctY = 1; /* ´¹Ö±y·½ÏòУÕý: 1´ú±íУÕý, 0´ú±í²»Ð£Õý */ fecParams.saveMaxFovX = 1; /* ±£Áôˮƽx·½Ïò×î´óFOV: 1´ú±í±£Áô, 0´ú±í²»±£Áô */ fecParams.isFecOld = 1; /* ÊÇ·ñ¾É°æFEC: 1´ú±íÊÇ£¬0´ú±í²»ÊÇ */ fecParams.saveMesh4bin = 0; /* ÊÇ·ñ±£´æmeshxi,xf,yi,yf4¸öbinÎļþ: 1´ú±í±£´æ, 0´ú±í²»±£´æ */ sprintf(fecParams.mesh4binPath, "../data_out/"); /* ±£´æmeshxi,xf,yi,yf4¸öbinÎļþµÄ·¾¶ */ rkclock.clockStart(); genFecMeshInit(srcWidth, srcHeight, dstWidth, dstHeight, fecParams, camCoeff); /* ³õʼ»¯£º¸ù¾ÝͼÏñÊä³ö·Ö±æÂÊ£¬¼ÆËãFECÓ³Éä±íµÄÏà¹Ø²ÎÊý£¬ÉêÇëÐèÒªµÄbuffer */ rkclock.clockEnd("genFecMeshInit"); unsigned short *pMeshXI; /* XÕûÊý²¿·Ö */ unsigned char *pMeshXF; /* XСÊý²¿·Ö */ unsigned short *pMeshYI; /* YÕûÊý²¿·Ö */ unsigned char *pMeshYF; /* YСÊý²¿·Ö */ /* FEC 4¸ömesh ÄÚ´æÉêÇë */ mallocFecMesh(fecParams.meshSize4bin, &pMeshXI, &pMeshXF, &pMeshYI, &pMeshYF); bool success; int level = 0; /* level·¶Î§: 0-255 */ char dstYuvPath[256]; for (level = 0; level <= 255; level = level + 1) { printf("level = %d\n", level); /* Éú³É²»Í¬Ð£Õý³Ì¶ÈµÄFECÄ£¿éµÄmesh±í */ rkclock.clockStart(); success = genFECMeshNLevel(fecParams, camCoeff, level, pMeshXI, pMeshXF, pMeshYI, pMeshYF); rkclock.clockEnd("genFECMeshNLevel"); /* µ÷ÓÃFEC_Cmodel_4bin */ FEC_Cmodel_4bin(srcWidth, srcHeight, dstWidth, dstHeight, pImgY, pImgUV, pMeshXI, pMeshXF, pMeshYI, pMeshYF, pImgOut); /* ±£´æ */ if (fecParams.correctX == 1 && fecParams.correctY == 1) { sprintf(dstYuvPath, "../data_out/fec_out_both_correct_%dx%d_%03d.nv12", dstWidth, dstHeight, level); } else if (fecParams.correctX == 1 && fecParams.correctY == 0) { sprintf(dstYuvPath, "../data_out/fec_out_x_correct_%dx%d_%03d.nv12", dstWidth, dstHeight, level); } else if (fecParams.correctX == 0 && fecParams.correctY == 1) { sprintf(dstYuvPath, "../data_out/fec_out_y_correct_%dx%d_%03d.nv12", dstWidth, dstHeight, level); } else if (fecParams.correctX == 0 && fecParams.correctY == 0) { sprintf(dstYuvPath, "../data_out/fec_out_no_correct_%dx%d_%03d.nv12", dstWidth, dstHeight, level); } saveNV12(dstYuvPath, dstWidth, dstHeight, pImgOut); } delete[] pImgY; delete[] pImgUV; delete[] pImgOut; /* FEC mesh ÄÚ´æÊÍ·Å */ freeFecMesh(pMeshXI, pMeshXF, pMeshYI, pMeshYF); /* ·´³õʼ»¯ */ genFecMeshDeInit(fecParams); } /* ²âÊÔLDCH·Ö¼¶Ð£ÕýЧ¹û */ void test2() { int srcWidth, srcHeight; int dstWidth, dstHeight; /* ¾µÍ·²ÎÊý */ CameraCoeff camCoeff; /* imx415_2.88mm_3840x2160_ISP */ //srcWidth = 3840; //srcHeight = 2160; //dstWidth = 3840; //dstHeight = 2160; //camCoeff.a0 = -2297.284245574242504517; //camCoeff.a2 = 0.0001183387160889; //camCoeff.a3 = 0.00000000621559354720; //camCoeff.a4 = 0.00000000001194583141; //camCoeff.cx = 1950.09945599999991827644; //camCoeff.cy = 1124.36467200000015509431; /* imx415_2.88mm_3840x2160 */ //srcWidth = 3840; //srcHeight = 2160; //dstWidth = 3840; //dstHeight = 2160; //camCoeff.a0 = -2288.3964056645068012585397809743881225585937500000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0001189734940934424712666653278780870550690451636910438537597656250000000000000000000000000000000000; //camCoeff.a3 = 0.0000000054279366156211879180515005656904731212719639188435394316911697387695312500000000000000000000; //camCoeff.a4 = 0.0000000000122304699233774804266760321267817402703104168182335342862643301486968994140625000000000000; //camCoeff.cx = 1950.0996751827506159315817058086395263671875000000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 1123.5352222944213735900120809674263000488281250000000000000000000000000000000000000000000000000000000000; /* imx415_3.6mm_3840x2160_ISP */ //srcWidth = 3840; //srcHeight = 2160; //dstWidth = 3840; //dstHeight = 2160; //camCoeff.a0 = -2819.4072493821618081; //camCoeff.a2 = 0.0000316126581792; //camCoeff.a3 = 0.0000000688410142; //camCoeff.a4 = -0.0000000000130686; //camCoeff.cx = 1956.3909119999998438; //camCoeff.cy = 1140.6355200000000422; /* imx415_3.6mm_3840x2160 */ //srcWidth = 3840; //srcHeight = 2160; //dstWidth = 3840; //dstHeight = 2160; //camCoeff.a0 = -2701.5553345375383287318982183933258056640625000000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0000268969613364317018525725261346437378051632549613714218139648437500000000000000000000000000000000; //camCoeff.a3 = 0.0000000691847147285347339282183675053528038034755809349007904529571533203125000000000000000000000000; //camCoeff.a4 = -0.0000000000130627571989119925053445836944665276596611036552531004417687654495239257812500000000000000; //camCoeff.cx = 1957.1773439999999482097337022423744201660156250000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 1135.7418239999999514111550524830818176269531250000000000000000000000000000000000000000000000000000000000; /* imx347_4mm_2688x1520 */ //srcWidth = 2688; //srcHeight = 1520; //dstWidth = 2688; //dstHeight = 1520; //camCoeff.a0 = -1863.7984212819360436697024852037429809570312500000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0004710038222292998403434305387804670317564159631729125976562500000000000000000000000000000000000000; //camCoeff.a3 = -0.0000002932338849422447377658846635883893583240933367051184177398681640625000000000000000000000000000; //camCoeff.a4 = 0.0000000001512588833120702854166806930133210712385860574613616336137056350708007812500000000000000000; //camCoeff.cx = 1363.0740479999999479332473129034042358398437500000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 787.0316799999999375359038822352886199951171875000000000000000000000000000000000000000000000000000000000; /* OS04A10_4IR_2688x1520 */ //srcWidth = 2688; //srcHeight = 1520; //dstWidth = 2688; //dstHeight = 1520; //camCoeff.a0 = -1830.2636074851754983683349564671516418457031250000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0004237951284061040315917501253295540664112195372581481933593750000000000000000000000000000000000000; //camCoeff.a3 = -0.0000002507674855122118848025746917079770170744268398266285657882690429687500000000000000000000000000; //camCoeff.a4 = 0.0000000001272470035935948196069050985539572624916093701585850794799625873565673828125000000000000000; //camCoeff.cx = 1351.1178239999999277642928063869476318359375000000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 739.4860800000000153886503539979457855224609375000000000000000000000000000000000000000000000000000000000; /* OS04A10_6IR_2688x1520 */ //srcWidth = 2688; //srcHeight = 1520; //dstWidth = 2688; //dstHeight = 1520; //camCoeff.a0 = -2653.9299617503911576932296156883239746093750000000000000000000000000000000000000000000000000000000000000; //camCoeff.a2 = 0.0001171174803799108549888854935439042037614854052662849426269531250000000000000000000000000000000000; //camCoeff.a3 = -0.0000000150166870224219489918825648283248752612450971355428919196128845214843750000000000000000000000; //camCoeff.a4 = 0.0000000000087465891629053077103521832658175594581856371334538380324374884366989135742187500000000000; //camCoeff.cx = 1333.2695039999998698476701974868774414062500000000000000000000000000000000000000000000000000000000000000; //camCoeff.cy = 728.1043200000000297222868539392948150634765625000000000000000000000000000000000000000000000000000000000; /* s5kgm1sp_2mm_3840x2160 */ srcWidth = 3840; srcHeight = 2160; dstWidth = 3840; dstHeight = 2160; camCoeff.a0 = -2218.1261186871761310612782835960388183593750000000000000000000000000000000000000000000000000000000000000; camCoeff.a2 = 0.0001041174419821471223372016945418749855889473110437393188476562500000000000000000000000000000000000; camCoeff.a3 = 0.0000000126660789198655226725038293366168429265883332845987752079963684082031250000000000000000000000; camCoeff.a4 = -0.0000000000042910636667388937011160122430028583239564055062942315998952835798263549804687500000000000; camCoeff.cx = 1941.4969974473960974137298762798309326171875000000000000000000000000000000000000000000000000000000000000; camCoeff.cy = 1119.2980280068773026869166642427444458007812500000000000000000000000000000000000000000000000000000000000; int srcSize = (srcWidth * srcHeight) > (dstWidth * dstHeight) ? (srcWidth * srcHeight) : (dstWidth * dstHeight); unsigned short *pImgIn = new unsigned short[srcSize * 3]; unsigned short *pImgOut = new unsigned short[srcSize * 3]; /* ¶ÁBGRͼÏñ */ char srcBGRPath[256]; //sprintf(srcBGRPath, "../data_in/imx415_2.88mm_3840x2160/imx415_2.88mm_3840x2160_001.jpeg"); /* imx415_2.88mm_3840x2160 */ //sprintf(srcBGRPath, "../data_in/imx415_3.6mm_3840x2160/imx415_3.6mm_3840x2160_001.jpeg"); /* imx415_3.6mm_3840x2160 */ //sprintf(srcBGRPath, "../data_in/imx347_4mm_2688x1520/imx347_4mm_2688x1520_006.bmp"); /* imx415_3.6mm_3840x2160 */ sprintf(srcBGRPath, "../data_in/s5kgm1sp_2mm_3840x2160/s5kgm1sp_2mm_3840x2160_001.png"); /* s5kgm1sp_2mm_3840x2160 */ #ifdef WIN32 cv::Mat imgBGR = cv::imread(srcBGRPath); unsigned char *pIn = imgBGR.data; int stride = srcWidth * 3; int index = 0; for (int y = 0; y < imgBGR.rows; ++y) { for (int x = 0; x < imgBGR.cols; ++x) { pImgIn[index + 0] = *(pIn + y * stride + 3 * x + 0); pImgIn[index + 1] = *(pIn + y * stride + 3 * x + 1); pImgIn[index + 2] = *(pIn + y * stride + 3 * x + 2); index = index + 3; } } #endif Rkclock rkclock; /* Éú³ÉLDCHÓ³Éä±íÏà¹ØµÄ²ÎÊý */ LdchParams ldchParams; ldchParams.saveMaxFovX = 1; /* ±£Áôˮƽx·½Ïò×î´óFOV: 1´ú±í±£Áô, 0´ú±í²»±£Áô */ ldchParams.isLdchOld = 1; /* ÊÇ·ñ¾É°æLDCH: 1´ú±íÊÇ£¬0´ú±í²»ÊÇ */ ldchParams.saveMeshX = 0; /* ÊÇ·ñ±£´æMeshX.binÎļþ: 1´ú±í±£´æ, 0´ú±í²»±£´æ */ sprintf(ldchParams.meshPath, "../data_out/"); /* ±£´æMeshX.binÎļþµÄ·¾¶ */ rkclock.clockStart(); genLdchMeshInit(srcWidth, srcHeight, dstWidth, dstHeight, ldchParams, camCoeff); /* ³õʼ»¯£º¸ù¾ÝͼÏñÊä³ö·Ö±æÂÊ£¬¼ÆËãLDCHÓ³Éä±íµÄÏà¹Ø²ÎÊý£¬ÉêÇëÐèÒªµÄbuffer */ rkclock.clockEnd("genLdchMeshInit"); unsigned short *pMeshX = new unsigned short[ldchParams.meshSize]; bool success; int level = 0; /* level·¶Î§: 0-255 */ char dstYuvPath[256]; for (level = 0; level <= 255; ++level) { printf("level = %d\n", level); rkclock.clockStart(); success = genLDCMeshNLevel(ldchParams, camCoeff, level, pMeshX); /* Éú³É¶ÔӦУÕýlevelµÄLDCHÓ³Éä±í */ rkclock.clockEnd("genLDCMeshNLevel"); LDCH_Cmodel(dstWidth, dstHeight, pImgIn, pImgOut, pMeshX); /* µ÷ÓÃLDCH_Cmodel */ #ifdef WIN32 /* ±£´æ */ int imgBit = 8; //sprintf(dstYuvPath, "../data_out/ldch_out_%dx%d_%03d.bmp", dstWidth, dstHeight, level); //SaveBmpFile2(dstYuvPath, dstWidth, dstHeight, imgBit, pImgOut); sprintf(dstYuvPath, "../data_out/ldch_out_%dx%d_%03d.nv12", dstWidth, dstHeight, level); saveLdchNV12(dstYuvPath, dstWidth, dstHeight, imgBit, pImgOut); #endif } /* ÄÚ´æÊÍ·Å */ delete[] pImgIn; delete[] pImgOut; delete[] pMeshX; /* ·´³õʼ»¯ */ genLdchMeshDeInit(ldchParams); } int main() { test1(); #ifdef WIN32 system("pause"); #endif return 0; }