2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2011 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-12-30 12:03:59 +01:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2013-12-30 12:03:59 +01:00
|
|
|
*
|
|
|
|
* This file contains declarations of function which are used
|
|
|
|
* by multiple tracking files but which should not be public.
|
|
|
|
*/
|
|
|
|
|
2014-01-12 12:05:24 +01:00
|
|
|
#pragma once
|
2013-12-30 12:03:59 +01:00
|
|
|
|
2014-02-13 13:31:02 +01:00
|
|
|
#include "BLI_threads.h"
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-12-30 12:03:59 +01:00
|
|
|
struct GHash;
|
|
|
|
struct MovieTracking;
|
|
|
|
struct MovieTrackingMarker;
|
|
|
|
|
2014-02-20 14:41:05 +01:00
|
|
|
struct libmv_CameraIntrinsicsOptions;
|
|
|
|
|
2013-12-30 12:03:59 +01:00
|
|
|
/*********************** Tracks map *************************/
|
|
|
|
|
|
|
|
typedef struct TracksMap {
|
|
|
|
char object_name[MAX_NAME];
|
|
|
|
|
|
|
|
int num_tracks;
|
|
|
|
MovieTrackingTrack *tracks;
|
|
|
|
|
|
|
|
struct GHash *hash;
|
|
|
|
|
|
|
|
int ptr;
|
2014-02-13 13:31:02 +01:00
|
|
|
|
|
|
|
/* Spin lock is used to sync context during tracking. */
|
|
|
|
SpinLock spin_lock;
|
2013-12-30 12:03:59 +01:00
|
|
|
} TracksMap;
|
|
|
|
|
2023-03-02 15:09:50 +01:00
|
|
|
struct TracksMap *tracks_map_new(const char *object_name, int num_tracks);
|
2013-12-30 12:03:59 +01:00
|
|
|
int tracks_map_get_size(struct TracksMap *map);
|
2023-03-02 15:09:50 +01:00
|
|
|
void tracks_map_insert(struct TracksMap *map, struct MovieTrackingTrack *track);
|
|
|
|
void tracks_map_free(struct TracksMap *map);
|
2013-12-30 12:03:59 +01:00
|
|
|
void tracks_map_merge(struct TracksMap *map, struct MovieTracking *tracking);
|
|
|
|
|
|
|
|
/*********************** Space transformation functions *************************/
|
|
|
|
|
|
|
|
void tracking_get_search_origin_frame_pixel(int frame_width,
|
|
|
|
int frame_height,
|
|
|
|
const struct MovieTrackingMarker *marker,
|
|
|
|
float frame_pixel[2]);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Each marker has 5 coordinates associated with it that get warped with
|
|
|
|
* tracking: the four corners ("pattern_corners"), and the center ("pos").
|
|
|
|
* This function puts those 5 points into the appropriate frame for tracking
|
|
|
|
* (the "search" coordinate frame).
|
|
|
|
*/
|
2013-12-30 12:03:59 +01:00
|
|
|
void tracking_get_marker_coords_for_tracking(int frame_width,
|
|
|
|
int frame_height,
|
|
|
|
const struct MovieTrackingMarker *marker,
|
|
|
|
double search_pixel_x[5],
|
|
|
|
double search_pixel_y[5]);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Inverse of #tracking_get_marker_coords_for_tracking.
|
|
|
|
*/
|
2013-12-30 12:03:59 +01:00
|
|
|
void tracking_set_marker_coords_from_tracking(int frame_width,
|
|
|
|
int frame_height,
|
|
|
|
struct MovieTrackingMarker *marker,
|
|
|
|
const double search_pixel_x[5],
|
|
|
|
const double search_pixel_y[5]);
|
|
|
|
|
2022-11-18 17:15:13 +01:00
|
|
|
/**
|
|
|
|
* Convert the lens principal point (optical center) between normalized and pixel spaces.
|
|
|
|
*
|
|
|
|
* The normalized space stores principal point relative to the frame center which has normalized
|
2022-12-05 02:58:18 +01:00
|
|
|
* principal coordinate of (0, 0). The right top corner of the frame corresponds to a normalized
|
|
|
|
* principal coordinate of (1, 1), and the left bottom corner corresponds to coordinate of
|
2022-11-18 17:15:13 +01:00
|
|
|
* (-1, -1).
|
|
|
|
*
|
2022-12-05 02:58:18 +01:00
|
|
|
* The pixel space is measured in pixels, with the reference being the left bottom corner of
|
2022-11-18 17:15:13 +01:00
|
|
|
* the frame.
|
|
|
|
*/
|
|
|
|
void tracking_principal_point_normalized_to_pixel(const float principal_point_normalized[2],
|
|
|
|
int frame_width,
|
|
|
|
int frame_height,
|
|
|
|
float r_principal_point_pixel[2]);
|
|
|
|
void tracking_principal_point_pixel_to_normalized(const float principal_point_pixel[2],
|
|
|
|
int frame_width,
|
|
|
|
int frame_height,
|
|
|
|
float r_principal_point_normalized[2]);
|
|
|
|
|
2013-12-30 12:03:59 +01:00
|
|
|
/*********************** General purpose utility functions *************************/
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Place a disabled marker before or after specified ref_marker.
|
|
|
|
*
|
|
|
|
* If before is truth, disabled marker is placed before reference
|
|
|
|
* one, and it's placed after it otherwise.
|
|
|
|
*
|
|
|
|
* If there's already a marker at the frame where disabled one is expected to be placed,
|
|
|
|
* nothing will happen if overwrite is false.
|
|
|
|
*/
|
2013-12-30 12:03:59 +01:00
|
|
|
void tracking_marker_insert_disabled(struct MovieTrackingTrack *track,
|
|
|
|
const struct MovieTrackingMarker *ref_marker,
|
|
|
|
bool before,
|
|
|
|
bool overwrite);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Fill in Libmv C-API camera intrinsics options from tracking structure.
|
|
|
|
*/
|
2014-02-20 14:41:05 +01:00
|
|
|
void tracking_cameraIntrinscisOptionsFromTracking(
|
|
|
|
struct MovieTracking *tracking,
|
|
|
|
int calibration_width,
|
|
|
|
int calibration_height,
|
|
|
|
struct libmv_CameraIntrinsicsOptions *camera_intrinsics_options);
|
|
|
|
|
|
|
|
void tracking_trackingCameraFromIntrinscisOptions(
|
|
|
|
struct MovieTracking *tracking,
|
|
|
|
const struct libmv_CameraIntrinsicsOptions *camera_intrinsics_options);
|
|
|
|
|
2014-06-22 16:19:48 +02:00
|
|
|
struct libmv_TrackRegionOptions;
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Fill in libmv tracker options structure with settings need to be used to perform track.
|
|
|
|
*/
|
2014-06-22 16:19:48 +02:00
|
|
|
void tracking_configure_tracker(const MovieTrackingTrack *track,
|
|
|
|
float *mask,
|
2021-03-15 15:48:15 +01:00
|
|
|
bool is_backwards,
|
2014-06-22 16:19:48 +02:00
|
|
|
struct libmv_TrackRegionOptions *options);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get previous keyframed marker.
|
|
|
|
*/
|
2014-06-22 16:19:48 +02:00
|
|
|
struct MovieTrackingMarker *tracking_get_keyframed_marker(struct MovieTrackingTrack *track,
|
|
|
|
int current_frame,
|
|
|
|
bool backwards);
|
|
|
|
|
2017-05-26 15:21:15 +02:00
|
|
|
/*********************** Masking *************************/
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Region is in pixel space, relative to marker's center.
|
|
|
|
*/
|
2022-10-04 16:57:16 +02:00
|
|
|
float *tracking_track_get_mask_for_region(const int frame_width,
|
|
|
|
const int frame_height,
|
2017-05-26 15:21:15 +02:00
|
|
|
const float region_min[2],
|
|
|
|
const float region_max[2],
|
2022-10-04 16:57:16 +02:00
|
|
|
const MovieTrackingTrack *track);
|
2017-05-26 15:21:15 +02:00
|
|
|
|
2021-02-05 06:23:34 +01:00
|
|
|
/*********************** Frame Accessor *************************/
|
2014-06-22 16:19:48 +02:00
|
|
|
|
|
|
|
struct libmv_FrameAccessor;
|
|
|
|
|
|
|
|
#define MAX_ACCESSOR_CLIP 64
|
|
|
|
typedef struct TrackingImageAccessor {
|
|
|
|
struct MovieClip *clips[MAX_ACCESSOR_CLIP];
|
|
|
|
int num_clips;
|
2020-11-30 15:55:52 +01:00
|
|
|
|
|
|
|
/* Array of tracks which are being tracked.
|
|
|
|
* Points to actual track from the `MovieClip` (or multiple of them).
|
|
|
|
* This accessor owns the array, but not the tracks themselves. */
|
2017-05-26 15:21:15 +02:00
|
|
|
struct MovieTrackingTrack **tracks;
|
|
|
|
int num_tracks;
|
2020-11-30 15:55:52 +01:00
|
|
|
|
2014-06-22 16:19:48 +02:00
|
|
|
struct libmv_FrameAccessor *libmv_accessor;
|
2017-08-14 11:28:58 +02:00
|
|
|
SpinLock cache_lock;
|
2014-06-22 16:19:48 +02:00
|
|
|
} TrackingImageAccessor;
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Clips are used to access images of an actual footage.
|
2020-11-30 15:55:52 +01:00
|
|
|
* Tracks are used to access masks associated with the tracks.
|
|
|
|
*
|
2021-12-07 07:19:15 +01:00
|
|
|
* \note Both clips and tracks arrays are copied into the image accessor. It means that the caller
|
|
|
|
* is allowed to pass temporary arrays which are only valid during initialization.
|
|
|
|
*/
|
2014-06-22 16:19:48 +02:00
|
|
|
TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR_CLIP],
|
|
|
|
int num_clips,
|
2017-05-26 15:21:15 +02:00
|
|
|
MovieTrackingTrack **tracks,
|
2020-11-30 15:50:21 +01:00
|
|
|
int num_tracks);
|
2014-06-22 16:19:48 +02:00
|
|
|
void tracking_image_accessor_destroy(TrackingImageAccessor *accessor);
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|