This repository was archived by the owner on Feb 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLineExtracterLSD.cpp
More file actions
58 lines (54 loc) · 1.4 KB
/
Copy pathLineExtracterLSD.cpp
File metadata and controls
58 lines (54 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// LineExtracterLSD.cpp
// cvar_core
//
// Created by Daichi Sakai on 2013/01/13.
// Copyright (c) 2013 Daichi Sakai. All rights reserved.
//
// Extracting lines by LSD detector.
// See "LSD: a Line Segment Detector" http://www.ipol.im/pub/art/2012/gjmr-lsd/
#include "LineExtracterLSD.h"
void LineExtracterLSD::extractLine(const cv::Mat& gray, std::vector<Line>& lines, const double minlen)
{
const int cols = gray.cols;
const int rows = gray.rows;
double *dat = new double[rows*cols];
double *dp = dat;
for(int y = 0; y < rows; y++)
{
const unsigned char* sp = gray.ptr<unsigned char>(y);
for(int x = 0; x < cols; x++) {
(*dp) = sp[x];
++dp;
}
}
double* lsd_lines;
int n_lines;
lsd_lines = lsd_scale(&n_lines, dat, cols, rows, 1.0);
for(int i=0; i<n_lines; i++)
{
const double *l = &lsd_lines[i * 7];
if(10 < l[6]) // NFA
{
const double len = sqrt(cvmath::sqr(l[0]-l[2])+cvmath::sqr(l[1]-l[3]));
if (len>minlen) {
Line line(l[0], l[1], l[2], l[3]);
/*
line.x1[0] = l[0]; //x
line.x1[1] = l[1]; //y
line.x2[0] = l[2];
line.x2[1] = l[3];
line.mean[0] = (l[0]+l[2])/2;
line.mean[1] = (l[1]+l[3])/2;
//line.theta = theta; // not needed in process following?
//line.r = r;
line.l[0] = l[1] - l[3];
line.l[1] = l[2] - l[0];
line.l[2] = l[0]*l[3] - l[2]*l[1];
*/
lines.push_back(line);
}
}
}
delete [] dat;
}