I am experimenting with cv2.drawContours. I tried this:
import cv2
import numpy as np
def fix_format(cts):
return [np.asarray(np.round(ct), np.int32)[:, :, np.newaxis] for ct in cts]
# these are 2 overlapping rectangular regions
cts1 = [
[[1, 1], [6, 1], [6, 4], [1,4]],
[[3, 2], [7, 2], [7, 7], [3,7]]
]
img1 = cv2.drawContours(np.zeros([10, 10]), fix_format(cts1), contourIdx=-1, color=1, thickness=-1)
I assumed that, since I am using thickness=-1, contours would be filled, and since the areas are overlapping I would end up with the union of the areas delimited by the 2 contours in cts1.
However, when printing img1, I see there are 2 values that are still 0 in the overlapping area (img1[3][4] and img1[3][5]).
Why is this happening?
EDIT:
I tried using the 2 contours separately, and this is what I get (for the first, second and both contours, respectively):



mmmh I tried to figure out what is going on and tried some more on the same example , please follow this approach:
output:
img1 :
imga :
imgb :
img1 :
imgX :
changing :
cnt_a, hier = cv2.findContours(imga, cv2.RETR_LIST , cv2.CHAIN_APPROX_NONE )and
cnt_b, hier = cv2.findContours(imgb, cv2.RETR_LIST , cv2.CHAIN_APPROX_NONE )to
cnt_a, hier = cv2.findContours(imga, cv2.RETR_LIST , cv2.CHAIN_APPROX_SIMPLE )and
cnt_b, hier = cv2.findContours(imgb, cv2.RETR_LIST , cv2.CHAIN_APPROX_SIMPLE )I get imgX :