triangles.py 1.45 KB
Newer Older
tilman's avatar
tilman committed
1
2
3
4
5
6
import numpy as np

def reduceToTrianglePoint(indices,pose):
    points = pose[indices] #filter out poses wich are not part of the points points indices
    if len(points) <= 0:
        return None #no relevant indices exist
7
    pointsFiltered = points[np.where(points[:,2] > 0.1)[0]] #filter out points bellow openpose confidence value of 0.1
tilman's avatar
tilman committed
8
9
10
11
12
13
14
15
16
17
18
    if len(pointsFiltered) <= 0 or pointsFiltered is None:
        bestPoint = points[np.argsort(points[:,2])[::-1]][0] #points with best openpose confidence
        if bestPoint[2]>0.0:
            return bestPoint
        else:
            return None
        return None #else return point with best openpose confidence
    else:
        return pointsFiltered[0] #take first point if filterd has values

def poseToTriangle(pose):
19
20
21
    triangleTopSortedIndices = [1,0,2,5,15,16,17,18]
    triangleLeftSortedIndices = [11,24,13,22,10,9]
    triangleRightSortedIndices = [14,21,19,20,13,12]
tilman's avatar
tilman committed
22
23
24
25
26
27
28
29
    top = reduceToTrianglePoint(triangleTopSortedIndices,pose)
    left = reduceToTrianglePoint(triangleLeftSortedIndices,pose)
    right = reduceToTrianglePoint(triangleRightSortedIndices,pose)

    if top is not None and left is not None and right is not None:
        retval = np.array([(top[0],top[1]),(left[0],left[1]),(right[0],right[1])])
        return np.array(retval).astype(int)
    else:
30
31
32
33
34
        return None

def triangleToBodyLine(triangle):
    bottom_middle_point = (triangle[1]+triangle[2])/2
    return (triangle[0],bottom_middle_point)