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
pull/2824/head
abidrahmank 11 years ago
parent cafcfc4d0f
commit 530fc99947
  1. 10
      modules/imgproc/doc/feature_detection.rst
  2. 18
      modules/imgproc/src/lsd.cpp

@ -519,6 +519,8 @@ Creates a smart pointer to a LineSegmentDetector object and initializes it.
.. ocv:function:: Ptr<LineSegmentDetector> 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.

@ -422,10 +422,10 @@ void LineSegmentDetectorImpl::detect(InputArray _image, OutputArray _lines,
std::vector<double> 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<Vec4i>(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<Vec4i>(i)[0], _lines1.at<Vec4i>(i)[1]);
Point e(_lines1.at<Vec4i>(i)[2], _lines1.at<Vec4i>(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<Vec4i>(i)[0], _lines2.at<Vec4i>(i)[1]);
Point e(_lines2.at<Vec4i>(i)[2], _lines2.at<Vec4i>(i)[3]);

Loading…
Cancel
Save