EdgeDrawing: Add getter for line edge segments

pull/3130/head
ToFam 3 years ago
parent 8bd63161fe
commit e90e9fccee
  1. 6
      modules/ximgproc/include/opencv2/ximgproc/edge_drawing.hpp
  2. 10
      modules/ximgproc/src/edge_drawing.cpp

@ -67,8 +67,14 @@ public:
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.

@ -109,6 +109,7 @@ public:
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;
@ -120,6 +121,7 @@ protected:
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
@ -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++)
@ -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;
}

Loading…
Cancel
Save