一下午被opencv3.4里面lsd提示异常(因为许可问题)拖住了
#include <opencv2/core/core.hpp>
#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodes.hpp>
#include <iostream>
#include <string>
using namespace std;
using namespace cv;
int main()
{
cv::Mat srcImage = cv::imread();
Canny(srcImage,srcImage,50,200,3);
#if 1
Ptr<LineSegmentDetector> lsd = createLineSegmentDetector(LSD_REFINE_STD);
#else
Ptr<LineSegmentDetector> lsd = createLineSegmentDetector(LSD_REFINE_NONE);
#endif
double start = double(getTickCount());
vector<Vec4f> vecLines;
double times = (double(getTickCount()) - start) * 1000 / getTickFrequency();
std::cout<<"times:" <<times<<"ms"<<std::endl;
cv::Mat reslineMat(srcImage);
lsd->drawSegments(reslineMat,vecLines);
cv::imshow("reslineMat",reslineMat);
cv::waitKey();
return 0;
}
附上代码出处
https://blog.csdn.net/qq_35789421/article/details/89208349
以上代码编译是有问题的:
(1)Canny(srcImage,srcImage,50,200,3); 提示异常,要新创建一个Mat对象替换第二个参数
(2)Ptr lsd = createLineSegmentDetector(LSD_REFINE_STD); 提示异常,这就是因为lsd许可问题了
【解决办法】
下载opencv3.1,在…\opencv-3.1.0\modules\imgproc\src路径下复制lsd.cpp和precomp.hpp文件到工程目录下,再在解决方案里导入这两个文件,编译,注释掉precomp.hpp里面报错的头文件,就可以了。
最后开心地得到了结果: