Error with gpumat and mat

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 anyone know why?

+5
source share
2 answers

In current versions of OpenCV, the cv::Mat class does not have an overloaded assignment operator or copy constructor that takes an argument of type cv::gpu::GpuMat . Thus, the next line of your code will not compile.

 cv::Mat result_host = dst; 

There are 2 alternatives to this.

You can first pass dst as an argument to the result_host constructor.

 cv::Mat result_host(dst); 

Secondly, you can call the download dst function

 cv::Mat result_host; dst.download(result_host); 
+3
source

It seems that you should use the download method gpuMat to convert it to cv::Mat :

 //! downloads data from device to host memory. Blocking calls. void download(cv::Mat& m) const; 

See this document .

+2
source

Source: https://habr.com/ru/post/955934/


All Articles