Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature matching result output #9

Open
Lucifer1002 opened this issue Feb 4, 2021 · 1 comment
Open

Feature matching result output #9

Lucifer1002 opened this issue Feb 4, 2021 · 1 comment

Comments

@Lucifer1002
Copy link

Hello, may I ask, how to output the matching results of image feature points?

@Shiaoming
Copy link
Owner

check this function:

Python-VO/utils/tools.py

Lines 38 to 91 in c03e88f

def plot_matches(image0, image1, kpts0, kpts1, scores=None, layout="lr"):
"""
plot matches between two images. If score is nor None, then red: bad match, green: good match
:param image0: reference image
:param image1: current image
:param kpts0: keypoints in reference image
:param kpts1: keypoints in current image
:param scores: matching score for each keypoint pair, range [0~1], 0: worst match, 1: best match
:param layout: 'lr': left right; 'ud': up down
:return:
"""
H0, W0 = image0.shape[0], image0.shape[1]
H1, W1 = image1.shape[0], image1.shape[1]
if layout == "lr":
H, W = max(H0, H1), W0 + W1
out = 255 * np.ones((H, W, 3), np.uint8)
out[:H0, :W0, :] = image0
out[:H1, W0:, :] = image1
elif layout == "ud":
H, W = H0 + H1, max(W0, W1)
out = 255 * np.ones((H, W, 3), np.uint8)
out[:H0, :W0, :] = image0
out[H0:, :W1, :] = image1
else:
raise ValueError("The layout must be 'lr' or 'ud'!")
kpts0, kpts1 = np.round(kpts0).astype(int), np.round(kpts1).astype(int)
# get color
if scores is not None:
smin, smax = scores.min(), scores.max()
assert (0 <= smin <= 1 and 0 <= smax <= 1)
color = cm.gist_rainbow(scores * 0.4)
color = (np.array(color[:, :3]) * 255).astype(int)[:, ::-1]
else:
color = np.zeros((kpts0.shape[0], 3), dtype=int)
color[:, 1] = 255
for (x0, y0), (x1, y1), c in zip(kpts0, kpts1, color):
c = c.tolist()
if layout == "lr":
cv2.line(out, (x0, y0), (x1 + W0, y1), color=c, thickness=1, lineType=cv2.LINE_AA)
# display line end-points as circles
cv2.circle(out, (x0, y0), 2, c, -1, lineType=cv2.LINE_AA)
cv2.circle(out, (x1 + W0, y1), 2, c, -1, lineType=cv2.LINE_AA)
elif layout == "ud":
cv2.line(out, (x0, y0), (x1, y1 + H0), color=c, thickness=1, lineType=cv2.LINE_AA)
# display line end-points as circles
cv2.circle(out, (x0, y0), 2, c, -1, lineType=cv2.LINE_AA)
cv2.circle(out, (x1, y1 + H0), 2, c, -1, lineType=cv2.LINE_AA)
return out

Originally posted by @Shiaoming in #7 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants