OpenCV findContours with RETR_EXTERNAL not working

Following code is trying to extracting bounding rectangles from contours and merge rectangles which is contained in other rectangles


In above found contours, one inner contour is contained within an outer contour, but is not merged with outer contour. the inner one's border is 2 pixel away from outer one's border.

I checked the code multiple times, and not found something wrong.


Then I tried changed the drawing rectangle border thickness to 2, and it works..



Checking it in PyCharm SciView Data View I found their border is connected. So I'm not sure why it's working is caused by increased border width or connected shapes. (But in the past cv2.findContours with RETR_EXTERNAL will work for inner contours, so it's likely caused by thin border)