From 25c0d5978caae3be412390796f6290709b0dff41 Mon Sep 17 00:00:00 2001 From: Daniel Angelov Date: Thu, 5 Sep 2013 00:02:24 +0300 Subject: [PATCH] Update on the compare lines method. --- modules/imgproc/doc/feature_detection.rst | 2 +- modules/imgproc/src/lsd.cpp | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/modules/imgproc/doc/feature_detection.rst b/modules/imgproc/doc/feature_detection.rst index ef44c05c35..a6d5817dd7 100644 --- a/modules/imgproc/doc/feature_detection.rst +++ b/modules/imgproc/doc/feature_detection.rst @@ -598,7 +598,7 @@ Draws two groups of lines in blue and red, counting the non overlapping (mismatc :param lines2: The second group of lines. They visualized in red color. - :param image: Optional image, where the lines will be drawn. The image is converted to grayscale before displaying, leaving lines1 and lines2 in the above mentioned colors. + :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. diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index 9b57a34115..b860751e19 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -1220,12 +1220,9 @@ int LineSegmentDetectorImpl::compareSegments(const Size& size, InputArray lines1 if (_image.needed()) { - Mat Ig; - if (_image.channels() == 1) - { - cvtColor(_image, _image, CV_GRAY2BGR); - } - CV_Assert(_image.getMatRef().isContinuous() && I1.isContinuous() && I2.isContinuous()); + CV_Assert(_image.channels() == 3); + Mat img = _image.getMatRef(); + CV_Assert(img.isContinuous() && I1.isContinuous() && I2.isContinuous()); for (unsigned int i = 0; i < I1.total(); ++i) { @@ -1233,11 +1230,12 @@ int LineSegmentDetectorImpl::compareSegments(const Size& size, InputArray lines1 uchar i2 = I2.data[i]; if (i1 || i2) { - _image.getMatRef().data[3*i + 1] = 0; - if (i1) _image.getMatRef().data[3*i] = 255; - else _image.getMatRef().data[3*i] = 0; - if (i2) _image.getMatRef().data[3*i + 2] = 255; - else _image.getMatRef().data[3*i + 2] = 0; + unsigned int base_idx = i * 3; + if (i1) img.data[base_idx] = 255; + else img.data[base_idx] = 0; + img.data[base_idx + 1] = 0; + if (i2) img.data[base_idx + 2] = 255; + else img.data[base_idx + 2] = 0; } } }