Ask Your Question
0

stereoBM and SGBM not working

asked 2019-10-28 14:31:55 -0500

TakiEddine gravatar image

I am trying to test the OpenCV classes stereoBM and StereoSGBM classes. when compiling the code below using

g++ main.cpp -o app pkg-config --cflags --libs opencv I get this error, fatal error: opencv2/contrib/contrib.hpp: No such file or directory

I am using Ubuntu 18.04 on an ARM platform (ODROID-XU4), and I have installed OpenCV version 3.2 using Synaptic Package Manager. The libraries are installed as indicated in the picture. However, I cannot locate contrib.hpp

image description

#include "opencv2/core/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv2/contrib/contrib.hpp"  
#include <stdio.h>
#include <string.h>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
Mat g1, g2;
Mat disp, disp8;
char* method = argv[3];
g1 = imread(argv[1]);
g2 = imread(argv[2]);
//cvtColor(img1, g1, CV_BGR2GRAY);
//cvtColor(img2, g2, CV_BGR2GRAY);

if (!(strcmp(method, "BM")))
{
    StereoBM sbm;
    sbm.state->SADWindowSize = 9;
    sbm.state->numberOfDisparities = 112;
    sbm.state->preFilterSize = 5;
    sbm.state->preFilterCap = 61;
    sbm.state->minDisparity = -39;
    sbm.state->textureThreshold = 507;
    sbm.state->uniquenessRatio = 0;
    sbm.state->speckleWindowSize = 0;
    sbm.state->speckleRange = 8;
    sbm.state->disp12MaxDiff = 1;
    sbm(g1, g2, disp);
}
else if (!(strcmp(method, "SGBM")))
{
    StereoSGBM sbm;
    sbm.SADWindowSize = 3;
    sbm.numberOfDisparities = 144;
    sbm.preFilterCap = 63;
    sbm.minDisparity = -39;
    sbm.uniquenessRatio = 10;
    sbm.speckleWindowSize = 100;
    sbm.speckleRange = 32;
    sbm.disp12MaxDiff = 1;
    sbm.fullDP = false;
    sbm.P1 = 216;
    sbm.P2 = 864;
    sbm(g1, g2, disp);
}


normalize(disp, disp8, 0, 255, CV_MINMAX, CV_8U);

imshow("left", g1;
imshow("right", g2);
imshow("disp", disp8);

waitKey(0);

return(0);
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-10-28 14:48:27 -0500

berak gravatar image

updated 2019-10-29 00:47:50 -0500

your code is from (no more maintained) opencv2.4 and won't run with 3.x

3.x and upwards have a opencv_contrib repo, not a single module, from your screenshot, it rather looks like the ubuntu maintainers fouled up.

but you don't need anything from the contrib modules to run the stereo matching code, so remove those bogus contrib things from your project/makefile.

also, please discard your dead 2.4 code and start again with code that fits your version

edit flag offensive delete link more

Comments

@break Thanks for the remark, the code in the link you listed compiled successfully, however, it's a little bit confusing and I don't know how to use it.

TakiEddine gravatar imageTakiEddine ( 2019-10-29 04:45:35 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-10-28 14:31:55 -0500

Seen: 115 times

Last updated: Oct 29 '19