1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-21 19:33:03 +04:00

Merge pull request #27366 from chacha21:arrowedLine_clipped

Try to fix distant points to save time when ThickLine() calls FillConvexPoly() #27366

Proposal for #27365

cv::clipLine() is useful, but one should take care of a margin to preserve line caps.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [X] The PR is proposed to the proper branch
- [X] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Pierre Chatelier
2025-11-07 08:34:52 +01:00
committed by GitHub
parent 426aa598e7
commit 9fc556a83e
3 changed files with 21 additions and 9 deletions
+12
View File
@@ -1646,6 +1646,18 @@ ThickLine( Mat& img, Point2l p0, Point2l p1, const void* color,
{
static const double INV_XY_ONE = 1./static_cast<double>(XY_ONE);
Rect_<int64> 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;
+1 -1
View File
@@ -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;
+8 -8
View File
@@ -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);