OpenCV3中StereoBM函数的用法

OpenCV更新到3.0版本后,Stereo模块变化的挺多的,首先去掉了StereoBMState和StereoSGBMState这两个专门控制BM和SGBM算法参数的类,而且StereoBM不能直接声明实例,需要放到智能指针里cv::Ptr声明才行,而且不能直接通过访问state来访问参数,只能通过setter和getter方法来设置和获取参数,参考下面这段实例代码:
cv::Ptr bm = cv::StereoBM::create(16,9);

// setter
bm->setPreFilterType(CV_STEREO_BM_NORMALIZED_RESPONSE);
bm->setPreFilterSize(9);
bm->setPreFilterCap(31);
bm->setBlockSize(21);
bm->setMinDisparity(-16);
bm->setNumDisparities(64);
bm->setTextureThreshold(10);
bm->setUniquenessRatio(5);
bm->setSpeckleWindowSize(100);
bm->setSpeckleRange(32);
bm->setROI1(roi_left);
bm->setROI2(roi_right);

// getter
int pfs = bm->getPreFilterSize();
int pfc = bm->getPreFilterCap();
int bs = bm->getBlockSize();
int md = bm->getMinDisparity();
int nd = bm->getNumDisparities();
int tt = bm->getTextureThreshold();
int ur = bm->getUniquenessRatio();
int sw = bm->getSpeckleWindowSize();
int sr = bm->getSpeckleRange();

// Compute disparity
bm->compute(left, right, disp);

注意新版本下的BM和SGBM方法计算出的视差都是CV_16S格式的,使用32位float格式可以得到真实的视差值,所以我们需要除以16,需要加上下面一行代码:

// Convert
disp.convertTo(disp, CV_32F, 1.0/16);


转载链接:https://www.cnblogs.com/grandyang/p/5805261.html



你可能感兴趣的:(OpenCV3中StereoBM函数的用法)