From 5b3bd6d96aa923b3dc4ec306b8f1b3069e4e5bc5 Mon Sep 17 00:00:00 2001 From: rick <31221441+rwarren2163@users.noreply.github.com> Date: Mon, 18 May 2020 11:39:41 -0400 Subject: [PATCH] Prevent connecting un-labelled features Here's a simple fix preventing edges from being drawn to connect a feature with another un-labelled feature, which will have coordinates of [-999999 -999999] --- deepposekit/utils/keypoints.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/deepposekit/utils/keypoints.py b/deepposekit/utils/keypoints.py index cb89186..0d8b61f 100644 --- a/deepposekit/utils/keypoints.py +++ b/deepposekit/utils/keypoints.py @@ -73,19 +73,20 @@ def draw_graph(keypoints, height, width, output_shape, graph, sigma=1, linewidth if line >= 0: pt1 = keypoints[line_idx] pt2 = keypoints[line] - line_map = cv2.line( - zeros.copy(), - (int(pt1[0]), int(pt1[1])), - (int(pt2[0]), int(pt2[1])), - 1, - linewidth, - lineType=cv2.LINE_AA, - ) - blurred = cv2.GaussianBlur( - line_map.astype(np.float64), (height + 1, width + 1), sigma - ) - resized = cv2.resize(blurred, (out_width, out_height)) + MACHINE_EPSILON - edge_confidence[..., jdx] = resized + if np.all(pt1>=0) and np.all(pt2>=0): # make sure we don't draw edge for features that are not labelled within the frame + line_map = cv2.line( + zeros.copy(), + (int(pt1[0]), int(pt1[1])), + (int(pt2[0]), int(pt2[1])), + 1, + linewidth, + lineType=cv2.LINE_AA, + ) + blurred = cv2.GaussianBlur( + line_map.astype(np.float64), (height + 1, width + 1), sigma + ) + resized = cv2.resize(blurred, (out_width, out_height)) + MACHINE_EPSILON + edge_confidence[..., jdx] = resized edge_confidence = edge_confidence[..., 1:] edge_confidence_list.append(edge_confidence) confidence[..., idx] = edge_confidence.sum(-1)