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

linux c++ 编译链接 opencv

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

你可能感兴趣的:(opencv,c++,计算机视觉)