def test_estimate_partial_transform(): expected = [29.999978200505126, 29.999898169013868, 1.0278229229761564e-06] matched_keypoints = utils.match_keypoints(optical_flow, frame_1_kps) partial_transform = utils.estimate_partial_transform(matched_keypoints) assert np.allclose(partial_transform, expected, rtol=0.1)
def test_match_keypoints(): cur_matched_kps, prev_matched_kps = utils.match_keypoints(optical_flow, frame_1_kps) cur_matched_kps = [np.rint(x).astype('int').tolist() for x in cur_matched_kps] prev_matched_kps = [np.rint(x).astype('int').tolist() for x in prev_matched_kps] assert cur_matched_kps == [[[130, 130]], [[50, 130]], [[130, 80]], [[50, 80]]] assert prev_matched_kps == [[[100, 100]], [[20, 100]], [[100, 50]], [[20, 50]]]
def test_match_keypoints(): cur_matched_kps, prev_matched_kps = utils.match_keypoints(optical_flow, frame_1_kps) cur_matched_kps = np.rint(cur_matched_kps).astype('int') prev_matched_kps = np.rint(prev_matched_kps).astype('int') cur_expected = np.array([[[130, 130]], [[50, 130]], [[130, 80]], [[50, 80]]], dtype='int') prev_expected = cur_expected - 30 assert (cur_matched_kps == cur_expected).all() assert (prev_matched_kps == prev_expected).all()
def test_none_optical_flow(): prev_gray = np.ones((1208, 1920, 3)) * 250 current_frame_gray = np.ones((1208, 1920, 3)) * 250 prev_kps = np.array([], dtype='float32') # noinspection PyArgumentList prev_kps = prev_kps.reshape(0, 1, 2) none_optical_flow = cv2.calcOpticalFlowPyrLK(prev_gray, current_frame_gray, prev_kps, None) matched_keypoints = utils.match_keypoints(none_optical_flow, prev_kps) transform_i = utils.estimate_partial_transform(matched_keypoints) assert transform_i == [0, 0, 0]