Ejemplo n.º 1
0
def extract_points(frame, points, color_range, max_distance=50, size=150):
    mask = cv2.inRange(frame, color_range[0], color_range[1])
    masked = cv2.bitwise_and(frame, frame, mask=mask)
    h,s,v = cv2.split(masked)

    blurred = cv2.GaussianBlur(h, (33,33), 3)
    kernel = np.ones([3,3], np.uint8)
    dilated = cv2.dilate(blurred, kernel, iterations=3)

    result = []
    contours, hierarchy = cv2.findContours(dilated, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    for c in contours:
        if cv2.contourArea(c) < size:
            continue
        moment = cv2.moments(c)
        if moment['m00'] == 0:
            continue
        x = int(moment['m10'] / moment['m00'])
        y = int(moment['m01'] / moment['m00'])
        result.append((x,y))

    result = hm.coord_list_homography(result)
    result = result if len(points) == 0 else estimate_points(points, result, max_distance)
    points.append(result)
    return result
Ejemplo n.º 2
0
def homographed_points(pts):
    pts = np.array(pts)
    h, w, _ = pts.shape
    res = []
    # for each column(player),
    for i in range(0, w):
        player = pts[:,i]
        p = hm.coord_list_homography(player)
        res.append(p)
    return np.hstack(res)