Tracking: Specify image image for (un)distortion model
Allows to support distortion models which needs to know actual image dimensions to apply or inverse camera intrinsics.
This commit is contained in:
parent
665bf41f3c
commit
3135791395
Notes:
blender-bot
2023-02-14 00:37:17 +01:00
Referenced by issue #76277, Enabling Viewer Border in Compositor Crashes Blender
|
@ -261,8 +261,16 @@ void BKE_tracking_distortion_undistort_v2(struct MovieDistortion *distortion,
|
|||
float r_co[2]);
|
||||
void BKE_tracking_distortion_free(struct MovieDistortion *distortion);
|
||||
|
||||
void BKE_tracking_distort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]);
|
||||
void BKE_tracking_undistort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]);
|
||||
void BKE_tracking_distort_v2(struct MovieTracking *tracking,
|
||||
int image_width,
|
||||
int image_height,
|
||||
const float co[2],
|
||||
float r_co[2]);
|
||||
void BKE_tracking_undistort_v2(struct MovieTracking *tracking,
|
||||
int image_width,
|
||||
int image_height,
|
||||
const float co[2],
|
||||
float r_co[2]);
|
||||
|
||||
struct ImBuf *BKE_tracking_undistort_frame(struct MovieTracking *tracking,
|
||||
struct ImBuf *ibuf,
|
||||
|
@ -276,6 +284,8 @@ struct ImBuf *BKE_tracking_distort_frame(struct MovieTracking *tracking,
|
|||
float overscan);
|
||||
|
||||
void BKE_tracking_max_distortion_delta_across_bound(struct MovieTracking *tracking,
|
||||
int image_width,
|
||||
int image_height,
|
||||
struct rcti *rect,
|
||||
bool undistort,
|
||||
float delta[2]);
|
||||
|
|
|
@ -4694,7 +4694,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase
|
|||
pos[0] *= width;
|
||||
pos[1] *= height;
|
||||
|
||||
BKE_tracking_undistort_v2(tracking, pos, pos);
|
||||
BKE_tracking_undistort_v2(tracking, width, height, pos, pos);
|
||||
|
||||
/* Normalize pixel coordinates back. */
|
||||
pos[0] /= width;
|
||||
|
|
|
@ -1512,7 +1512,8 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip
|
|||
undist_marker.pos[0] *= width;
|
||||
undist_marker.pos[1] *= height * aspy;
|
||||
|
||||
BKE_tracking_undistort_v2(&clip->tracking, undist_marker.pos, undist_marker.pos);
|
||||
BKE_tracking_undistort_v2(
|
||||
&clip->tracking, width, height, undist_marker.pos, undist_marker.pos);
|
||||
|
||||
undist_marker.pos[0] /= width;
|
||||
undist_marker.pos[1] /= height * aspy;
|
||||
|
|
|
@ -2288,13 +2288,15 @@ void BKE_tracking_distortion_free(MovieDistortion *distortion)
|
|||
MEM_freeN(distortion);
|
||||
}
|
||||
|
||||
void BKE_tracking_distort_v2(MovieTracking *tracking, const float co[2], float r_co[2])
|
||||
void BKE_tracking_distort_v2(
|
||||
MovieTracking *tracking, int image_width, int image_height, const float co[2], float r_co[2])
|
||||
{
|
||||
const MovieTrackingCamera *camera = &tracking->camera;
|
||||
const float aspy = 1.0f / tracking->camera.pixel_aspect;
|
||||
|
||||
libmv_CameraIntrinsicsOptions camera_intrinsics_options;
|
||||
tracking_cameraIntrinscisOptionsFromTracking(tracking, 0, 0, &camera_intrinsics_options);
|
||||
tracking_cameraIntrinscisOptionsFromTracking(
|
||||
tracking, image_width, image_height, &camera_intrinsics_options);
|
||||
libmv_CameraIntrinsics *intrinsics = libmv_cameraIntrinsicsNew(&camera_intrinsics_options);
|
||||
|
||||
/* Normalize coordinates. */
|
||||
|
@ -2309,13 +2311,15 @@ void BKE_tracking_distort_v2(MovieTracking *tracking, const float co[2], float r
|
|||
r_co[1] = y;
|
||||
}
|
||||
|
||||
void BKE_tracking_undistort_v2(MovieTracking *tracking, const float co[2], float r_co[2])
|
||||
void BKE_tracking_undistort_v2(
|
||||
MovieTracking *tracking, int image_width, int image_height, const float co[2], float r_co[2])
|
||||
{
|
||||
const MovieTrackingCamera *camera = &tracking->camera;
|
||||
const float aspy = 1.0f / tracking->camera.pixel_aspect;
|
||||
|
||||
libmv_CameraIntrinsicsOptions camera_intrinsics_options;
|
||||
tracking_cameraIntrinscisOptionsFromTracking(tracking, 0, 0, &camera_intrinsics_options);
|
||||
tracking_cameraIntrinscisOptionsFromTracking(
|
||||
tracking, image_width, image_height, &camera_intrinsics_options);
|
||||
libmv_CameraIntrinsics *intrinsics = libmv_cameraIntrinsicsNew(&camera_intrinsics_options);
|
||||
|
||||
double x = co[0], y = co[1];
|
||||
|
@ -2361,13 +2365,19 @@ ImBuf *BKE_tracking_distort_frame(MovieTracking *tracking,
|
|||
}
|
||||
|
||||
void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking,
|
||||
int image_width,
|
||||
int image_height,
|
||||
rcti *rect,
|
||||
bool undistort,
|
||||
float delta[2])
|
||||
{
|
||||
float pos[2], warped_pos[2];
|
||||
const int coord_delta = 5;
|
||||
void (*apply_distortion)(MovieTracking * tracking, const float pos[2], float out[2]);
|
||||
void (*apply_distortion)(MovieTracking * tracking,
|
||||
int image_width,
|
||||
int image_height,
|
||||
const float pos[2],
|
||||
float out[2]);
|
||||
|
||||
if (undistort) {
|
||||
apply_distortion = BKE_tracking_undistort_v2;
|
||||
|
@ -2387,7 +2397,7 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking,
|
|||
pos[0] = a;
|
||||
pos[1] = rect->ymin;
|
||||
|
||||
apply_distortion(tracking, pos, warped_pos);
|
||||
apply_distortion(tracking, image_width, image_height, pos, warped_pos);
|
||||
|
||||
delta[0] = max_ff(delta[0], fabsf(pos[0] - warped_pos[0]));
|
||||
delta[1] = max_ff(delta[1], fabsf(pos[1] - warped_pos[1]));
|
||||
|
@ -2396,7 +2406,7 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking,
|
|||
pos[0] = a;
|
||||
pos[1] = rect->ymax;
|
||||
|
||||
apply_distortion(tracking, pos, warped_pos);
|
||||
apply_distortion(tracking, image_width, image_height, pos, warped_pos);
|
||||
|
||||
delta[0] = max_ff(delta[0], fabsf(pos[0] - warped_pos[0]));
|
||||
delta[1] = max_ff(delta[1], fabsf(pos[1] - warped_pos[1]));
|
||||
|
@ -2415,7 +2425,7 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking,
|
|||
pos[0] = rect->xmin;
|
||||
pos[1] = a;
|
||||
|
||||
apply_distortion(tracking, pos, warped_pos);
|
||||
apply_distortion(tracking, image_width, image_height, pos, warped_pos);
|
||||
|
||||
delta[0] = max_ff(delta[0], fabsf(pos[0] - warped_pos[0]));
|
||||
delta[1] = max_ff(delta[1], fabsf(pos[1] - warped_pos[1]));
|
||||
|
@ -2424,7 +2434,7 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking,
|
|||
pos[0] = rect->xmax;
|
||||
pos[1] = a;
|
||||
|
||||
apply_distortion(tracking, pos, warped_pos);
|
||||
apply_distortion(tracking, image_width, image_height, pos, warped_pos);
|
||||
|
||||
delta[0] = max_ff(delta[0], fabsf(pos[0] - warped_pos[0]));
|
||||
delta[1] = max_ff(delta[1], fabsf(pos[1] - warped_pos[1]));
|
||||
|
|
|
@ -50,7 +50,8 @@ void MovieDistortionOperation::initExecution()
|
|||
full_frame.xmin = full_frame.ymin = 0;
|
||||
full_frame.xmax = this->m_width;
|
||||
full_frame.ymax = this->m_height;
|
||||
BKE_tracking_max_distortion_delta_across_bound(tracking, &full_frame, !this->m_apply, delta);
|
||||
BKE_tracking_max_distortion_delta_across_bound(
|
||||
tracking, this->m_width, this->m_height, &full_frame, !this->m_apply, delta);
|
||||
|
||||
/* 5 is just in case we didn't hit real max of distortion in
|
||||
* BKE_tracking_max_undistortion_delta_across_bound
|
||||
|
|
|
@ -1651,7 +1651,7 @@ static void draw_tracking_tracks(SpaceClip *sc,
|
|||
pos[0] = (pos[0] / (pos[3] * 2.0f) + 0.5f) * width;
|
||||
pos[1] = (pos[1] / (pos[3] * 2.0f) + 0.5f) * height * aspy;
|
||||
|
||||
BKE_tracking_distort_v2(tracking, pos, npos);
|
||||
BKE_tracking_distort_v2(tracking, width, height, pos, npos);
|
||||
|
||||
if (npos[0] >= 0.0f && npos[1] >= 0.0f && npos[0] <= width && npos[1] <= height * aspy) {
|
||||
vec[0] = (marker->pos[0] + track->offset[0]) * width;
|
||||
|
@ -1777,7 +1777,7 @@ static void draw_distortion(SpaceClip *sc,
|
|||
for (i = 0; i <= n; i++) {
|
||||
for (j = 0; j <= n; j++) {
|
||||
if (i == 0 || j == 0 || i == n || j == n) {
|
||||
BKE_tracking_distort_v2(tracking, pos, tpos);
|
||||
BKE_tracking_distort_v2(tracking, width, height, pos, tpos);
|
||||
|
||||
for (a = 0; a < 4; a++) {
|
||||
int ok;
|
||||
|
@ -1810,7 +1810,7 @@ static void draw_distortion(SpaceClip *sc,
|
|||
pos[0] = idx[a][0] * dx;
|
||||
pos[1] = idx[a][1] * dy;
|
||||
|
||||
BKE_tracking_undistort_v2(tracking, pos, tpos);
|
||||
BKE_tracking_undistort_v2(tracking, width, height, pos, tpos);
|
||||
|
||||
minmax_v2v2_v2(min, max, tpos);
|
||||
}
|
||||
|
@ -1821,7 +1821,7 @@ static void draw_distortion(SpaceClip *sc,
|
|||
|
||||
for (i = 0; i <= n; i++) {
|
||||
for (j = 0; j <= n; j++) {
|
||||
BKE_tracking_distort_v2(tracking, pos, grid[i][j]);
|
||||
BKE_tracking_distort_v2(tracking, width, height, pos, grid[i][j]);
|
||||
|
||||
grid[i][j][0] /= width;
|
||||
grid[i][j][1] /= height * aspy;
|
||||
|
@ -1897,8 +1897,8 @@ static void draw_distortion(SpaceClip *sc,
|
|||
|
||||
/* we want to distort only long straight lines */
|
||||
if (stroke->totpoints == 2) {
|
||||
BKE_tracking_undistort_v2(tracking, pos, pos);
|
||||
BKE_tracking_undistort_v2(tracking, npos, npos);
|
||||
BKE_tracking_undistort_v2(tracking, width, height, pos, pos);
|
||||
BKE_tracking_undistort_v2(tracking, width, height, npos, npos);
|
||||
}
|
||||
|
||||
sub_v2_v2v2(dpos, npos, pos);
|
||||
|
@ -1907,7 +1907,7 @@ static void draw_distortion(SpaceClip *sc,
|
|||
immBegin(GPU_PRIM_LINE_STRIP, steps + 1);
|
||||
|
||||
for (j = 0; j <= steps; j++) {
|
||||
BKE_tracking_distort_v2(tracking, pos, tpos);
|
||||
BKE_tracking_distort_v2(tracking, width, height, pos, tpos);
|
||||
immVertex2f(position, tpos[0] / width, tpos[1] / (height * aspy));
|
||||
|
||||
add_v2_v2(pos, dpos);
|
||||
|
|
|
@ -546,7 +546,7 @@ void ED_clip_point_undistorted_pos(SpaceClip *sc, const float co[2], float r_co[
|
|||
r_co[0] *= width;
|
||||
r_co[1] *= height * aspy;
|
||||
|
||||
BKE_tracking_undistort_v2(&clip->tracking, r_co, r_co);
|
||||
BKE_tracking_undistort_v2(&clip->tracking, width, height, r_co, r_co);
|
||||
|
||||
r_co[0] /= width;
|
||||
r_co[1] /= height * aspy;
|
||||
|
@ -580,7 +580,7 @@ void ED_clip_point_stable_pos(
|
|||
float aspy = 1.0f / tracking->camera.pixel_aspect;
|
||||
float tmp[2] = {*xr * width, *yr * height * aspy};
|
||||
|
||||
BKE_tracking_distort_v2(tracking, tmp, tmp);
|
||||
BKE_tracking_distort_v2(tracking, width, height, tmp, tmp);
|
||||
|
||||
*xr = tmp[0] / width;
|
||||
*yr = tmp[1] / (height * aspy);
|
||||
|
|
|
@ -166,7 +166,8 @@ static float calculate_reprojection_error_at_marker(MovieClip *clip,
|
|||
reprojected_position[1] = (reprojected_position[1] / (reprojected_position[3] * 2.0f) + 0.5f) *
|
||||
clip_height * aspy;
|
||||
|
||||
BKE_tracking_distort_v2(tracking, reprojected_position, reprojected_position);
|
||||
BKE_tracking_distort_v2(
|
||||
tracking, clip_width, clip_height, reprojected_position, reprojected_position);
|
||||
|
||||
marker_position[0] = (marker->pos[0] + track->offset[0]) * clip_width;
|
||||
marker_position[1] = (marker->pos[1] + track->offset[1]) * clip_height * aspy;
|
||||
|
|
Loading…
Reference in New Issue