diff --git a/modules/imgproc/src/drawing.cpp b/modules/imgproc/src/drawing.cpp index e3158750c5..8214b17013 100644 --- a/modules/imgproc/src/drawing.cpp +++ b/modules/imgproc/src/drawing.cpp @@ -1646,6 +1646,18 @@ ThickLine( Mat& img, Point2l p0, Point2l p1, const void* color, { static const double INV_XY_ONE = 1./static_cast(XY_ONE); + Rect_ boundingRect(Point2l(0, 0), (Size2l)img.size()); + if( (thickness > 1) && (shift == 0) && ( !boundingRect.contains(p0) || !boundingRect.contains(p1) ) ) + { + const int margin = thickness; + const Point2l offset(margin, margin); + p0 += offset; + p1 += offset; + clipLine(Size2l(boundingRect.width+2*margin, boundingRect.height+2*margin), p0, p1); + p0 -= offset; + p1 -= offset; + } + p0.x <<= XY_SHIFT - shift; p0.y <<= XY_SHIFT - shift; p1.x <<= XY_SHIFT - shift; diff --git a/modules/imgproc/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp index 80e01794a1..50c146baad 100644 --- a/modules/imgproc/test/test_drawing.cpp +++ b/modules/imgproc/test/test_drawing.cpp @@ -589,7 +589,7 @@ TEST(Drawing, longline) Mat mat = Mat::zeros(256, 256, CV_8UC1); line(mat, cv::Point(34, 204), cv::Point(46400, 47400), cv::Scalar(255), 3); - EXPECT_EQ(310, cv::countNonZero(mat)); + EXPECT_EQ(264, cv::countNonZero(mat)); Point pt[6]; pt[0].x = 32; diff --git a/modules/js/test/test_features2d.js b/modules/js/test/test_features2d.js index 7844da3146..c49ec7ea90 100644 --- a/modules/js/test/test_features2d.js +++ b/modules/js/test/test_features2d.js @@ -26,7 +26,7 @@ QUnit.test('Detectors', function(assert) { let orb = new cv.ORB(); orb.detect(image, kp); - assert.equal(kp.size(), 67, 'ORB'); + assert.equal(kp.size(), 68, 'ORB'); let mser = new cv.MSER(); mser.detect(image, kp); @@ -34,7 +34,7 @@ QUnit.test('Detectors', function(assert) { let brisk = new cv.BRISK(); brisk.detect(image, kp); - assert.equal(kp.size(), 191, 'BRISK'); + assert.equal(kp.size(), 187, 'BRISK'); let ffd = new cv.FastFeatureDetector(); ffd.detect(image, kp); @@ -54,7 +54,7 @@ QUnit.test('Detectors', function(assert) { let akaze = new cv.AKAZE(); akaze.detect(image, kp); - assert.equal(kp.size(), 53, 'AKAZE'); + assert.equal(kp.size(), 52, 'AKAZE'); }); QUnit.test('SimpleBlobDetector', function(assert) { @@ -75,14 +75,14 @@ QUnit.test('BFMatcher', function(assert) { let orb = new cv.ORB(); orb.detectAndCompute(image, new cv.Mat(), kp, descriptors); - assert.equal(kp.size(), 67); + assert.equal(kp.size(), 68); // Run a matcher. let dm = new cv.DMatchVector(); let matcher = new cv.BFMatcher(); matcher.match(descriptors, descriptors, dm); - assert.equal(dm.size(), 67); + assert.equal(dm.size(), 68); }); QUnit.test('Drawing', function(assert) { @@ -93,7 +93,7 @@ QUnit.test('Drawing', function(assert) { let descriptors = new cv.Mat(); let orb = new cv.ORB(); orb.detectAndCompute(image, new cv.Mat(), kp, descriptors); - assert.equal(kp.size(), 67); + assert.equal(kp.size(), 68); let dst = new cv.Mat(); cv.drawKeypoints(image, kp, dst); @@ -104,7 +104,7 @@ QUnit.test('Drawing', function(assert) { let dm = new cv.DMatchVector(); let matcher = new cv.BFMatcher(); matcher.match(descriptors, descriptors, dm); - assert.equal(dm.size(), 67); + assert.equal(dm.size(), 68); cv.drawMatches(image, kp, image, kp, dm, dst); assert.equal(dst.rows, image.rows); @@ -112,7 +112,7 @@ QUnit.test('Drawing', function(assert) { dm = new cv.DMatchVectorVector(); matcher.knnMatch(descriptors, descriptors, dm, 2); - assert.equal(dm.size(), 67); + assert.equal(dm.size(), 68); cv.drawMatchesKnn(image, kp, image, kp, dm, dst); assert.equal(dst.rows, image.rows); assert.equal(dst.cols, 2 * image.cols);