using namespace std;
using namespace cv;
using namespace cv::ximgproc;
班级立体声的功能:
void stereo_matcher::cpu_sgbm_matcher(cv::Mat& IL, cv::Mat& IR, int min_disp, int max_disp)
{
int cn = IL.channels();
int winsize =9; //3
// Ptr<StereoSGBM> sgbm = StereoSGBM::create(0,256,9,0,0,1,63);
Ptr<StereoSGBM> left_matcher = StereoSGBM::create(0,max_disp,winsize);
left_matcher->setPreFilterCap(63);
left_matcher->setBlockSize(winsize);
left_matcher->setP1(8*cn*winsize*winsize); //8
left_matcher->setP2(32*cn*winsize*winsize); //32
left_matcher->setMinDisparity(min_disp);
left_matcher->setNumDisparities(max_disp);
left_matcher->setUniquenessRatio(10);
left_matcher->setSpeckleWindowSize(100);
left_matcher->setSpeckleRange(32);
left_matcher->setDisp12MaxDiff(1);
left_matcher->setMode(StereoSGBM::MODE_HH);
left_matcher->compute(IL, IR, disp16L);
Ptr<StereoMatcher> right_matcher = createRightMatcher(left_matcher);
right_matcher->compute(IR, IL, disp16R);
// cout<<disp16L<<endl;
Mat filtered_disp;
Mat conf_map = Mat(IL.rows,IL.cols,CV_8U);
conf_map = Scalar(255);
Ptr<DisparityWLSFilter> wls_filter=createDisparityWLSFilter(left_matcher);
// wls_filter = createDisparityWLSFilter(left_matcher);
cout<<"Here§§"<<endl;
wls_filter->setLambda(8000);
wls_filter->setSigmaColor(1.5);
double filtering_time = (double)getTickCount();
wls_filter->filter(disp16L,IL,filtered_disp,disp16R);
filtering_time = ((double)getTickCount() - filtering_time)/getTickFrequency();
cout<<"Filtering time: "<<filtering_time<<"s"<<endl;
disp16L=filtered_disp.clone();
disp16L.convertTo(disp32F, CV_32F,(double)1.0/(16.0),0.0);
// //! [visualization]
// double vis_mult=1.0;
// Mat raw_disp_vis;
// cv::ximgproc::getDisparityVis(disp16L,raw_disp_vis,vis_mult);
// namedWindow("raw disparity", WINDOW_AUTOSIZE);
// imshow("raw disparity", raw_disp_vis);
// Mat filtered_disp_vis;
// cv::ximgproc::getDisparityVis(filtered_disp,filtered_disp_vis,vis_mult);
// namedWindow("filtered disparity", WINDOW_AUTOSIZE);
// imshow("filtered disparity", filtered_disp_vis);
// waitKey(0);
// //! [visualization]
}
我做了什么: 我发现以下示例: https://github.com/Itseez/opencv_contrib/blob/master/modules/ximgproc/samples/disparity_filtering.cpp
我已经从以下程序安装了Opencv额外模块: https://github.com/Itseez/opencv_contrib
问题: 即使我的IDE(Qt)识别出头文件
编译时出现以下错误:
../../lib/libstereo.a(stereo_matcher.cpp.o):在函数stereo_matcher::cpu_sgbm_matcher(cv::Mat&, cv::Mat&, int, int)':
stereo_matcher.cpp:(.text+0xcc9): undefined reference to
cv :: ximgproc :: createDisparityWLSFilter(cv :: Ptr)&#39;
collect2:错误:ld返回1退出状态
make [2]: * [../bin/test_stereo]错误1
make [1]:* [apps / CMakeFiles / test_stereo.dir / all]错误2
如何链接此OpenCV库
提前感谢您提供帮助
答案 0 :(得分:0)
在Qt Creator中,我添加了.pro文件行LIBS += -lopencv_ximgproc
,它对我有所帮助。 (Qt 5.11,OpenCV 3.2,Linux Ubuntu 18.04)
INCLUDEPATH += /usr/local/include/opencv
....
LIBS += -lopencv_ximgproc
您应该在文件夹/usr/local/include/opencv
库文件中
libopencv_ximgproc.so