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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肥宅程序员aka不会游泳的鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值