Skip to content

Commit e0f2bf9

Browse files
committed
EdgeDrawing: Use getter for segment index
1 parent f78d484 commit e0f2bf9

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,20 @@ 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.
75-
@param segments output vector containing the edge segment index for each line, see getSegments()
7681
@note you should call detectEdges() method before call this.
7782
*/
78-
CV_WRAP virtual void detectLines(OutputArray lines, OutputArray segments = cv::noArray()) = 0;
83+
CV_WRAP virtual void detectLines(OutputArray lines) = 0;
7984

8085
/** @brief Detects circles and ellipses.
8186

modules/ximgproc/src/edge_drawing.cpp

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

111111
vector<vector<Point> > getSegments() CV_OVERRIDE;
112-
void detectLines(OutputArray lines, OutputArray segments = cv::noArray()) CV_OVERRIDE;
112+
vector<int> getSegmentIndicesOfLines() const CV_OVERRIDE;
113+
void detectLines(OutputArray lines) CV_OVERRIDE;
113114
void detectEllipses(OutputArray ellipses) CV_OVERRIDE;
114115

115116
virtual void read(const FileNode& fn) CV_OVERRIDE;
@@ -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++)
@@ -1263,7 +1270,7 @@ int EdgeDrawingImpl::RetrieveChainNos(Chain* chains, int root, int chainNos[])
12631270
return count;
12641271
}
12651272

1266-
void EdgeDrawingImpl::detectLines(OutputArray _lines, OutputArray _lineSegments)
1273+
void EdgeDrawingImpl::detectLines(OutputArray _lines)
12671274
{
12681275
std::vector<Vec4f> linePoints;
12691276
if (segmentPoints.size() < 1)
@@ -1312,18 +1319,14 @@ void EdgeDrawingImpl::detectLines(OutputArray _lines, OutputArray _lineSegments)
13121319
for (int i = 1; i <= size - linesNo; i++)
13131320
lines.pop_back();
13141321

1315-
std::vector<int> lineSegmentIndices;
1322+
segmentIndicesOfLines.clear();
13161323
for (int i = 0; i < linesNo; i++)
13171324
{
13181325
Vec4f line((float)lines[i].sx, (float)lines[i].sy, (float)lines[i].ex, (float)lines[i].ey);
13191326
linePoints.push_back(line);
1320-
lineSegmentIndices.push_back(lines[i].segmentNo);
1327+
segmentIndicesOfLines.push_back(lines[i].segmentNo);
13211328
}
13221329
Mat(linePoints).copyTo(_lines);
1323-
if (_lineSegments.needed())
1324-
{
1325-
Mat(lineSegmentIndices).copyTo(_lineSegments);
1326-
}
13271330

13281331
delete[] x;
13291332
delete[] y;

0 commit comments

Comments
 (0)