Following code is trying to extracting bounding rectangles from contours and merge rectangles which is contained in other rectangles
for i in xrange(len(find_contours)):
cv2.drawContours(z2, find_contours, i, (100, 0, 0))
rect = cv2.boundingRect(find_contours[i])
cv2.rectangle(z1, (rect, rect), (rect+rect, rect+rect), (200,255,80), 1)
find_thresh_img, find_contours, find_h = cv2.findContours(z1, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
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..
cv2.rectangle(z1, (rect, rect), (rect+rect, rect+rect), (200,255,80), 2)
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)