utils.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:Defect-Prediction 作者: Jorba123 项目源码 文件源码
def visulize_matches(matches, k2, k1, img2, img1):
    """ Visualize SIFT keypoint matches."""

    import scipy as sp
    img2 = cv.cvtColor(img2, cv.COLOR_GRAY2BGR)
    h1, w1 = img1.shape[:2]
    h2, w2 = img2.shape[:2]
    view = sp.zeros((max(h1, h2), w1 + w2, 3), sp.uint8)
    view[:h1, :w1, :] = img1  
    view[:h2, w1:, :] = img2
    view[:, :, 1] = view[:, :, 0]  
    view[:, :, 2] = view[:, :, 0]

    for m in matches:
        m = m[0]
        # draw the keypoints
        # print m.queryIdx, m.trainIdx, m.distance
        color = tuple([sp.random.randint(0, 255) for _ in xrange(3)])
        pt1 = (int(k1[m.queryIdx].pt[0]), int(k1[m.queryIdx].pt[1]))
        pt2 = (int(k2[m.trainIdx].pt[0] + w1), int(k2[m.trainIdx].pt[1]))

        cv.line(view, pt1, pt2, color)
    return view
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号