Skip to content

fillPoly draws outside boundaries #26130

@Eric-Vignola

Description

@Eric-Vignola

System Information

OpenCV python version 4.10.0
Operating System / Platform: Windows 11
Python version 3.7.7

Detailed description

In a nutshell: give 4 coordinates to fillPoly and polyLine using different colors will reveal that fillPoly exceeds the drawn boundaries of polyLine.

Issue fully described here:
https://stackoverflow.com/questions/78955298/python-opencv-draws-polygons-outside-of-lines/78959138

Steps to reproduce

import cv2
import numpy as np

def draw_polygon(points, resolution=50):
    
    # create a blank black canvas
    img = np.zeros((resolution, resolution, 3), dtype=np.uint8)
    pts = np.array(points, np.int32)
    pts = pts.reshape((-1, 1, 2))
    
    # draw a filled polygon in blue
    cv2.fillPoly(img, [pts], (0, 0, 255))
    
    # draw an outline in red
    cv2.polylines(img, [pts], True, (255, 0, 0), 1)
    
    # show the image
    cv2.imshow("Polygon", img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

    
    
# why is the infill outside the line?
if __name__ == "__main__":

    # 4 vertices of the quad (clockwise)
    quad = np.array([[[44, 27],
                      [7, 37],
                      [7, 19],
                      [38, 19]]])
    
    draw_polygon(quad)

image

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions