编译错误cv :: gpu

时间:2013-10-14 19:58:12

标签: c++ opencv

我在Ubuntu 12.04上使用OpenCV master branch(3.0.0.dev)和CUDA,并尝试使用gpu代码编译以下opencv:

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"

using namespace cv;

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

编译命令是:

g++ testgpu.cpp -o test `pkg-config --cflags --libs opencv` -lopencv_gpu

它有以下编译错误:

testgpu.cpp: In function ‘int main(int, char**)’:
testgpu.cpp:13:51: error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
         cv::Mat src_host = cv::imread("file.png", CV_LOAD_IMAGE_GRAYSCALE);
                                                   ^
testgpu.cpp:17:52: error: ‘CV_THRESH_BINARY’ was not declared in this scope
         cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);
                                                    ^
testgpu.cpp:19:31: error: conversion from ‘cv::gpu::GpuMat’ to non-scalar type ‘cv::Mat’ requested
         cv::Mat result_host = dst;
                           ^

安装OpenCV或Opencv 3.0.0中的API更改有问题吗?

2 个答案:

答案 0 :(得分:22)

在OpenCV 3.0中重新设计了gpu模块。它被拆分为几个模块,它被重命名为cudagpu::命名空间被重命名为cuda::。 OpenCV 3.0的正确代码:

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudaarithm.hpp"

using namespace cv;

int main (int argc, char* argv[])
{
    try
    {
        cv::Mat src_host = cv::imread("file.png", cv::IMREAD_GRAYSCALE);
        cv::cuda::GpuMat dst, src;
        src.upload(src_host);
        cv::cuda::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;
}

答案 1 :(得分:7)

啊,他们一直在玩大师的常数。预计CV_*前缀几乎在任何地方删除(类型CV_8U除外,等等仍然存在)。

所以它是cv::THRESH_BINARYcv::LOAD_IMAGE_GRAYSCALE,但是...... cv::COLOR_BGR2GRAY(你现在没有使用它,但我会饶你搜索;)

抱歉,我没有使用GPU的经验,所以我无法解决那里的最后一个谜语。

相关问题