-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Closed as duplicate of#15726
Description
System Information
opencv-python-headless==4.9.0.80
Operating System / Platform: Ubuntu 22.04 in docker
Python version: 3.11.9
Detailed description
ploting a square with square hole:
using this code:
# Create a binary mask with several polygons, some with holes
im = np.zeros((100, 100), dtype=np.uint8)
# Polygon (square with a hole)
im[30:50, 30:50] = 1
im[35:45, 35:45] = 0
fig, ax = plt.subplots()
plt.imshow(im)
plt.show()
contours_tuple_of_Nx1x2_uv_arrays, hierarchy_1xNx4 = cv2.findContours(im, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
for x in contours_tuple_of_Nx1x2_uv_arrays:
print(x.shape)
# result of print:
# (4, 1, 2)
# (8, 1, 2)
running this will give us the inner hole contour with bad corners - as you can see the inner hole should be square but we get 8 points in the contour and it looks like this:
Steps to reproduce
above
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)