我对OpenCV很陌生,我想为项目实现houghlines。我从OpenCV Docs中提取了houghlines.cpp。当我运行源文件时,我似乎得到一个错误。我在Visual Studios 15上运行它并使用OpenCV 3.1。我对Cuda的了解并不多,而且刚刚被介绍到OpenCV的世界,所以我需要更全面的指导。谢谢。
#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 @ cuda @ cv @@@ 2 @ MMHHH @ Z)在函数main
中引用答案 0 :(得分:0)
编译时必须链接其他库。
在Windows中,库名称为opencv_cudaimgproc310.lib
。如果使用Visual Studio,则必须在[配置属性] - &gt;中添加库名称。 [链接器] - &gt; [输入] - &gt; [附加依赖]。
在Linux中,它通常是libopencv_cudaimgproc.so
,它是libopencv_cudaimgproc.so.3.1
的符号链接,而libopencv_cudaimgproc.so.3.1.0
又是g++
的符号链接,它是实际的库。如果正在使用-lopencv_cudaimgproc
,则必须将g++
添加到 var LNSDict: NSDictionary;
LCFDict: CFDictionaryRef;
LCFDict := DADiskCopyDescription(lDisk);
try
LNSDict:= TNSDictionary.Wrap(LCFDict );
finally
CFRelease(LCFDict);
end;
命令。
我假设在这两种环境中,库搜索路径设置正确,也就是说,它包含OpenCV库的路径。