From 530fc99947e3955914f0370ab55279a8b536a3b5 Mon Sep 17 00:00:00 2001 From: abidrahmank Date: Tue, 3 Jun 2014 14:25:33 +0530 Subject: [PATCH] Issue #3709 - PyBindings for LSD Corrected crashing in Python bindings while using LSD_REFINE_NONE flags Corrected not drawing lines in drawSegments and compareSegments in Python bindings --- modules/imgproc/doc/feature_detection.rst | 10 +++++++++- modules/imgproc/src/lsd.cpp | 18 +++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/imgproc/doc/feature_detection.rst b/modules/imgproc/doc/feature_detection.rst index 2187b8f..9c661d0 100644 --- a/modules/imgproc/doc/feature_detection.rst +++ b/modules/imgproc/doc/feature_detection.rst @@ -519,6 +519,8 @@ Creates a smart pointer to a LineSegmentDetector object and initializes it. .. ocv:function:: Ptr createLineSegmentDetector(int _refine = LSD_REFINE_STD, double _scale = 0.8, double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024) +.. ocv:pyfunction:: cv2.createLineSegmentDetector([, _refine[, _scale[, _sigma_scale[, _quant[, _ang_th[, _log_eps[, _density_th[, _n_bins]]]]]]]]) -> retval + :param _refine: The way found lines will be refined: * **LSD_REFINE_NONE** - No refinement applied. @@ -550,6 +552,8 @@ Finds lines in the input image. See the lsd_lines.cpp sample for possible usage. .. ocv:function:: void LineSegmentDetector::detect(const InputArray _image, OutputArray _lines, OutputArray width = noArray(), OutputArray prec = noArray(), OutputArray nfa = noArray()) +.. ocv:pyfunction:: cv2.createLineSegmentDetector.detect(_image[, _lines[, width[, prec[, nfa]]]]) -> _lines, width, prec, nfa + :param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use :: lsd_ptr->detect(image(roi), lines, ...); @@ -585,6 +589,8 @@ Draws the line segments on a given image. .. ocv:function:: void LineSegmentDetector::drawSegments(InputOutputArray _image, InputArray lines) +.. ocv:pyfunction:: cv2.createLineSegmentDetector.drawSegments(_image, lines) -> _image + :param image: The image, where the liens will be drawn. Should be bigger or equal to the image, where the lines were found. :param lines: A vector of the lines that needed to be drawn. @@ -596,13 +602,15 @@ Draws two groups of lines in blue and red, counting the non overlapping (mismatc .. ocv:function:: int LineSegmentDetector::compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) +.. ocv:pyfunction:: cv2.createLineSegmentDetector.compareSegments(size, lines1, lines2[, _image]) -> retval, _image + :param size: The size of the image, where lines1 and lines2 were found. :param lines1: The first group of lines that needs to be drawn. It is visualized in blue color. :param lines2: The second group of lines. They visualized in red color. - :param image: Optional image, where the lines will be drawn. The image should be color in order for lines1 and lines2 to be drawn in the above mentioned colors. + :param image: Optional image, where the lines will be drawn. The image should be color(3-channel) in order for lines1 and lines2 to be drawn in the above mentioned colors. diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index 0e82a39..018fc3b 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -422,10 +422,10 @@ void LineSegmentDetectorImpl::detect(InputArray _image, OutputArray _lines, std::vector w, p, n; w_needed = _width.needed(); p_needed = _prec.needed(); - n_needed = _nfa.needed(); - - CV_Assert((!_nfa.needed()) || // NFA InputArray will be filled _only_ when - (_nfa.needed() && doRefine >= LSD_REFINE_ADV)); // REFINE_ADV type LineSegmentDetectorImpl object is created. + if (doRefine < LSD_REFINE_ADV) + n_needed = false; + else + n_needed = _nfa.needed(); flsd(lines, w, p, n); @@ -1172,9 +1172,10 @@ void LineSegmentDetectorImpl::drawSegments(InputOutputArray _image, InputArray l Mat _lines; _lines = lines.getMat(); + int N = _lines.checkVector(4); // Draw segments - for(int i = 0; i < _lines.size().width; ++i) + for(int i = 0; i < N; ++i) { const Vec4i& v = _lines.at(i); Point b(v[0], v[1]); @@ -1197,14 +1198,17 @@ int LineSegmentDetectorImpl::compareSegments(const Size& size, InputArray lines1 Mat _lines2; _lines1 = lines1.getMat(); _lines2 = lines2.getMat(); + int N1 = _lines1.checkVector(4); + int N2 = _lines2.checkVector(4); + // Draw segments - for(int i = 0; i < _lines1.size().width; ++i) + for(int i = 0; i < N1; ++i) { Point b(_lines1.at(i)[0], _lines1.at(i)[1]); Point e(_lines1.at(i)[2], _lines1.at(i)[3]); line(I1, b, e, Scalar::all(255), 1); } - for(int i = 0; i < _lines2.size().width; ++i) + for(int i = 0; i < N2; ++i) { Point b(_lines2.at(i)[0], _lines2.at(i)[1]); Point e(_lines2.at(i)[2], _lines2.at(i)[3]); -- 2.7.4