To do this, you should take a look at this tutorial on how to use the hierarchy object returned by the findContours method.
The main thing is that you should use cv2.RETR_TREE instead of cv2.RETR_LIST to get the relationship between parents and children between your clusters:
regions, hierarchy = cv2.findContours(binary_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
Then you can check if the path with index i inside another if hierarchy[0,i,3] is -1 or not. If it is other than -1, your path is inside another.
source share