Skip to content

Fix occuring artifacts in fillPoly#23076

Merged
alalek merged 1 commit intoopencv:3.4from
inayd:22012-bugfixFillPoly
Jan 28, 2023
Merged

Fix occuring artifacts in fillPoly#23076
alalek merged 1 commit intoopencv:3.4from
inayd:22012-bugfixFillPoly

Conversation

@inayd
Copy link
Copy Markdown
Contributor

@inayd inayd commented Jan 2, 2023

Fixes #22012
Fixing the bug described in #22012

The artifacts can occur when corners of a polygon are outside of the image. To be more precise, the outline of the polygon is being drawn using clipped endpoints of an edge, while the borders of the area to be filled are determined using unclipped points of an edge. This can introduce a small offset between the outline and the filled area in polygons which have corner points outside of the image.

The issue is fixed by correcting the edges when lines are clipped.

Pull Request Readiness Checklist

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

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work

@inayd inayd marked this pull request as draft January 4, 2023 16:21
@inayd inayd marked this pull request as ready for review January 4, 2023 16:21
@inayd
Copy link
Copy Markdown
Contributor Author

inayd commented Jan 18, 2023

I adjusted the code after the review. Could you take another look? 🙂

@inayd inayd requested a review from alalek January 25, 2023 19:52
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thank you for contribution!

@alalek alalek merged commit c67d4fc into opencv:3.4 Jan 28, 2023
This was referenced Jan 28, 2023
@asmorkalov asmorkalov mentioned this pull request May 31, 2023
@dan-masek
Copy link
Copy Markdown
Contributor

Today I ran across this question: https://stackoverflow.com/questions/78955298/python-opencv-draws-polygons-outside-of-lines

Looks like it started to appear between 4.7 and 4.8 which leads me to believe it's related to this patch.

import cv2
import numpy as np
    
points = np.array([[[44, 27], [7, 37], [7, 19],[38, 19]]], np.int32).reshape((-1, 1, 2))
img = np.zeros((50, 50, 3), dtype=np.uint8)

cv2.fillPoly(img, [pts], (0, 0, 255))
cv2.polylines(img, [pts], True, (255, 0, 0), 1)

cv2.imwrite("output_v" + str(cv2.__version__) + ".png", img)

In 4.7 and older:
output_v4 7 0

In 4.8 and younger:
output_v4 8 0

Is that expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants