image.vision\spatiotemporal\primitives.mbt
95.5% · 21 / 22 points · 174 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 时空基元 spatiotemporal/primitives - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 时空原语:TInterval / TFrame / TImage / TVideo。 - 7
// Spatiotemporal primitives: time interval, temporal frame, time-varying image, video. - 8
// - 9
// 核心思想(GeoVerse):时间不是属性标签,是原生第 3 维。 - 10
// 静态图像 = 单帧 TImage;动画/视频 = 多帧 TImage。 - 11
- 12
///| - 13
/// 时间区间 [start, end),单位秒。 - 14
/// 时间区间 [start Time interval [start - 15
#derive(Eq, @debug.Debug) - 16
pub(all) struct TInterval { - 17
start : Float - 18
end : Float - 19
} - 20
- 21
///| - 22
pub extend TInterval with @debug.Debug::{to_repr} - 23
- 24
///| - 25
pub extend TInterval with Eq::{not_equal, equal} - 26
- 27
///| - 28
/// 创建时间区间,要求 end >= start。 - 29
/// 创建时间区间;要求 end >= start Create a time interval; requires end >= start. - 30
pub fn TInterval::make( - 31
start : Float, - 32
end : Float, - 33
) -> TInterval raise @types.LoadError { - 34●
if end < start { - 35●
raise @types.LoadError::DecodeFailed( - 36
"TInterval::make: end 必须大于等于 start", - 37
) - 38
} - 39
{ start, end, } - 40
} - 41
- 42
///| - 43
/// 时间区间长度。 - 44
/// 时间区间时长 Duration of the time interval. - 45
pub fn TInterval::duration(self : TInterval) -> Float { - 46●
self.end - self.start - 47
} - 48
- 49
///| - 50
/// 时空帧:单帧图像 + 时间戳 + 持续时间。 - 51
/// 时间帧:带时间戳和时长的单帧图像 Temporal frame: a single image with timestamp and duration. - 52
#derive(Eq, @debug.Debug) - 53
pub(all) struct TFrame { - 54
image : @types.Image - 55
timestamp : Float - 56
duration : Float - 57
} - 58
- 59
///| - 60
pub extend TFrame with @debug.Debug::{to_repr} - 61
- 62
///| - 63
pub extend TFrame with Eq::{not_equal, equal} - 64
- 65
///| - 66
/// 创建时空帧。 - 67
/// 创建时间帧 Create a temporal frame. - 68
pub fn TFrame::make( - 69
image : @types.Image, - 70
timestamp : Float, - 71
duration : Float, - 72
) -> TFrame raise @types.LoadError { - 73●
if duration < 0.0F { - 74●
raise @types.LoadError::DecodeFailed("TFrame::make: duration 必须非负") - 75
} - 76
{ image, timestamp, duration, } - 77
} - 78
- 79
///| - 80
/// 时变图像:多帧序列 + 维度 + 帧率。 - 81
/// 时变图像:带尺寸和 fps 的多帧序列 Time-varying image: multi-frame sequence with dimensions and fps. - 82
#derive(Eq, @debug.Debug) - 83
pub(all) struct TImage { - 84
frames : Array[TFrame] - 85
width : Int32 - 86
height : Int32 - 87
channels : Int32 - 88
fps : Float - 89
} - 90
- 91
///| - 92
pub extend TImage with @debug.Debug::{to_repr} - 93
- 94
///| - 95
pub extend TImage with Eq::{not_equal, equal} - 96
- 97
///| - 98
/// 创建时变图像,所有帧尺寸必须一致。 - 99
/// 创建时变图像;所有帧须有相同尺寸 Create a time-varying image; all frames must have the same dimensions. - 100
pub fn TImage::make( - 101
frames : Array[TFrame], - 102
fps : Float, - 103
) -> TImage raise @types.LoadError { - 104●
if frames.length() == 0 { - 105●
raise @types.LoadError::DecodeFailed("TImage::make: 帧序列不能为空") - 106
} - 107
if fps <= 0.0F { - 108●
raise @types.LoadError::DecodeFailed("TImage::make: fps 必须大于0") - 109
} - 110
let first = frames[0] - 111
let w = first.image.width - 112
let h = first.image.height - 113
let ch = first.image.channels - 114●
for i in 1..<frames.length() { - 115●
let f = frames[i] - 116
if f.image.width != w || f.image.height != h || f.image.channels != ch { - 117○
raise @types.LoadError::DecodeFailed( - 118
"TImage::make: 所有帧尺寸和通道数必须一致", - 119
) - 120
} - 121
} - 122
{ frames, width: w, height: h, channels: ch, fps, } - 123
} - 124
- 125
///| - 126
/// 时变图像的帧数。 - 127
/// 时变图像帧数 Number of frames in the time-varying image. - 128
pub fn TImage::frame_count(self : TImage) -> Int32 { - 129●
self.frames.length() - 130
} - 131
- 132
///| - 133
/// 时变图像总时长(秒)。 - 134
/// 时变图像总时长(秒) Total duration of the time-varying image (seconds). - 135
pub fn TImage::total_duration(self : TImage) -> Float { - 136●
let mut sum = 0.0F - 137●
for i in 0..<self.frames.length() { - 138●
sum = sum + self.frames[i].duration - 139
} - 140
sum - 141
} - 142
- 143
///| - 144
/// 从单帧静态图像创建时变图像。 - 145
/// 创建时变图像;所有帧须有相同尺寸 Create a time-varying image from a single static image frame. - 146
pub fn TImage::from_static( - 147
image : @types.Image, - 148
) -> TImage raise @types.LoadError { - 149●
let frame = TFrame::make(image, 0.0F, 0.0F) - 150●
TImage::make([frame], 1.0F) - 151
} - 152
- 153
///| - 154
/// 时空视频:时变图像 + 元数据。 - 155
/// 时空视频:带元数据的时变图像 Spatiotemporal video: time-varying image with metadata. - 156
#derive(Eq, @debug.Debug) - 157
pub(all) struct TVideo { - 158
timage : TImage - 159
codec_name : String - 160
total_duration : Float - 161
} - 162
- 163
///| - 164
pub extend TVideo with @debug.Debug::{to_repr} - 165
- 166
///| - 167
pub extend TVideo with Eq::{not_equal, equal} - 168
- 169
///| - 170
/// 从时变图像创建视频。 - 171
/// 从时变图像创建视频 Create a video from a time-varying image. - 172
pub fn TVideo::from_timage(timage : TImage, codec_name : String) -> TVideo { - 173●
{ timage, codec_name, total_duration: timage.total_duration(), } - 174
}