Skip to content

Commit f78d484

Browse files
committed
EdgeDrawing: Add output of segment index for line detection
1 parent 8bd6316 commit f78d484

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

modules/ximgproc/include/opencv2/ximgproc/edge_drawing.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ class CV_EXPORTS_W EdgeDrawing : public Algorithm
7272
/** @brief Detects lines.
7373
7474
@param lines output Vec<4f> contains start point and end point of detected lines.
75+
@param segments output vector containing the edge segment index for each line, see getSegments()
7576
@note you should call detectEdges() method before call this.
7677
*/
77-
CV_WRAP virtual void detectLines(OutputArray lines) = 0;
78+
CV_WRAP virtual void detectLines(OutputArray lines, OutputArray segments = cv::noArray()) = 0;
7879

7980
/** @brief Detects circles and ellipses.
8081

modules/ximgproc/src/edge_drawing.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class EdgeDrawingImpl : public EdgeDrawing
109109
void getGradientImage(OutputArray dst) CV_OVERRIDE;
110110

111111
vector<vector<Point> > getSegments() CV_OVERRIDE;
112-
void detectLines(OutputArray lines) CV_OVERRIDE;
112+
void detectLines(OutputArray lines, OutputArray segments = cv::noArray()) CV_OVERRIDE;
113113
void detectEllipses(OutputArray ellipses) CV_OVERRIDE;
114114

115115
virtual void read(const FileNode& fn) CV_OVERRIDE;
@@ -1263,7 +1263,7 @@ int EdgeDrawingImpl::RetrieveChainNos(Chain* chains, int root, int chainNos[])
12631263
return count;
12641264
}
12651265

1266-
void EdgeDrawingImpl::detectLines(OutputArray _lines)
1266+
void EdgeDrawingImpl::detectLines(OutputArray _lines, OutputArray _lineSegments)
12671267
{
12681268
std::vector<Vec4f> linePoints;
12691269
if (segmentPoints.size() < 1)
@@ -1312,12 +1312,19 @@ void EdgeDrawingImpl::detectLines(OutputArray _lines)
13121312
for (int i = 1; i <= size - linesNo; i++)
13131313
lines.pop_back();
13141314

1315+
std::vector<int> lineSegmentIndices;
13151316
for (int i = 0; i < linesNo; i++)
13161317
{
13171318
Vec4f line((float)lines[i].sx, (float)lines[i].sy, (float)lines[i].ex, (float)lines[i].ey);
13181319
linePoints.push_back(line);
1320+
lineSegmentIndices.push_back(lines[i].segmentNo);
13191321
}
13201322
Mat(linePoints).copyTo(_lines);
1323+
if (_lineSegments.needed())
1324+
{
1325+
Mat(lineSegmentIndices).copyTo(_lineSegments);
1326+
}
1327+
13211328
delete[] x;
13221329
delete[] y;
13231330
}

0 commit comments

Comments
 (0)