gpt4 book ai didi

c++ - gpumat 和 mat 错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:25:36 24 4
gpt4 key购买 nike

当我编译这个例子时:

#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;
}

我收到以下错误:

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 类型参数的复制构造函数.因此,您的以下代码行将无法编译。

cv::Mat result_host = dst;

有两种选择。

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

cv::Mat result_host(dst);

其次是可以调用dstdownload函数

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

关于c++ - gpumat 和 mat 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14468191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com