Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/ximgproc/include/opencv2/ximgproc/edge_drawing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ class CV_EXPORTS_W EdgeDrawing : public Algorithm
CV_WRAP virtual void getEdgeImage(OutputArray dst) = 0;
CV_WRAP virtual void getGradientImage(OutputArray dst) = 0;

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

/** @brief Returns for each line found in detectLines() its edge segment index in getSegments()
*/
CV_WRAP virtual std::vector<int> getSegmentIndicesOfLines() const = 0;

/** @brief Detects lines.

@param lines output Vec<4f> contains start point and end point of detected lines.
Expand Down
10 changes: 10 additions & 0 deletions modules/ximgproc/src/edge_drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class EdgeDrawingImpl : public EdgeDrawing
void getGradientImage(OutputArray dst) CV_OVERRIDE;

vector<vector<Point> > getSegments() CV_OVERRIDE;
vector<int> getSegmentIndicesOfLines() const CV_OVERRIDE;
void detectLines(OutputArray lines) CV_OVERRIDE;
void detectEllipses(OutputArray ellipses) CV_OVERRIDE;

Expand All @@ -120,6 +121,7 @@ class EdgeDrawingImpl : public EdgeDrawing
int height; // height of source image
uchar *srcImg;
vector<vector<Point> > segmentPoints;
vector<int> segmentIndicesOfLines;
Mat smoothImage;
uchar *edgeImg; // pointer to edge image data
uchar *smoothImg; // pointer to smoothed image data
Expand Down Expand Up @@ -440,6 +442,11 @@ std::vector<std::vector<Point> > EdgeDrawingImpl::getSegments()
return segmentPoints;
}

std::vector<int> EdgeDrawingImpl::getSegmentIndicesOfLines() const
{
return segmentIndicesOfLines;
}

void EdgeDrawingImpl::ComputeGradient()
{
for (int j = 0; j < width; j++)
Expand Down Expand Up @@ -1312,12 +1319,15 @@ void EdgeDrawingImpl::detectLines(OutputArray _lines)
for (int i = 1; i <= size - linesNo; i++)
lines.pop_back();

segmentIndicesOfLines.clear();
for (int i = 0; i < linesNo; i++)
{
Vec4f line((float)lines[i].sx, (float)lines[i].sy, (float)lines[i].ex, (float)lines[i].ey);
linePoints.push_back(line);
segmentIndicesOfLines.push_back(lines[i].segmentNo);
}
Mat(linePoints).copyTo(_lines);

delete[] x;
delete[] y;
}
Expand Down