def test_rots(theta): invVR_mats = ltool.matrix_multiply(invV_mats, R_mats(theta)) _oris = ktool.get_invVR_mats_oris(invVR_mats) print('________') print('theta = %r' % (theta % TAU, )) print('b / a = %r' % (_oris, )) passed, error = utool.almost_eq(_oris, theta % TAU, ret_error=True) try: assert np.all(passed) except AssertionError as ex: utool.printex(ex, 'rotation unequal', key_list=['passed', 'error'])
def test_rots(theta): invVR_mats = ltool.matrix_multiply(invV_mats, R_mats(theta)) _oris = ktool.get_invVR_mats_oris(invVR_mats) print('________') print('theta = %r' % (theta % TAU,)) print('b / a = %r' % (_oris,)) passed, error = utool.almost_eq(_oris, theta % TAU, ret_error=True) try: assert np.all(passed) except AssertionError as ex: utool.printex(ex, 'rotation unequal', key_list=['passed', 'error'])
def _test_hypothesis_inliers(Aff, invVR1s_m, xy2_m, det2_m, ori2_m, xy_thresh_sqrd, scale_thresh_sqrd, ori_thresh): """ Critical section code. Inner loop of _test_hypothesis_inliers CommandLine: python -m vtool.spatial_verification --test-_test_hypothesis_inliers Example: >>> # ENABLE_DOCTEST >>> from vtool.spatial_verification import * # NOQA >>> from vtool.spatial_verification import _test_hypothesis_inliers # NOQA >>> import vtool.tests.dummy as dummy >>> import vtool.keypoint as ktool >>> _kw1 = dict(seed=12, damping=1.2, wh_stride=(30, 30)) >>> _kw2 = dict(seed=24, damping=1.6, wh_stride=(30, 30)) >>> kpts1 = dummy.perterbed_grid_kpts(**_kw1).astype(np.float64) >>> kpts2 = dummy.perterbed_grid_kpts(**_kw2).astype(np.float64) >>> fm = dummy.make_dummy_fm(len(kpts1)).astype(np.int32) >>> kpts1_m = kpts1[fm.T[0]] >>> kpts2_m = kpts2[fm.T[1]] >>> xy_thresh_sqrd = np.float64(.009) ** 2 >>> scale_thresh_sqrd = np.float64(2) >>> ori_thresh = np.float64(TAU / 4) >>> # Get keypoints to project in matrix form >>> #invVR1s_m = ktool.get_invV_mats(kpts1_m, with_trans=True, with_ori=True) >>> #print(invVR1s_m[0]) >>> invVR1s_m = ktool.get_invVR_mats3x3(kpts1_m) >>> RV1s_m = ktool.get_RV_mats_3x3(kpts1_m) >>> invVR2s_m = ktool.get_invVR_mats3x3(kpts2_m) >>> # The transform from kp1 to kp2 is given as: >>> Aff_mats = matrix_multiply(invVR2s_m, RV1s_m) >>> Aff = Aff_mats[0] >>> # Get components to test projects against >>> xy2_m = ktool.get_invVR_mats_xys(invVR2s_m) >>> det2_m = ktool.get_sqrd_scales(kpts2_m) >>> ori2_m = ktool.get_invVR_mats_oris(invVR2s_m) >>> output = _test_hypothesis_inliers(Aff, invVR1s_m, xy2_m, det2_m, ori2_m, xy_thresh_sqrd, scale_thresh_sqrd, ori_thresh) >>> result = ut.hashstr(output) >>> print(result) +%q&%je52nlyli5& Timeit: %timeit xy_err < xy_thresh_sqrd %timeit np.less(xy_err, xy_thresh_sqrd) """ # Map keypoints from image 1 onto image 2 invVR1s_mt = matrix_multiply(Aff, invVR1s_m) # Get projection components _xy1_mt = ktool.get_invVR_mats_xys(invVR1s_mt) _det1_mt = ktool.get_invVR_mats_sqrd_scale(invVR1s_mt) _ori1_mt = ktool.get_invVR_mats_oris(invVR1s_mt) ## Check for projection errors xy_err = dtool.L2_sqrd(xy2_m.T, _xy1_mt.T, dtype=SV_DTYPE) scale_err = dtool.det_distance(_det1_mt, det2_m) ori_err = dtool.ori_distance(_ori1_mt, ori2_m) # Mark keypoints which are inliers to this hypothosis xy_inliers_flag = np.less(xy_err, xy_thresh_sqrd) scale_inliers_flag = np.less(scale_err, scale_thresh_sqrd) ori_inliers_flag = np.less(ori_err, ori_thresh) #np.logical_and(xy_inliers_flag, scale_inliers_flag) # TODO Add uniqueness of matches constraint #hypo_inliers_flag = np.empty(xy_inliers_flag.size, dtype=np.bool) hypo_inliers_flag = xy_inliers_flag # Try to re-use memory np.logical_and(hypo_inliers_flag, ori_inliers_flag, out=hypo_inliers_flag) np.logical_and(hypo_inliers_flag, scale_inliers_flag, out=hypo_inliers_flag) #hypo_inliers_flag = np.logical_and.reduce( # [xy_inliers_flag, ori_inliers_flag, scale_inliers_flag]) # this is also slower hypo_inliers = np.where(hypo_inliers_flag)[0] hypo_errors = (xy_err, ori_err, scale_err) return hypo_inliers, hypo_errors