Reputation: 3739
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?
Upvotes: 1
Views: 13369
Reputation: 16086
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.
Upvotes: 4
Reputation: 550
The solution is:
Mat src;
src = cv::imread("...");
GpuMat dst;
dst.upload(src);
Upvotes: 7