Skip to content

Commit eed990a

Browse files
committed
Merge pull request #3130 from ToFam:ed_segment_getter
2 parents 1cecd2c + e90e9fc commit eed990a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ class CV_EXPORTS_W EdgeDrawing : public Algorithm
6767
CV_WRAP virtual void getEdgeImage(OutputArray dst) = 0;
6868
CV_WRAP virtual void getGradientImage(OutputArray dst) = 0;
6969

70+
/** @brief Returns std::vector<std::vector<Point>> of detected edge segments, see detectEdges()
71+
*/
7072
CV_WRAP virtual std::vector<std::vector<Point> > getSegments() = 0;
7173

74+
/** @brief Returns for each line found in detectLines() its edge segment index in getSegments()
75+
*/
76+
CV_WRAP virtual std::vector<int> getSegmentIndicesOfLines() const = 0;
77+
7278
/** @brief Detects lines.
7379
7480
@param lines output Vec<4f> contains start point and end point of detected lines.

modules/ximgproc/src/edge_drawing.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class EdgeDrawingImpl : public EdgeDrawing
109109
void getGradientImage(OutputArray dst) CV_OVERRIDE;
110110

111111
vector<vector<Point> > getSegments() CV_OVERRIDE;
112+
vector<int> getSegmentIndicesOfLines() const CV_OVERRIDE;
112113
void detectLines(OutputArray lines) CV_OVERRIDE;
113114
void detectEllipses(OutputArray ellipses) CV_OVERRIDE;
114115

@@ -120,6 +121,7 @@ class EdgeDrawingImpl : public EdgeDrawing
120121
int height; // height of source image
121122
uchar *srcImg;
122123
vector<vector<Point> > segmentPoints;
124+
vector<int> segmentIndicesOfLines;
123125
Mat smoothImage;
124126
uchar *edgeImg; // pointer to edge image data
125127
uchar *smoothImg; // pointer to smoothed image data
@@ -440,6 +442,11 @@ std::vector<std::vector<Point> > EdgeDrawingImpl::getSegments()
440442
return segmentPoints;
441443
}
442444

445+
std::vector<int> EdgeDrawingImpl::getSegmentIndicesOfLines() const
446+
{
447+
return segmentIndicesOfLines;
448+
}
449+
443450
void EdgeDrawingImpl::ComputeGradient()
444451
{
445452
for (int j = 0; j < width; j++)
@@ -1312,12 +1319,15 @@ void EdgeDrawingImpl::detectLines(OutputArray _lines)
13121319
for (int i = 1; i <= size - linesNo; i++)
13131320
lines.pop_back();
13141321

1322+
segmentIndicesOfLines.clear();
13151323
for (int i = 0; i < linesNo; i++)
13161324
{
13171325
Vec4f line((float)lines[i].sx, (float)lines[i].sy, (float)lines[i].ex, (float)lines[i].ey);
13181326
linePoints.push_back(line);
1327+
segmentIndicesOfLines.push_back(lines[i].segmentNo);
13191328
}
13201329
Mat(linePoints).copyTo(_lines);
1330+
13211331
delete[] x;
13221332
delete[] y;
13231333
}

0 commit comments

Comments
 (0)