The main confusion here is probably the fact that the returned hierarchy is an array with numbers with more dimensions than necessary. Also, it looks like the Python FindContours function returns a tuple, which is a list of paths, and an NDARRAY hierarchy ...
You can get a reasonable array of hierarchy information that more closely matches C documents by simply taking the hierarchy [0]. Then there would be a suitable shape for zip, for example, with contours.
Below is an example that will draw the outermost rectangles in green and the innermost red rectangles in this image:

Output:

Note, by the way, that the wording in the OpenCV documents is a bit ambiguous, but hierarchyDataOfAContour[2] describes the children of this circuit (if it is negative, then this is the internal circuit), and hierarchyDataOfAContour[3] describes the parents of this circuit (if it is negative, it is external circuit).
Also note: I studied the implementation of the algorithm that you talked about in the OCR document, and I saw that FindContours gave me many repetitions of almost the same outlines. This will make it difficult to detect "border boxes" as described in the article. Perhaps this is due to the fact that Canny thresholds were too low (note that I played with them as described in the document), but there might be some way to reduce this effect or just look at the average deviation of the four corners of all the boxes and exclude duplicates ...
import cv2 import numpy
bellkev
source share