ubuntu16.04下基于opencv 3.4.1实现stereo-bm算法的双目视图的视差图

环境

ubuntu16.04LTS

code

算法:BM

#include 
#include 
#include 
#include 
#include 
//#include 
#include 
#include 
#include 
#include 
using namespace std; 
using namespace cv; 

int main() 
{ 
//IplImage * img1 = cvLoadImage("left.png",0); 
//IplImage * img2 = cvLoadImage("right.png",0); 
//IplImage * img1 = cvLoadImage("tsukuba_l.png",0); 
//IplImage * img2 = cvLoadImage("tsukuba_r.png",0); 
    IplImage * img1 = cvLoadImage("../Art/view1.png",0); 
    IplImage * img2 = cvLoadImage("../Art/view5.png",0); 
    CvStereoBMState* BMState=cvCreateStereoBMState(); 
    assert(BMState); 
    BMState->preFilterSize=9; 
    BMState->preFilterCap=31; 
    BMState->SADWindowSize=15; 
    BMState->minDisparity=0; 
    BMState->numberOfDisparities=144; 
    BMState->textureThreshold=10; 
    BMState->uniquenessRatio=5; 
    BMState->speckleWindowSize=100; 
    BMState->speckleRange=32; 
    BMState->disp12MaxDiff=-1; 
    CvMat* disp=cvCreateMat(img1->height,img1->width,CV_16S); 
    CvMat* vdisp=cvCreateMat(img1->height,img1->width,CV_8U); 
    int64 t=getTickCount(); 
    cvFindStereoCorrespondenceBM(img1,img2,disp,BMState); 
    t=getTickCount()-t; 
    cout<<"Time elapsed:"<

注意事项

要修改opencv库版本,比如当前open3.4.1安装在如下

/usr/local/opencv3.4.1

那么使用pkg-config

pkg-config --cflag opencv                 查看头文件路径
pkg-config --libs opencv                  查看库名
pkg-config --modversion opencv            查看版本
gedit ~/.bashrc
CMAKE_INSTALL_PREFIX=/usr/local/opencv3.4.1
export PKG_CONFIG_PATH=/usr/local/opencv3.4.1/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/opencv3.4.1/lib

编译:

g++ `pkg-config opencv --cflags` stereo-bm.cpp -o opencv `pkg-config opencv --libs`

你可能感兴趣的:(ubuntu16.04下基于opencv 3.4.1实现stereo-bm算法的双目视图的视差图)