from typing import OrderedDict


def detectionsToObj(detections):
    """Detection list to Python object hierarchy"""
    data = []
    for detection in detections:
        # item = {'family': detection.tag_family.decode(),
        #         'id': detection.tag_id,
        #         'hamming': detection.hamming,
        #         'goodness': detection.goodness,
        #         'decision_margin': detection.decision_margin,
        #         'H': detection.homography.tolist(),
        #         'c': detection.center.tolist(),
        #         'p': detection.corners.tolist()
        #        }
        item = OrderedDict( [
                        ('family', detection.tag_family.decode()),
                        ('id', detection.tag_id),
                        ('hamming', detection.hamming),
                        ('goodness', detection.goodness),
                        ('decision_margin', detection.decision_margin),
                        ('H', detection.homography.tolist()),
                        ('c', detection.center.tolist()),
                        ('p', detection.corners.tolist())
                    ] )
        data.append(item)
    return data