基于Opencv的幾種立體匹配算法+ELAS_第1頁(yè)
基于Opencv的幾種立體匹配算法+ELAS_第2頁(yè)
基于Opencv的幾種立體匹配算法+ELAS_第3頁(yè)
基于Opencv的幾種立體匹配算法+ELAS_第4頁(yè)
基于Opencv的幾種立體匹配算法+ELAS_第5頁(yè)
已閱讀5頁(yè),還剩3頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、基于Opencv的幾種立體匹配算法+ELAS0:ELAS這里要去下載日as的開源庫(kù)函數(shù)。intStereoMatch:ElasMatch()(cv:Matdisp_l,disp_r,disp8u_l,disp8u_r;doubleminVal;doublemaxVal;/視差圖的極值cv二MatleftImage=cv二imread(./test_images/leftr31.png,0);cv:MatrightImage=cv二imread(./test_images/rightr31.png,0);/計(jì)算視差/generatedisparityimageusingLIBELASintbd=

2、0;constint32_tdims3=leftImage.cols,leftImage.rows,leftImage.cols;cv:Matleftdpf=cv二Mat:zeros(cv二Size(leftImage.cols,leftImage.rows),CV_32F);cv:Matrightdpf=cv:Mat:zeros(cv二Size(leftImage.cols,leftImage.rows),CV_32F);Elas:parametersparam;param.postprocess_only_left=false;Elaselas(param);cess(le

3、ftlmage.data,rightlmage.data,leftdpf.ptr(0),rightdpf.ptr(0),dims);cv二Mat(leftdpf(cv二Rect(bd,0,leftImage.cols,leftImage.rows).copyTo(disp_l);cv二Mat(rightdpf(cv:Rect(bd,0,rightImage.cols,rightImage.rows).copyTo(disp_r);一Checkitsextremevaluescv二minMaxLoc(disp_l,&minVal,&maxVal);coutMindisp:MaxvalueminV

4、almaxVal;numberOfDisparities.=(maxVal-minVal)一DisplayitasaCV_8UC1imagedisp_l.convertTo(disp8u_l,CV_8U,255/(maxVal-minVal);(numberOfDisparities*16.)cv二minMaxLoc(disp_r,&minVal,&maxVal);coutMindisp:MaxvalueminValmaxVal;numberOfDisparities.=(maxVal-minVal)/-DisplayitasaCV_8UC1imagedisp_r.convertTo(disp

5、8u_r,CV_8U,255/(maxVal-minVal);/(numberOfDisparities*16.)cv:normalize(disp8u_l,disp8u_l,0,255,CV_MINMAX,CV_8UC1);/obtainnormalizedimagecv:normalize(disp8u_r,disp8u_r,0,255,CV_MINMAX,CV_8UC1);/obtainnormalizedimagecv:imshow(Left,leftImage);cv二imshow(Right,rightImage);cv:imshow(Elas_left,disp8u_l);cv:

6、imshow(Elas_right,disp8u_r);cv:imwrite(Elas_left.png,disp8u_l);cv:imwrite(Elas_right.png,disp8u_r);coutendlOverendl;cv:waitKey(0);return0;1:BM算法intStereoMatch:BMMatching()cv:Matdisp,disp8u;doubleminVal;doublemaxVal;/視差圖的極值cv:Matleftlmage=cv:imread(./test_images/leftr.png,0);cv:MatrightImage=cv二imrea

7、d(./test_images/rightr.png,0);intSADWindowSize=19;intnumberOfDisparities=16*3;/*0?numberOfDisparities:(leftImage.cols/8)+15)&-16;/bm.state-roi1=remapMat.Calib_Roi_L;/左右視圖的有效像素區(qū)域,一般由雙目校正階段的cvStereoRectify函數(shù)傳遞,也可以自行設(shè)定。/bm.state-roi2=remapMat.Calib_Roi_R;/一旦在狀態(tài)參數(shù)中設(shè)定了roi1和roi2,OpenCV會(huì)通過(guò)cvGetValidDispari

8、tyROI函數(shù)計(jì)算出視差圖的有效區(qū)域,在有效區(qū)域外的視差值將被清零。/bm.State-preFilterSize=41;/預(yù)處理濾波器窗口大小,5-21,oddbm.state-preFilterCap=31;/63,1-31/預(yù)處理濾波器的截?cái)嘀担A(yù)處理的輸出值僅保留卜preFilterCap,preFilterCap范圍內(nèi)的值,bm.state-SADWindowSize=SADWindowSize0?SADWindowSize:9;/SAD窗口大小5-21bm.state-minDisparity=0;/64最小視差,默認(rèn)值為0bm.state-numberOfDisparities=

9、numberOfDisparities;/128視差窗口,即最大視差值與最小視差值之差,窗口大小必須是16的整數(shù)倍bm.state-textureThreshold=10;/低紋理區(qū)域的判斷閾值。如果當(dāng)前SAD窗口內(nèi)所有鄰居像素點(diǎn)的x導(dǎo)數(shù)絕對(duì)值之和小于指定閾值,則該窗口對(duì)應(yīng)的像素點(diǎn)的視差值為0bm.state-uniquenessRatio=15;/5-15視差唯一性百分比,視差窗口范圍內(nèi)最低代價(jià)是次低代價(jià)的(1+uniquenessRatio/100)倍時(shí),最低代價(jià)對(duì)應(yīng)的視差值才是該像素點(diǎn)的視差,否則該像素點(diǎn)的視差為0bm.state-speckleWindowSize=100;/檢查視差連

10、通區(qū)域變化度的窗口大小,值為0時(shí)取消speckle檢查bm.state-speckleRange=32;/視差變化閾值,當(dāng)窗口內(nèi)視差變化大于閾值時(shí),該窗口內(nèi)的視差清零bm.state-disp12MaxDiff=1;左視差圖(直接計(jì)算得出)和右視差圖(通過(guò)cvValidateDisparity計(jì)算得出)之間的最大容許差異。超過(guò)該閾值的視差值將被清零。該參數(shù)默認(rèn)為-1,即不執(zhí)行左右視差檢查。注意在程序調(diào)試階段最好保持該值為-1,以便查看不同視差窗口生成的視差效果。/計(jì)算視差bm(leftImage,rightImage,disp);/-Checkitsextremevaluescv:minMax

11、Loc(disp,&minVal,&maxVal);coutMindisp:MaxvalueminValmaxVal;/numberOfDisparities.=(maxVal-minVal)/-4.DisplayitasaCV_8UC1imagedisp.convertTo(disp8u,CV_8U,255/(maxVal-minVal);(numberOfDisparities*16.)cv二normalize(disp8u,disp8u,0,255,CV_MINMAX,CV_8UC1);/obtainnormalizedimagecv二imshow(left,leftImage);cv二

12、imshow(right,leftImage);cv二imshow(Disp,disp8u);cv二imwrite(bm.png,disp8u);cv二waitKey(0);2:SGBMintStereoMatch:SGBMMatching()cv二Matdisp,disp8u;doubleminVal;doublemaxVal;/視差圖的極值cv二MatleftImage=cv二imread(./test_images/leftr.png,0);cv二MatrightImage=cv二imread(./test_images/rightr.png,0);intnumberOfDisparit

13、ies=16*2;/*0?numberOfDisparities:(leftImage.cols/8)+15)&-16;intSADWindowSize=11;sgbm.preFilterCap=63;sgbm.SADWindowSize=SADWindowSize0?SADWindowSize:3;/3-11intcn=leftImage.channels();sgbm.P1=8*cn*sgbm.SADWindowSize*sgbm.SADWindowSize;P1、P2的值越大,視差越平,toP2P1,可取(50,800)或者(40,2500)sgbm.P2=32*cn*sgbm.SADW

14、indowSize*sgbm.SADWindowSize;sgbm.minDisparity=0;sgbm.numberOfDisparities=numberOfDisparities;128,256sgbm.uniquenessRatio=10;/10,0sgbm.speckleWindowSize=100;/200sgbm.speckleRange=32;sgbm.disp12MaxDiff=1;sgbm.fullDP=1;/計(jì)算視差sgbm(leftImage,rightImage,disp);/-Checkitsextremevaluescv二minMaxLoc(disp,&minV

15、al,&maxVal);coutMindisp:MaxvalueminValmaxVal;/numberOfDisparities.=(maxVal-minVal)/-4.DisplayitasaCV_8UC1imagedisp.convertTo(disp8u,CV_8U,255/(maxVal-minVal);/(numberOfDisparities*16.)cv二normalize(disp8u,disp8u,0,255,CV_MINMAX,CV_8UC1);/obtainnormalizedimagecv二imshow(left,leftImage);cv二imshow(right,

16、leftImage);cv二imshow(Disp,disp8u);cv二imwrite(sgbm.png,disp8u);cv二waitKey(0);3:VARintStereoMatch:VARMatching()(cv:Matdisp,disp8u;doubleminVal;doublemaxVal;/視差圖的極值cv二MatleftImage=cv二imread(./test_images/leftr.png,0);cv:MatrightImage=cv二imread(./test_images/rightr.png,0);intnumberOfDisparities=16*2;/*0

17、?numberOfDisparities:(leftImage.cols/8)+15)&-16;var.levels=3;/ignoredwithUSE_AUTO_PARAMSvar.pyrScale=0.5;/ignoredwithUSE_AUTO_PARAMSvar.nIt=25;var.minDisp=-numberOfDisparities;var.maxDisp=0;var.poly_n=3;var.poly_sigma=0.0;var.fi=15.0f;var.lambda=0.03f;var.penalization=var.PENALIZATION_TICHONOV;/igno

18、redwithUSE_AUTO_PARAMSvar.cycle=var.CYCLE_V;/ignoredwithUSE_AUTO_PARAMSvar.flags=var.USE_SMART_ID|var.USE_AUTO_PARAMS|var.USE_INITIAL_DISPARITY|var.USE_MEDIAN_FILTERING;/計(jì)算視差var(leftImage,rightimage,disp);/-Checkitsextremevaluescv二minMaxLoc(disp,&minVal,&maxVal);coutMindisp:MaxvalueminValendldepth,1

19、);IplImage*right_disp_=cvCreateImage(cvGetSize(leftImage),leftImage-depth,1);cvFindStereoCorrespondenceGC(leftImage,rightImage,left_disp_,right_disp_,state,0);cvReleaseStereoGCState(&state);cvNamedWindow(Left,1);cvNamedWindow(Right,1);cvNamedWindow(GC_left,1);cvNamedWindow(GC_right,1);cvShowImage(Le

20、ft,leftImage);cvShowImage(Right,rightImage);cvNormalize(left_disp_,left_disp_,0,255,CV_MINMAX,CV_8UC1);cvNormalize(right_disp_,right_disp_,0,255,CV_MINMAX,CV_8UC1);cvShowImage(GC_left,left_disp_);cvShowImage(GC_right,right_disp_);cvSaveImage(GC_left.png,left_disp_);cvSaveImage(GC_right.png,right_dis

21、p_);coutendlOverendl;cvWaitKey(O);cvDestroyAllWindows();cvReleaseImage(&leftImage);cvReleaseImage(&rightImage);return0;intStereoMatch:GCMatching_Mat()(doubleminVal;doublemaxVal;/視差圖的極值cv:Matdisp8u_l,disp8u_r;cv:MatleftImage=cv二imread(./test_images/leftr31.png,0);cv:MatrightImage=cv二imread(./test_ima

22、ges/rightr31.png,0);CvStereoGCState*state=cvCreateStereoGCState(16,5);cv二Matleft_disp_=leftImage.clone();cv:Matright_disp_=rightImage.clone();IplImagetemp=(IplImage)leftImage;IplImage*leftimg=&temp;IplImagetemp1=(IplImage)rightImage;IplImage*rightimg=&temp1;IplImagetemp2=(IplImage)left_disp_;IplImage*leftdisp=&temp2;IplImagetemp3=(IplImage)right_disp_;IplImage*rightdisp=&temp3;cvFindStereoCorrespondenceGC(leftimg,rightimg,leftdisp,rightdisp,state,0);cvReleaseStereoGCState(&state);cv二namedWindow(Left,1);cv:namedWindow(Right,1);cv:nam

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論