OpenCV GpuMat usage

12,746

Solution 1

The solution is:

Mat src;

src = cv::imread("...");

GpuMat dst;

dst.upload(src);

Solution 2

I believe it throws the assert in the GpuMat constructor because your call to imread returns null, and hence your Gpu Matrix is empty / not defined.

This means that your image can not be read probably due because of missing file, improper permissions or an unsupported or invalid format.

Verify that baboon.jpg exists in the same directory as where you are running your program, also verify that your image file has the correct permissions and isn't corrupt.

Share:
12,746
JohnnyAce
Author by

JohnnyAce

Updated on June 08, 2022

Comments

  • JohnnyAce
    JohnnyAce almost 2 years

    I'm trying to use OpenCV GpuMat but I'm getting an assert error, my code is as follows

    #include "opencv2/opencv.hpp"
    #include "opencv2/imgproc/imgproc.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/gpu/gpu.hpp"
    
    // ...
    
    using namespace cv;
    using namespace cv::gpu;
    
    int main()
    {
        string baboon = "baboon.jpg";
        try
        {
            DeviceInfo info = getDevice();
            cout << info.name() << endl;
    
            GpuMat src;
    
            src = cv::imread(baboon, 1);
        }
        catch (const cv::Exception* ex)
        {
            cout << "Error: " << ex->what() << endl;
        }
    }
    

    The output is:

    GeForce GTX 550 Ti
    OpenCV Error: Assertion failed (!m.empty()) in unknown function, file ($PATH_TO_OPENCV)\opencv\modules\gpu\src\gpumat.cpp, line 411
    

    Any ideas on how to solve this problem?

  • David Doria
    David Doria over 10 years
    Shouldn't it just be dst.upload(src); ?