opencv 3.1 Display Driver Stopped Responding when using canny in opencl

asked 2016-01-20 18:15:12 -0600

gino0717 gravatar image

I am trying to use opencl in opencv 3.1.0 , I copy some of the code in tutorials. However, my computer always shows " Display Driver Stopped Responding " message and crash.

and there are my code:

    VideoCapture cap(0); // open the default camera         

    UMat edges;
    UMat fgMaskMOG2;
    Ptr<BackgroundSubtractor> pMOG2;

    pMOG2 = createBackgroundSubtractorMOG2(500, 20.0, false);

    for (;;)
    {

         UMat frame;
         UMat frame2 = frame.clone();
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, COLOR_BGR2GRAY);
        GaussianBlur(edges, edges, cv::Size(7, 7), 1.5, 1.5);
    //  Canny(edges, edges, 0, 30, 3);   // The program always crashes here and shows " Display Driver Stopped Responding "
        pMOG2->apply(frame, fgMaskMOG2);
        imshow("edges", edges);
        imshow("edges2", frame);
        imshow("FG Mask MOG 2", fgMaskMOG2);

        if (waitKey(30) >= 0) break;
    }

I think in opencv3.1.0, If I want to use gpu, all I need to do is change "Mat" into "UMat", the code work fine if there is no Canny , How should I do to use Canny if I want to use opencl in opencv? Thanks for your help and sorry for my poor English.

edit retag flag offensive close merge delete

Comments

Are you sure that the lower threshold should be 0?

matman gravatar imagematman ( 2016-01-21 01:16:57 -0600 )edit

I think in opencv3.1.0, If I want to use gpu, all I need to do is change "Mat" into "UMat"

Well that actually depends. It is true if you want to address your GPU through OpenCL, however if you have an NVIDIA GPU, you will need to builtin CUDA into your OpenCV installation.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-01-21 04:07:29 -0600 )edit
2

@StevePuttermans: Thats not correct. Nvidia supports OpenCL, too. But I'm actually not sure if you need to install CUDA on your system to get the Nvidia OpenCL support. My program runs fine on Nvidia GPU using UMat without OpenCV with CUDA buildin.

matman gravatar imagematman ( 2016-01-21 12:57:31 -0600 )edit

@matman Since the code work fine if using Mat instead of UMat, I don't think the threshold=0 should be the problem. If so, the code would throw the exception instead of stoping the display driver. I also tried other value of the threshold, and there is still the same problem.

@StevenPuttemans I think OpenCL is already intrinic in the driver.

gino0717 gravatar imagegino0717 ( 2016-01-22 21:26:41 -0600 )edit