CUDA::StereoSGM can not run

Bay_Esan
Tue, 28 Feb 2023 12:34:29 +0000
C++

Hey friends. I’m writing a program to calculate the parallax using a binocular camera. Since the calculation speed of the CPU is too slow, I plan to use the cuda function to speed up the stereo matching operation, but the program cannot run. I already have two images Left.jpg and Right.jpg that have been registered using the remap function in the root directory. When I use the following code to read the image and calculate the disparity, it prompts an error

error: (-217:Gpu API call) out of memory in function 'allocate'.

When I set the numDisparities parameter to 128, the program can run, but in my simple knowledge, the MX250 has 2g of video memory, and there should be no problem of insufficient video memory when processing two pictures.I don’t know what is wrong with my code，and i am asking for some help.
Below is my program code:

int main()
{
    using namespace cv;
    using namespace cuda;
    GpuMat left,right,disp;
    left.upload(imread("./Left.jpg",ImreadModes::IMREAD_GRAYSCALE));
    right.upload(imread("./Right.jpg",ImreadModes::IMREAD_GRAYSCALE));
    Ptr<cuda::StereoSGM> sgm = cuda::createStereoSGM(0,256);
    sgm->compute(left,right,disp);
    Mat now;
    disp.download(now);
    now.convertTo(now,CV_32F,1.0/16);

    namedWindow("--",0);
    resizeWindow("--",Size(800,600));
    imshow("--",now);
    waitKey(0);
    return 0;
}

The environment I use is Ubuntu22.04, i5-8265u MX250 graphics card and 16G RAM.
I cloned the 4.x branch and the opencv_contrib branch in the GitHub repository of opencv, compiled the opencv library and completed the installation.

10 posts - 3 participants