Skip to content

Commit b56c79c

Browse files
committed
additional improvements and documentation of class
1 parent a37a17a commit b56c79c

File tree

7 files changed

+242
-126
lines changed

7 files changed

+242
-126
lines changed

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

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,72 @@ class CV_EXPORTS_W EdgeDrawing : public Algorithm
4141
LSD = 3
4242
};
4343

44+
struct CV_EXPORTS_W_SIMPLE Params
45+
{
46+
CV_WRAP Params();
47+
//! Parameter Free mode will be activated when this value is true.
48+
CV_PROP_RW bool PFmode;
49+
//! indicates the operator used for gradient calculation.The following operation flags are available(cv::ximgproc::EdgeDrawing::GradientOperator)
50+
CV_PROP_RW int EdgeDetectionOperator;
51+
//! threshold value used to create gradient image.
52+
CV_PROP_RW int GradientThresholdValue;
53+
//! threshold value used to create gradient image.
54+
CV_PROP_RW int AnchorThresholdValue;
55+
CV_PROP_RW int ScanInterval;
56+
//! minimun connected pixels length processed to create an edge segment.
57+
CV_PROP_RW int MinPathLength;
58+
//! sigma value for internal GaussianBlur() function.
59+
CV_PROP_RW float Sigma;
60+
CV_PROP_RW bool SumFlag;
61+
//! when this value is true NFA (Number of False Alarms) algorithm will be used for line and ellipse validation.
62+
CV_PROP_RW bool NFAValidation;
63+
//! minimun line length to detect.
64+
CV_PROP_RW int MinLineLength;
65+
CV_PROP_RW double MaxDistanceBetweenTwoLines;
66+
CV_PROP_RW double LineFitErrorThreshold;
67+
CV_PROP_RW double MaxErrorThreshold;
68+
69+
void read(const FileNode& fn);
70+
void write(FileStorage& fs) const;
71+
};
72+
73+
/** @brief Detects edges and prepares them to detect lines and ellipses.
74+
75+
@param src input image
76+
*/
4477
CV_WRAP virtual void detectEdges(InputArray src) = 0;
4578
CV_WRAP virtual void getEdgeImage(OutputArray dst) = 0;
4679
CV_WRAP virtual void getGradientImage(OutputArray dst) = 0;
4780

4881
CV_WRAP virtual std::vector<std::vector<Point> > getSegments() = 0;
4982

50-
CV_WRAP virtual void detectLines(OutputArray lines, bool validate = true,
51-
int MinLineLength = -1, double LineError = 1.0,
52-
double MaxDistanceBetweenTwoLines = 6.0, double MaxError = 1.3) = 0;
53-
CV_WRAP virtual void detectEllipses(OutputArray ellipses, bool validate = true) = 0;
83+
/** @brief Detects lines.
84+
85+
@param lines output Vec<4f> contains start point and end point of detected lines.
86+
@note you should call detectEdges() method before call this.
87+
*/
88+
CV_WRAP virtual void detectLines(OutputArray lines) = 0;
89+
90+
/** @brief Detects circles and ellipses.
5491
92+
@param ellipses output Vec<6d> contains center point and perimeter for circles.
93+
@note you should call detectEdges() method before call this.
94+
*/
95+
CV_WRAP virtual void detectEllipses(OutputArray ellipses) = 0;
96+
97+
CV_WRAP Params params;
98+
99+
/** @brief sets parameters.
100+
101+
this function is meant to be used for parameter setting in other languages than c++.
102+
*/
103+
CV_WRAP void setParams(EdgeDrawing::Params parameters);
55104
virtual ~EdgeDrawing() { }
56105
};
57106

58107
/** @brief Creates a smart pointer to a EdgeDrawing object and initializes it
59-
60-
@param EdgeDetectionOperator The following operation flags are available (cv::ximgproc::EdgeDrawing::GradientOperator)
61-
@param GradientThresholdValue threshold value used to create gradient image. if this value is 0 then
62-
parameter free (EDPF) used internally.
63-
@param AnchorThresholdValue threshold value used to find anchor points.
64-
@param ScanningInterval
65-
@param MinPathLength Segments shorter than this value will be discarded.
66-
@param Sigma sigma value used internal GaussianBlur() function.
67-
@param SumFlag
68108
*/
69-
CV_EXPORTS_W Ptr<EdgeDrawing> createEdgeDrawing(int EdgeDetectionOperator = EdgeDrawing::SOBEL,
70-
int GradientThresholdValue = 20, int AnchorThresholdValue = 0, int ScanningInterval = 1,
71-
int MinPathLength = 10, double Sigma = 1.0, bool SumFlag = true);
72-
109+
CV_EXPORTS_W Ptr<EdgeDrawing> createEdgeDrawing();
73110
//! @}
74111

75112
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifdef HAVE_OPENCV_XIMGPROC
2+
typedef cv::ximgproc::EdgeDrawing::Params EdgeDrawing_Params;
3+
#endif

modules/ximgproc/samples/edge_drawing.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,40 @@ def main():
3232
lsrc = src.copy()
3333
esrc = src.copy()
3434

35-
ed = cv.ximgproc.createEdgeDrawing(cv.ximgproc.EdgeDrawing_SOBEL, 36, 8)
35+
ed = cv.ximgproc.createEdgeDrawing()
36+
37+
# you can change parameters (refer the documentation to see all parameters)
38+
EDParams = cv.ximgproc_EdgeDrawing_Params()
39+
EDParams.MinPathLength = 50 # try changing this value between 5 to 1000
40+
EDParams.PFmode = False # defaut value try to swich it to True
41+
EDParams.MinLineLength = 10 # try changing this value between 5 to 100
42+
EDParams.NFAValidation = True # defaut value try to swich it to False
43+
44+
ed.setParams(EDParams)
3645

3746
# Detect edges
3847
# you should call this before detectLines() and detectEllipses()
3948
ed.detectEdges(gray)
40-
41-
lines = ed.detectLines(False)
4249
segments = ed.getSegments()
50+
lines = ed.detectLines()
51+
ellipses = ed.detectEllipses()
4352

53+
#Draw detected edge segments
4454
for i in range(len(segments)):
4555
color = (rng.randint(0,256), rng.randint(0,256), rng.randint(0,256))
4656
cv.polylines(ssrc, [segments[i]], False, color, 1, cv.LINE_8)
4757

48-
cv.imshow("detected edges", ssrc)
58+
cv.imshow("detected edge segments", ssrc)
4959

50-
if lines is not None: # Check if lines have been found and only then iterate over these and add them to the image
60+
#Draw detected lines
61+
if lines is not None: # Check if the lines have been found and only then iterate over these and add them to the image
5162
lines = np.uint16(np.around(lines))
5263
for i in range(len(lines)):
5364
cv.line(lsrc, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 1, cv.LINE_AA)
5465

5566
cv.imshow("detected lines", lsrc)
5667

57-
ellipses = ed.detectEllipses()
58-
68+
#Draw detected circles and ellipses
5969
if ellipses is not None: # Check if circles and ellipses have been found and only then iterate over these and add them to the image
6070
ellipses = np.uint16(np.around(ellipses))
6171
for i in range(len(ellipses)):

modules/ximgproc/samples/fld_lines.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ int main(int argc, char** argv)
7373

7474
waitKey(1);
7575

76-
Ptr<EdgeDrawing> ed = createEdgeDrawing(EdgeDrawing::SOBEL, 36, 8);
76+
Ptr<EdgeDrawing> ed = createEdgeDrawing();
77+
ed->params.EdgeDetectionOperator = EdgeDrawing::SOBEL;
78+
ed->params.GradientThresholdValue = 38;
79+
ed->params.AnchorThresholdValue = 8;
80+
7781
vector<Vec6d> ellipses;
7882

7983
for (int run_count = 0; run_count < 5; run_count++) {
@@ -86,13 +90,13 @@ int main(int argc, char** argv)
8690
ed->detectEdges(image);
8791

8892
// Detect lines
89-
ed->detectLines(lines, false);
93+
ed->detectLines(lines);
9094
double duration_ms = double(getTickCount() - start) * 1000 / freq;
9195
cout << "Elapsed time for EdgeDrawing detectLines " << duration_ms << " ms." << endl;
9296

9397
start = getTickCount();
9498
// Detect circles and ellipses
95-
ed->detectEllipses(ellipses, true);
99+
ed->detectEllipses(ellipses);
96100
duration_ms = double(getTickCount() - start) * 1000 / freq;
97101
cout << "Elapsed time for EdgeDrawing detectEllipses " << duration_ms << " ms." << endl;
98102
}

0 commit comments

Comments
 (0)