本文主要是介绍opencv3.4使用lsd线段检测提示异常解决办法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一下午被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 1Ptr<LineSegmentDetector> lsd = createLineSegmentDetector(LSD_REFINE_STD);#elsePtr<LineSegmentDetector> lsd = createLineSegmentDetector(LSD_REFINE_NONE);#endifdouble 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里面报错的头文件,就可以了。
最后开心地得到了结果:
这篇关于opencv3.4使用lsd线段检测提示异常解决办法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!