Python OpenCV Создать карту с видеокадрами - PullRequest
1 голос
/ 09 июля 2020

Я хотел бы спросить, может ли кто-нибудь помочь мне с моим вопросом. В настоящее время я работаю над созданием карты в реальном времени с кадрами, снятыми с камеры. Мне удалось найти ключевые точки и гомографию с помощью ORB, Brute Force Matcher и функции findHomography (). Теперь я хочу сшить рамки, используя матрицу гомографии для создания карты. Я работаю над средой Windows с Python и OpenCV.

Любая помощь приветствуется.

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
...