gpumat和垫错误 [英] error with gpumat and mat

查看:100
本文介绍了gpumat和垫错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编译此示例时:

#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

有人知道为什么吗?

推荐答案

在当前版本的OpenCV中,cv::Mat类没有使用参数cv::gpu::GpuMat类型的重载赋值运算符或复制构造函数.因此,下面的代码行将无法编译.

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;

有2种替代方法.

首先,您可以将dst作为result_host的构造函数的参数传递.

First you can pass the dst as the argument of the constructor of result_host.

cv::Mat result_host(dst);

第二个是您可以调用dst

cv::Mat result_host;
dst.download(result_host);

这篇关于gpumat和垫错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆