OpenCV-cudaimgproc错误 [英] OpenCV - cudaimgproc errors

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

问题描述

我对OpenCV还是很陌生,所以我想为项目实现轮廓线.我从OpenCV文档中提取了houghlines.cpp.当我运行源文件时,似乎出现错误.我在Visual Studios 15上运行它,并且正在使用OpenCV 3.1.我对Cuda的了解并不多,并且刚刚被介绍给OpenCV,所以我确实需要更详尽的指导.谢谢.

I'm pretty new to OpenCV and I wanted to implement houghlines for a project. I pulled the houghlines.cpp from the OpenCV Docs. When I run the source file I seem to get an error. I run it on Visual Studios 15 and am using OpenCV 3.1. I don't really know much about Cuda and have just been introduced into the world of OpenCV, so I do require a more thorough guidance. Thank You.

#include <cmath>
#include <iostream>
#include "opencv2/core.hpp"
#include <opencv2/core/utility.hpp>
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/cudaimgproc.hpp"
using namespace std;
using namespace cv;
using namespace cv::cuda;
static void help()
{
    cout << "This program demonstrates line finding with the Hough transform." << endl;
    cout << "Usage:" << endl;
    cout << "./gpu-example-houghlines <image_name>, Default is ../data/pic1.png\n" << endl;
}
int main(int argc, const char* argv[])
{
    const string filename = argc >= 2 ? argv[1] : "../data/pic1.png";
    Mat src = imread(filename, IMREAD_GRAYSCALE);
    if (src.empty())
    {
        help();
        cout << "can not open " << filename << endl;
        return -1;
    }
    Mat mask;
    cv::Canny(src, mask, 100, 200, 3);
    Mat dst_cpu;
    cv::cvtColor(mask, dst_cpu, COLOR_GRAY2BGR);
    Mat dst_gpu = dst_cpu.clone();
    vector<Vec4i> lines_cpu;
    {
        const int64 start = getTickCount();
        cv::HoughLinesP(mask, lines_cpu, 1, CV_PI / 180, 50, 60, 5);
        const double timeSec = (getTickCount() - start) / getTickFrequency();
        cout << "CPU Time : " << timeSec * 1000 << " ms" << endl;
        cout << "CPU Found : " << lines_cpu.size() << endl;
    }
    for (size_t i = 0; i < lines_cpu.size(); ++i)
    {
        Vec4i l = lines_cpu[i];
        line(dst_cpu, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 3, LINE_AA);
    }
    GpuMat d_src(mask);
    GpuMat d_lines;
    {
        const int64 start = getTickCount();
        Ptr<cuda::HoughSegmentDetector> hough = cuda::createHoughSegmentDetector(1.0f, (float)(CV_PI / 180.0f), 50, 5);
        hough->detect(d_src, d_lines);
        const double timeSec = (getTickCount() - start) / getTickFrequency();
        cout << "GPU Time : " << timeSec * 1000 << " ms" << endl;
        cout << "GPU Found : " << d_lines.cols << endl;
    }
    vector<Vec4i> lines_gpu;
    if (!d_lines.empty())
    {
        lines_gpu.resize(d_lines.cols);
        Mat h_lines(1, d_lines.cols, CV_32SC4, &lines_gpu[0]);
        d_lines.download(h_lines);
    }
    for (size_t i = 0; i < lines_gpu.size(); ++i)
    {
        Vec4i l = lines_gpu[i];
        line(dst_gpu, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 3, LINE_AA);
    }
    imshow("source", src);
    imshow("detected lines [CPU]", dst_cpu);
    imshow("detected lines [GPU]", dst_gpu);
    waitKey();
    return 0;
}

错误LNK2019

未解决的外部符号"struct cv :: Ptr __cdecl cv :: cuda :: createHoughSegmentDetector(float,float,int,int,int)"(?createHoughSegmentDetector @ cuda @ cv @@ YA?AU?$ Ptr @ VHoughSegmentDetector @函式主要

unresolved external symbol "struct cv::Ptr __cdecl cv::cuda::createHoughSegmentDetector(float,float,int,int,int)" (?createHoughSegmentDetector@cuda@cv@@YA?AU?$Ptr@VHoughSegmentDetector@cuda@cv@@@2@MMHHH@Z) referenced in function main

推荐答案

编译时必须链接其他库.

An additional library must be linked when compiling.

在Windows中,库名称为 opencv_cudaimgproc310.lib .如果使用的是Visual Studio,则必须在[配置属性]-> [链接器]-> [输入]-> [其他依赖项]中添加库名称.

In Windows, the library name is opencv_cudaimgproc310.lib. If one is using Visual Studio, the library name must be added at [Configuration Properties] -> [Linker] -> [Input] -> [Additional Dependencies].

在Linux中,通常是 libopencv_cudaimgproc.so ,它是指向 libopencv_cudaimgproc.so.3.1 的符号链接,而这又是指向的符号链接.libopencv_cudaimgproc.so.3.1.0 ,它是实际的库.如果使用的是 g ++ ,则必须将 -lopencv_cudaimgproc 添加到 g ++ 命令中.

In Linux, it is typically libopencv_cudaimgproc.so, which is a symbolic link to libopencv_cudaimgproc.so.3.1, which in turn is a symbolic link to libopencv_cudaimgproc.so.3.1.0, which is the actual library. If one is using g++, -lopencv_cudaimgproc must be added to g++ command.

我假设在这两种环境中,库搜索路径都已正确设置,即它包含OpenCV库的路径.

I'm assuming that, in both environment, library search path is set properly, that is, it contains path to the OpenCV libraries.

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

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