Python OpenCV使用视频帧创建地图

Python OpenCV使用视频帧创建地图,python,windows,computer-vision,opencv3.0,Python,Windows,Computer Vision,Opencv3.0,我想问一下是否有人能帮我回答这个问题。 我目前正在用相机拍摄的帧实时制作地图。通过使用ORB、蛮力匹配器和findHomography()函数,我成功地找到了关键点和单应性。 现在我想通过使用单应矩阵来创建贴图来缝合帧。 我正在使用Python和OpenCV在Windows环境下工作 感谢您的帮助 def homography(current_frame_gray, previous_frame_gray): orb = cv2.ORB_create() kpts1, desc

我想问一下是否有人能帮我回答这个问题。 我目前正在用相机拍摄的帧实时制作地图。通过使用ORB、蛮力匹配器和findHomography()函数,我成功地找到了关键点和单应性。 现在我想通过使用单应矩阵来创建贴图来缝合帧。 我正在使用Python和OpenCV在Windows环境下工作

感谢您的帮助

def homography(current_frame_gray, previous_frame_gray):
    orb = cv2.ORB_create()

    kpts1, descs1 = orb.detectAndCompute(previous_frame_gray, None)
    kpts2, descs2 = orb.detectAndCompute(current_frame_gray, None)

    bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

    matches = bf.match(descs1, descs2)
    dmatches = sorted(matches, key=lambda x: x.distance)

    src_pts = np.float32([kpts1[m.queryIdx].pt for m in dmatches]).reshape(-1, 1, 2)
    dst_pts = np.float32([kpts2[m.trainIdx].pt for m in dmatches]).reshape(-1, 1, 2)

    if dst_pts is None:
        return False

    M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)
    print(M)
    print("M exact")
    print(M[0,2])
    h, w = previous_frame.shape[:2]
    pts = np.float32([[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0]]).reshape(-1, 1, 2)


    if current_frame is not None:
        print("Not None")
        print(type(current_frame))
    else:
        print("NONE!!!")

    if previous_frame is not None:
        print("Not None")
    else:
        print("NONE!!!")

    res = cv2.drawMatches(previous_frame, kpts1, current_frame, kpts2, dmatches[:20], None, flags=2)


    cv2.imshow("orb_match", res)

    return res

关于你的问题,你有其他的信息吗?当你使用这个函数时,你是遇到了一个错误,还是仅仅是一个意外的输出?嗨@JoshuaBone,它工作得很好。我正在使用warpPerspective函数来缝合帧,但它没有缝合帧,它只是用matplotlib逐帧显示,而且它没有实时功能,因为每次我想让它继续时,我都必须按thw Alt+F4。因此,不幸的是,没有任何错误。如果“缝合”的意思是你想水平连接图像,你可以使用cv2.hconcat([image1,image2]),通过缝合,我的意思是将所有帧与单应矩阵的重叠点合并。我的意思是精确拼接。你有关于你的问题的其他信息吗?当你使用这个函数时,你是遇到了一个错误,还是仅仅是一个意外的输出?嗨@JoshuaBone,它工作得很好。我正在使用warpPerspective函数来缝合帧,但它没有缝合帧,它只是用matplotlib逐帧显示,而且它没有实时功能,因为每次我想让它继续时,我都必须按thw Alt+F4。因此,不幸的是,没有任何错误。如果“缝合”意味着要水平连接图像,可以使用cv2.hconcat([image1,image2]),通过缝合,我的意思是将所有帧与单应矩阵中的重叠点完全合并