(self, skeletons)
return sorted_skeletons
Skeletons are sorted based on the distance
        between neck and image center, from small to large.
        A skeleton near center will be processed first and be given a smaller human id.
        Here the center is defined as (0.5, 0.5), although it's not accurate due to h_scale.
Skeletons are sorted based on the distance
        between neck and image center, from small to large.
        A skeleton near center will be processed first and be given a smaller human id.
        Here the center is defined as (0.5, 0.5), although it's not accurate due to h_scale.
Skeletons are sorted based on the distance between neck and image center from small to large . A skeleton near center will be processed first and be given a smaller human id . Here the center is defined as ( 0 . 5 0 . 5 ) although it s not accurate due to h_scale .
def _sort_skeletons_by_dist_to_center(self, skeletons):
        ''' Skeletons are sorted based on the distance
        between neck and image center, from small to large.
        A skeleton near center will be processed first and be given a smaller human id.
        Here the center is defined as (0.5, 0.5), although it's not accurate due to h_scale.
        '''
        def calc_dist(p1, p2): return (
            (p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**0.5

        def cost(skeleton):
            x1, y1 = self._get_neck(skeleton)
            return calc_dist((x1, y1), (0.5, 0.5))  # dist to center

        def cmp(a, b): return (a > b)-(a < b)
        def mycmp(sk1, sk2): return cmp(cost(sk1), cost(sk2))
        sorted_skeletons = sorted(skeletons, key=functools.cmp_to_key(mycmp))
        return sorted_skeletons
def _sort_skeletons_by_dist_to_center ( self , skeletons ) : def calc_dist ( p1 , p2 ) : return ( ( p1 [ 0 ] - p2 [ 0 ] ) ** 2 + ( p1 [ 1 ] - p2 [ 1 ] ) ** 2 ) ** 0.5 def cost ( skeleton ) : x1 , y1 = self . _get_neck ( skeleton ) return calc_dist ( ( x1 , y1 ) , ( 0.5 , 0.5 ) ) # dist to center def cmp ( a , b ) : return ( a > b ) - ( a < b ) def mycmp ( sk1 , sk2 ) : return cmp ( cost ( sk1 ) , cost ( sk2 ) ) sorted_skeletons = sorted ( skeletons , key = functools . cmp_to_key ( mycmp ) ) return sorted_skeletons