linux c++ 使用opencv 中lsd函数 测试代码

linux c++ 编译链接 opencv

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
//g++ test.cpp `pkg-config opencv --libs --cflags` -o test
int main()
{
    
    
    cout << "hello world" << endl;
	Mat image = imread("edge.png");
	Mat grayImage;
	cvtcolor(image, grayimage, cv_bgr2gray);

	ptr<linesegmentdetector> ls = createlinesegmentdetector(
		/*refine */ lsd_refine_std, /* scale*/ 0.8,
		/* sigma_scale */ 0.6, /*quant*/2.0, /*ang_th */22.5,
		/*log_eps*/0, /*_density_th*/0.75);

	vector<vec4f> lines_std;
	// detect the lines
	ls->detect(grayimage, lines_std);//这里把检测到的直线线段都存入了lines_std中,4个float的值,分别为起止点的坐标
	ofstream outfile("test.txt"); //利用构造函数创建txt文本,并且打开该文本
	for (int i = 0; i < lines_std.size(); i++)
	{
    
    
		cout << lines_std[i][0] << " " << lines_std[i][1] << " "
			<< lines_std[i][2] << " " << lines_std[i][3] << endl;

		outfile << lines_std[i][0] << " " << lines_std[i][1] << " "
					<< lines_std[i][2] << " " << lines_std[i][3] << endl;
	}	
	
	outfile.close(); //关闭test.txt文件

	show found lines
	mat drawnlines(image);
	ls->drawsegments(drawnlines, lines_std);
	imwrite("drawnLines.png", image);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42280271/article/details/126546176
今日推荐