When I compile this example:
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"
int main (int argc, char* argv[])
{
try
{
cv::Mat src_host = cv::imread("file.png", CV_LOAD_IMAGE_GRAYSCALE);
cv::gpu::GpuMat dst, src;
src.upload(src_host);
cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);
cv::Mat result_host = dst;
cv::imshow("Result", result_host);
cv::waitKey();
}
catch(const cv::Exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
return 0;
}
I got the following error:
threshold.cpp: In function ‘int main(int, char**)’:
threshold.cpp:19: error: conversion from ‘cv::gpu::GpuMat’ to non-scalar type ‘cv::Mat’ requested
Does anybody knows why?
In the current versions of OpenCV, the cv::Mat
class has no overloaded assignment operator or copy constructor which takes argument of type cv::gpu::GpuMat
. So the following line of your code will not compile.
cv::Mat result_host = dst;
There are 2 alternatives to this.
First you can pass the dst
as the argument of the constructor of result_host
.
cv::Mat result_host(dst);
Second is that you can call the download
function of dst
cv::Mat result_host;
dst.download(result_host);
It seems that you should use download
method of gpuMat
to convert it to cv::Mat
:
//! downloads data from device to host memory. Blocking calls.
void download(cv::Mat& m) const;
See this doc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With