Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
aom-rav1e
Commits
1a2b35f9
Commit
1a2b35f9
authored
Oct 21, 2017
by
Debargha Mukherjee
Browse files
Remove code for homography models
Change-Id: Ib93f090f395e52bd69c59e1229e2e035a8772af5
parent
945176aa
Changes
8
Hide whitespace changes
Inline
Side-by-side
av1/common/mv.h
View file @
1a2b35f9
...
...
@@ -71,10 +71,7 @@ typedef enum {
TRANSLATION
=
1
,
// translational motion 2-parameter
ROTZOOM
=
2
,
// simplified affine with rotation + zoom only, 4-parameter
AFFINE
=
3
,
// affine, 6-parameter
HORTRAPEZOID
=
4
,
// constrained homography, hor trapezoid, 6-parameter
VERTRAPEZOID
=
5
,
// constrained homography, ver trapezoid, 6-parameter
HOMOGRAPHY
=
6
,
// homography, 8-parameter
TRANS_TYPES
=
7
,
TRANS_TYPES
,
}
TransformationType
;
/* clang-format on */
...
...
@@ -103,7 +100,7 @@ typedef struct {
}
WarpTypesAllowed
;
// number of parameters used by each transformation in TransformationTypes
static
const
int
trans_model_params
[
TRANS_TYPES
]
=
{
0
,
2
,
4
,
6
,
6
,
6
,
8
};
static
const
int
trans_model_params
[
TRANS_TYPES
]
=
{
0
,
2
,
4
,
6
};
// The order of values in the wmmat matrix below is best described
// by the homography:
...
...
@@ -308,11 +305,6 @@ static INLINE int_mv gm_get_motion_vector(const WarpedMotionParams *gm,
}
static
INLINE
TransformationType
get_gmtype
(
const
WarpedMotionParams
*
gm
)
{
if
(
gm
->
wmmat
[
6
]
!=
0
||
gm
->
wmmat
[
7
]
!=
0
)
{
if
(
!
gm
->
wmmat
[
6
]
&&
!
gm
->
wmmat
[
4
])
return
HORTRAPEZOID
;
if
(
!
gm
->
wmmat
[
7
]
&&
!
gm
->
wmmat
[
3
])
return
VERTRAPEZOID
;
return
HOMOGRAPHY
;
}
if
(
gm
->
wmmat
[
5
]
==
(
1
<<
WARPEDMODEL_PREC_BITS
)
&&
!
gm
->
wmmat
[
4
]
&&
gm
->
wmmat
[
2
]
==
(
1
<<
WARPEDMODEL_PREC_BITS
)
&&
!
gm
->
wmmat
[
3
])
{
return
((
!
gm
->
wmmat
[
1
]
&&
!
gm
->
wmmat
[
0
])
?
IDENTITY
:
TRANSLATION
);
...
...
av1/common/warped_motion.c
View file @
1a2b35f9
...
...
@@ -93,9 +93,6 @@ static const int error_measure_lut[512] = {
static
ProjectPointsFunc
get_project_points_type
(
TransformationType
type
)
{
switch
(
type
)
{
case
VERTRAPEZOID
:
return
project_points_vertrapezoid
;
case
HORTRAPEZOID
:
return
project_points_hortrapezoid
;
case
HOMOGRAPHY
:
return
project_points_homography
;
case
AFFINE
:
return
project_points_affine
;
case
ROTZOOM
:
return
project_points_rotzoom
;
case
TRANSLATION
:
return
project_points_translation
;
...
...
av1/decoder/decodeframe.c
View file @
1a2b35f9
...
...
@@ -2829,21 +2829,6 @@ static int read_global_motion_params(WarpedMotionParams *params,
*
params
=
default_warp_params
;
params
->
wmtype
=
type
;
switch
(
type
)
{
case
HOMOGRAPHY
:
case
HORTRAPEZOID
:
case
VERTRAPEZOID
:
if
(
type
!=
HORTRAPEZOID
)
params
->
wmmat
[
6
]
=
aom_rb_read_signed_primitive_refsubexpfin
(
rb
,
GM_ROW3HOMO_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
6
]
>>
GM_ROW3HOMO_PREC_DIFF
))
*
GM_ROW3HOMO_DECODE_FACTOR
;
if
(
type
!=
VERTRAPEZOID
)
params
->
wmmat
[
7
]
=
aom_rb_read_signed_primitive_refsubexpfin
(
rb
,
GM_ROW3HOMO_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
7
]
>>
GM_ROW3HOMO_PREC_DIFF
))
*
GM_ROW3HOMO_DECODE_FACTOR
;
case
AFFINE
:
case
ROTZOOM
:
params
->
wmmat
[
2
]
=
aom_rb_read_signed_primitive_refsubexpfin
(
...
...
@@ -2852,17 +2837,15 @@ static int read_global_motion_params(WarpedMotionParams *params,
(
1
<<
GM_ALPHA_PREC_BITS
))
*
GM_ALPHA_DECODE_FACTOR
+
(
1
<<
WARPEDMODEL_PREC_BITS
);
if
(
type
!=
VERTRAPEZOID
)
params
->
wmmat
[
3
]
=
aom_rb_read_signed_primitive_refsubexpfin
(
params
->
wmmat
[
3
]
=
aom_rb_read_signed_primitive_refsubexpfin
(
rb
,
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
))
*
GM_ALPHA_DECODE_FACTOR
;
if
(
type
>=
AFFINE
)
{
params
->
wmmat
[
4
]
=
aom_rb_read_signed_primitive_refsubexpfin
(
rb
,
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
))
*
(
ref_params
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
))
*
GM_ALPHA_DECODE_FACTOR
;
if
(
type
>=
AFFINE
)
{
if
(
type
!=
HORTRAPEZOID
)
params
->
wmmat
[
4
]
=
aom_rb_read_signed_primitive_refsubexpfin
(
rb
,
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
))
*
GM_ALPHA_DECODE_FACTOR
;
params
->
wmmat
[
5
]
=
aom_rb_read_signed_primitive_refsubexpfin
(
rb
,
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
5
]
>>
GM_ALPHA_PREC_DIFF
)
-
...
...
av1/encoder/bitstream.c
View file @
1a2b35f9
...
...
@@ -3914,20 +3914,6 @@ static void write_global_motion_params(const WarpedMotionParams *params,
}
switch
(
type
)
{
case
HOMOGRAPHY
:
case
HORTRAPEZOID
:
case
VERTRAPEZOID
:
if
(
type
!=
HORTRAPEZOID
)
aom_wb_write_signed_primitive_refsubexpfin
(
wb
,
GM_ROW3HOMO_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
6
]
>>
GM_ROW3HOMO_PREC_DIFF
),
(
params
->
wmmat
[
6
]
>>
GM_ROW3HOMO_PREC_DIFF
));
if
(
type
!=
VERTRAPEZOID
)
aom_wb_write_signed_primitive_refsubexpfin
(
wb
,
GM_ROW3HOMO_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
7
]
>>
GM_ROW3HOMO_PREC_DIFF
),
(
params
->
wmmat
[
7
]
>>
GM_ROW3HOMO_PREC_DIFF
));
// fallthrough intended
case
AFFINE
:
case
ROTZOOM
:
aom_wb_write_signed_primitive_refsubexpfin
(
...
...
@@ -3935,17 +3921,15 @@ static void write_global_motion_params(const WarpedMotionParams *params,
(
ref_params
->
wmmat
[
2
]
>>
GM_ALPHA_PREC_DIFF
)
-
(
1
<<
GM_ALPHA_PREC_BITS
),
(
params
->
wmmat
[
2
]
>>
GM_ALPHA_PREC_DIFF
)
-
(
1
<<
GM_ALPHA_PREC_BITS
));
if
(
type
!=
VERTRAPEZOID
)
aom_wb_write_signed_primitive_refsubexpfin
(
wb
,
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
),
(
params
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
));
if
(
type
>=
AFFINE
)
{
aom_wb_write_signed_primitive_refsubexpfin
(
wb
,
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
),
(
params
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
));
if
(
type
>=
AFFINE
)
{
if
(
type
!=
HORTRAPEZOID
)
aom_wb_write_signed_primitive_refsubexpfin
(
wb
,
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
),
(
params
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
));
(
ref_params
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
),
(
params
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
));
aom_wb_write_signed_primitive_refsubexpfin
(
wb
,
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_params
->
wmmat
[
5
]
>>
GM_ALPHA_PREC_DIFF
)
-
...
...
av1/encoder/encodeframe.c
View file @
1a2b35f9
...
...
@@ -3654,37 +3654,21 @@ static int gm_get_params_cost(const WarpedMotionParams *gm,
int
params_cost
=
0
;
int
trans_bits
,
trans_prec_diff
;
switch
(
gm
->
wmtype
)
{
case
HOMOGRAPHY
:
case
HORTRAPEZOID
:
case
VERTRAPEZOID
:
if
(
gm
->
wmtype
!=
HORTRAPEZOID
)
params_cost
+=
aom_count_signed_primitive_refsubexpfin
(
GM_ROW3HOMO_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_gm
->
wmmat
[
6
]
>>
GM_ROW3HOMO_PREC_DIFF
),
(
gm
->
wmmat
[
6
]
>>
GM_ROW3HOMO_PREC_DIFF
));
if
(
gm
->
wmtype
!=
VERTRAPEZOID
)
params_cost
+=
aom_count_signed_primitive_refsubexpfin
(
GM_ROW3HOMO_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_gm
->
wmmat
[
7
]
>>
GM_ROW3HOMO_PREC_DIFF
),
(
gm
->
wmmat
[
7
]
>>
GM_ROW3HOMO_PREC_DIFF
));
// Fallthrough intended
case
AFFINE
:
case
ROTZOOM
:
params_cost
+=
aom_count_signed_primitive_refsubexpfin
(
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_gm
->
wmmat
[
2
]
>>
GM_ALPHA_PREC_DIFF
)
-
(
1
<<
GM_ALPHA_PREC_BITS
),
(
gm
->
wmmat
[
2
]
>>
GM_ALPHA_PREC_DIFF
)
-
(
1
<<
GM_ALPHA_PREC_BITS
));
if
(
gm
->
wmtype
!=
VERTRAPEZOID
)
params_cost
+=
aom_count_signed_primitive_refsubexpfin
(
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_gm
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
),
(
gm
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
));
if
(
gm
->
wmtype
>=
AFFINE
)
{
params_cost
+=
aom_count_signed_primitive_refsubexpfin
(
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_gm
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
),
(
gm
->
wmmat
[
3
]
>>
GM_ALPHA_PREC_DIFF
));
if
(
gm
->
wmtype
>=
AFFINE
)
{
if
(
gm
->
wmtype
!=
HORTRAPEZOID
)
params_cost
+=
aom_count_signed_primitive_refsubexpfin
(
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_gm
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
),
(
gm
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
));
(
ref_gm
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
),
(
gm
->
wmmat
[
4
]
>>
GM_ALPHA_PREC_DIFF
));
params_cost
+=
aom_count_signed_primitive_refsubexpfin
(
GM_ALPHA_MAX
+
1
,
SUBEXPFIN_K
,
(
ref_gm
->
wmmat
[
5
]
>>
GM_ALPHA_PREC_DIFF
)
-
...
...
av1/encoder/global_motion.c
View file @
1a2b35f9
...
...
@@ -116,9 +116,6 @@ static void force_wmtype(WarpedMotionParams *wm, TransformationType wmtype) {
wm
->
wmmat
[
3
]
=
0
;
case
ROTZOOM
:
wm
->
wmmat
[
4
]
=
-
wm
->
wmmat
[
3
];
wm
->
wmmat
[
5
]
=
wm
->
wmmat
[
2
];
case
AFFINE
:
wm
->
wmmat
[
6
]
=
wm
->
wmmat
[
7
]
=
0
;
break
;
case
HORTRAPEZOID
:
wm
->
wmmat
[
6
]
=
wm
->
wmmat
[
4
]
=
0
;
break
;
case
VERTRAPEZOID
:
wm
->
wmmat
[
7
]
=
wm
->
wmmat
[
3
]
=
0
;
break
;
case
HOMOGRAPHY
:
break
;
default:
assert
(
0
);
}
wm
->
wmtype
=
wmtype
;
...
...
@@ -134,7 +131,7 @@ int64_t refine_integerized_param(WarpedMotionParams *wm,
int
d_height
,
int
d_stride
,
int
n_refinements
,
int64_t
best_frame_error
)
{
static
const
int
max_trans_model_params
[
TRANS_TYPES
]
=
{
0
,
2
,
4
,
6
,
8
,
8
,
8
0
,
2
,
4
,
6
,
};
const
int
border
=
ERRORADV_BORDER
;
int
i
=
0
,
p
;
...
...
@@ -161,8 +158,6 @@ int64_t refine_integerized_param(WarpedMotionParams *wm,
for
(
p
=
0
;
p
<
n_params
;
++
p
)
{
int
step_dir
=
0
;
// Skip searches for parameters that are forced to be 0
if
(
wmtype
==
HORTRAPEZOID
&&
(
p
==
4
||
p
==
6
))
continue
;
if
(
wmtype
==
VERTRAPEZOID
&&
(
p
==
3
||
p
==
7
))
continue
;
param
=
param_mat
+
p
;
curr_param
=
*
param
;
best_param
=
curr_param
;
...
...
@@ -229,9 +224,6 @@ int64_t refine_integerized_param(WarpedMotionParams *wm,
static
INLINE
RansacFunc
get_ransac_type
(
TransformationType
type
)
{
switch
(
type
)
{
case
HOMOGRAPHY
:
return
ransac_homography
;
case
HORTRAPEZOID
:
return
ransac_hortrapezoid
;
case
VERTRAPEZOID
:
return
ransac_vertrapezoid
;
case
AFFINE
:
return
ransac_affine
;
case
ROTZOOM
:
return
ransac_rotzoom
;
case
TRANSLATION
:
return
ransac_translation
;
...
...
av1/encoder/ransac.c
View file @
1a2b35f9
...
...
@@ -80,60 +80,6 @@ static void project_points_double_affine(double *mat, double *points,
}
}
static
void
project_points_double_hortrapezoid
(
double
*
mat
,
double
*
points
,
double
*
proj
,
const
int
n
,
const
int
stride_points
,
const
int
stride_proj
)
{
int
i
;
double
x
,
y
,
Z
,
Z_inv
;
for
(
i
=
0
;
i
<
n
;
++
i
)
{
x
=
*
(
points
++
),
y
=
*
(
points
++
);
Z_inv
=
mat
[
7
]
*
y
+
1
;
assert
(
fabs
(
Z_inv
)
>
0
.
000001
);
Z
=
1
.
/
Z_inv
;
*
(
proj
++
)
=
(
mat
[
2
]
*
x
+
mat
[
3
]
*
y
+
mat
[
0
])
*
Z
;
*
(
proj
++
)
=
(
mat
[
5
]
*
y
+
mat
[
1
])
*
Z
;
points
+=
stride_points
-
2
;
proj
+=
stride_proj
-
2
;
}
}
static
void
project_points_double_vertrapezoid
(
double
*
mat
,
double
*
points
,
double
*
proj
,
const
int
n
,
const
int
stride_points
,
const
int
stride_proj
)
{
int
i
;
double
x
,
y
,
Z
,
Z_inv
;
for
(
i
=
0
;
i
<
n
;
++
i
)
{
x
=
*
(
points
++
),
y
=
*
(
points
++
);
Z_inv
=
mat
[
6
]
*
x
+
1
;
assert
(
fabs
(
Z_inv
)
>
0
.
000001
);
Z
=
1
.
/
Z_inv
;
*
(
proj
++
)
=
(
mat
[
2
]
*
x
+
mat
[
0
])
*
Z
;
*
(
proj
++
)
=
(
mat
[
4
]
*
x
+
mat
[
5
]
*
y
+
mat
[
1
])
*
Z
;
points
+=
stride_points
-
2
;
proj
+=
stride_proj
-
2
;
}
}
static
void
project_points_double_homography
(
double
*
mat
,
double
*
points
,
double
*
proj
,
const
int
n
,
const
int
stride_points
,
const
int
stride_proj
)
{
int
i
;
double
x
,
y
,
Z
,
Z_inv
;
for
(
i
=
0
;
i
<
n
;
++
i
)
{
x
=
*
(
points
++
),
y
=
*
(
points
++
);
Z_inv
=
mat
[
6
]
*
x
+
mat
[
7
]
*
y
+
1
;
assert
(
fabs
(
Z_inv
)
>
0
.
000001
);
Z
=
1
.
/
Z_inv
;
*
(
proj
++
)
=
(
mat
[
2
]
*
x
+
mat
[
3
]
*
y
+
mat
[
0
])
*
Z
;
*
(
proj
++
)
=
(
mat
[
4
]
*
x
+
mat
[
5
]
*
y
+
mat
[
1
])
*
Z
;
points
+=
stride_points
-
2
;
proj
+=
stride_proj
-
2
;
}
}
static
void
normalize_homography
(
double
*
pts
,
int
n
,
double
*
T
)
{
double
*
p
=
pts
;
double
mean
[
2
]
=
{
0
,
0
};
...
...
@@ -193,22 +139,6 @@ static void denormalize_homography(double *params, double *T1, double *T2) {
multiply_mat
(
iT2
,
params2
,
params
,
3
,
3
,
3
);
}
static
void
denormalize_homography_reorder
(
double
*
params
,
double
*
T1
,
double
*
T2
)
{
double
params_denorm
[
MAX_PARAMDIM
];
memcpy
(
params_denorm
,
params
,
sizeof
(
*
params
)
*
8
);
params_denorm
[
8
]
=
1
.
0
;
denormalize_homography
(
params_denorm
,
T1
,
T2
);
params
[
0
]
=
params_denorm
[
2
];
params
[
1
]
=
params_denorm
[
5
];
params
[
2
]
=
params_denorm
[
0
];
params
[
3
]
=
params_denorm
[
1
];
params
[
4
]
=
params_denorm
[
3
];
params
[
5
]
=
params_denorm
[
4
];
params
[
6
]
=
params_denorm
[
6
];
params
[
7
]
=
params_denorm
[
7
];
}
static
void
denormalize_affine_reorder
(
double
*
params
,
double
*
T1
,
double
*
T2
)
{
double
params_denorm
[
MAX_PARAMDIM
];
params_denorm
[
0
]
=
params
[
0
];
...
...
@@ -377,217 +307,6 @@ static int find_affine(int np, double *pts1, double *pts2, double *mat) {
return
0
;
}
static
int
find_vertrapezoid
(
int
np
,
double
*
pts1
,
double
*
pts2
,
double
*
mat
)
{
const
int
np3
=
np
*
3
;
double
*
a
=
(
double
*
)
aom_malloc
(
sizeof
(
*
a
)
*
np3
*
14
);
double
*
U
=
a
+
np3
*
7
;
double
S
[
7
],
V
[
7
*
7
],
H
[
9
];
int
i
,
mini
;
double
sx
,
sy
,
dx
,
dy
;
double
T1
[
9
],
T2
[
9
];
normalize_homography
(
pts1
,
np
,
T1
);
normalize_homography
(
pts2
,
np
,
T2
);
for
(
i
=
0
;
i
<
np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
1
]
=
V
[
i
*
7
+
mini
];
for
(;
i
<
7
;
i
++
)
H
[
i
+
2
]
=
V
[
i
*
7
+
mini
];
denormalize_homography_reorder
(
H
,
T1
,
T2
);
aom_free
(
a
);
if
(
H
[
8
]
==
0
.
0
)
{
return
1
;
}
else
{
// normalize
double
f
=
1
.
0
/
H
[
8
];
for
(
i
=
0
;
i
<
8
;
i
++
)
mat
[
i
]
=
f
*
H
[
i
];
}
return
0
;
}
static
int
find_hortrapezoid
(
int
np
,
double
*
pts1
,
double
*
pts2
,
double
*
mat
)
{
const
int
np3
=
np
*
3
;
double
*
a
=
(
double
*
)
aom_malloc
(
sizeof
(
*
a
)
*
np3
*
14
);
double
*
U
=
a
+
np3
*
7
;
double
S
[
7
],
V
[
7
*
7
],
H
[
9
];
int
i
,
mini
;
double
sx
,
sy
,
dx
,
dy
;
double
T1
[
9
],
T2
[
9
];
normalize_homography
(
pts1
,
np
,
T1
);
normalize_homography
(
pts2
,
np
,
T2
);
for
(
i
=
0
;
i
<
np
;
++
i
)
{
dx
=
*
(
pts2
++
);
dy
=
*
(
pts2
++
);
sx
=
*
(
pts1
++
);
sy
=
*
(
pts1
++
);
a
[
i
*
3
*
7
+
0
]
=
a
[
i
*
3
*
7
+
1
]
=
a
[
i
*
3
*
7
+
2
]
=
0
;
a
[
i
*
3
*
7
+
3
]
=
-
sy
;
a
[
i
*
3
*
7
+
4
]
=
-
1
;
a
[
i
*
3
*
7
+
5
]
=
dy
*
sy
;
a
[
i
*
3
*
7
+
6
]
=
dy
;
a
[(
i
*
3
+
1
)
*
7
+
0
]
=
sx
;
a
[(
i
*
3
+
1
)
*
7
+
1
]
=
sy
;
a
[(
i
*
3
+
1
)
*
7
+
2
]
=
1
;
a
[(
i
*
3
+
1
)
*
7
+
3
]
=
a
[(
i
*
3
+
1
)
*
7
+
4
]
=
0
;
a
[(
i
*
3
+
1
)
*
7
+
5
]
=
-
dx
*
sy
;
a
[(
i
*
3
+
1
)
*
7
+
6
]
=
-
dx
;
a
[(
i
*
3
+
2
)
*
7
+
0
]
=
-
dy
*
sx
;
a
[(
i
*
3
+
2
)
*
7
+
1
]
=
-
dy
*
sy
;
a
[(
i
*
3
+
2
)
*
7
+
2
]
=
-
dy
;
a
[(
i
*
3
+
2
)
*
7
+
3
]
=
dx
*
sy
;
a
[(
i
*
3
+
2
)
*
7
+
4
]
=
dx
;
a
[(
i
*
3
+
2
)
*
7
+
5
]
=
a
[(
i
*
3
+
2
)
*
7
+
6
]
=
0
;
}
if
(
SVD
(
U
,
S
,
V
,
a
,
np3
,
7
))
{
aom_free
(
a
);
return
1
;
}
else
{
double
minS
=
1e12
;
mini
=
-
1
;
for
(
i
=
0
;
i
<
7
;
++
i
)
{
if
(
S
[
i
]
<
minS
)
{
minS
=
S
[
i
];
mini
=
i
;
}
}
}
H
[
3
]
=
H
[
6
]
=
0
;
for
(
i
=
0
;
i
<
3
;
i
++
)
H
[
i
]
=
V
[
i
*
7
+
mini
];
for
(;
i
<
5
;
i
++
)
H
[
i
+
1
]
=
V
[
i
*
7
+
mini
];
for
(;
i
<
7
;
i
++
)
H
[
i
+
2
]
=
V
[
i
*
7
+
mini
];
denormalize_homography_reorder
(
H
,
T1
,
T2
);
aom_free
(
a
);
if
(
H
[
8
]
==
0
.
0
)
{
return
1
;
}
else
{
// normalize
double
f
=
1
.
0
/
H
[
8
];
for
(
i
=
0
;
i
<
8
;
i
++
)
mat
[
i
]
=
f
*
H
[
i
];
}
return
0
;
}
static
int
find_homography
(
int
np
,
double
*
pts1
,
double
*
pts2
,
double
*
mat
)
{
// Implemented from Peter Kovesi's normalized implementation
const
int
np3
=
np
*
3
;
double
*
a
=
(
double
*
)
aom_malloc
(
sizeof
(
*
a
)
*
np3
*
18
);
double
*
U
=
a
+
np3
*
9
;
double
S
[
9
],
V
[
9
*
9
],
H
[
9
];
int
i
,
mini
;
double
sx
,
sy
,
dx
,
dy
;
double
T1
[
9
],
T2
[
9
];
normalize_homography
(
pts1
,
np
,
T1
);
normal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np3
,
9
))
{
aom_free
(
a
);
return
1
;
}
else
{
double
minS
=
1e12
;
mini
=
-
1
;
for
(
i
=
0
;
i
<
9
;
++
i
)
{
if
(
S
[
i
]
<
minS
)
{
minS
=
S
[
i
];
mini
=
i
;
}
}
}
for
(
i
=
0
;
i
<
9
;
i
++
)
H
[
i
]
=
V
[
i
*
9
+
mini
];
denormalize_homography_reorder
(
H
,
T1
,
T2
);
aom_free
(
a
);
if
(
H
[
8
]
==
0
.
0
)
{
return
1
;
}
else
{
// normalize
double
f
=
1
.
0
/
H
[
8
];
for
(
i
=
0
;
i
<
8
;
i
++
)
mat
[
i
]
=
f
*
H
[
i
];
}
return
0
;
}
static
int
get_rand_indices
(
int
npoints
,
int
minpts
,
int
*
indices
,
unsigned
int
*
seed
)
{
int
i
,
j
;
...
...
@@ -860,11 +579,6 @@ static int is_degenerate_affine(double *p) {
return
is_collinear3
(
p
,
p
+
2
,
p
+
4
);
}
static
int
is_degenerate_homography
(
double
*
p
)
{
return
is_collinear3
(
p
,
p
+
2
,
p
+
4
)
||
is_collinear3
(
p
,
p
+
2
,
p
+
6
)
||
is_collinear3
(
p
,
p
+
4
,
p
+
6
)
||
is_collinear3
(
p
+
2
,
p
+
4
,
p
+
6
);
}
int
ransac_translation
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_desired_motions
)
{
...
...
@@ -887,30 +601,3 @@ int ransac_affine(int *matched_points, int npoints, int *num_inliers_by_motion,
params_by_motion
,
num_desired_motions
,
3
,
is_degenerate_affine
,
find_affine
,
project_points_double_affine
);
}
int
ransac_homography
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_desired_motions
)
{
return
ransac
(
matched_points
,
npoints
,
num_inliers_by_motion
,
params_by_motion
,
num_desired_motions
,
4
,
is_degenerate_homography
,
find_homography
,
project_points_double_homography
);
}
int
ransac_hortrapezoid
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_desired_motions
)
{
return
ransac
(
matched_points
,
npoints
,
num_inliers_by_motion
,
params_by_motion
,
num_desired_motions
,
4
,
is_degenerate_homography
,
find_hortrapezoid
,
project_points_double_hortrapezoid
);
}
int
ransac_vertrapezoid
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_desired_motions
)
{
return
ransac
(
matched_points
,
npoints
,
num_inliers_by_motion
,
params_by_motion
,
num_desired_motions
,
4
,
is_degenerate_homography
,
find_vertrapezoid
,
project_points_double_vertrapezoid
);
}
av1/encoder/ransac.h
View file @
1a2b35f9
...
...
@@ -25,17 +25,8 @@ typedef int (*RansacFunc)(int *matched_points, int npoints,
/* Each of these functions fits a motion model from a set of
corresponding points in 2 frames using RANSAC. */
int
ransac_homography
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_motions
);
int
ransac_affine
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_motions
);
int
ransac_hortrapezoid
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_motions
);
int
ransac_vertrapezoid
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_motions
);
int
ransac_rotzoom
(
int
*
matched_points
,
int
npoints
,
int
*
num_inliers_by_motion
,
double
*
params_by_motion
,
int
num_motions
);
int
ransac_translation
(
int
*
matched_points
,
int
npoints
,
...
...