Skip to main content

scirs2_vision/activity_recognition/
types.rs

1//! Plain data types for [`super`] (the activity-recognition engine and its
2//! result structures). Split out of the former monolithic
3//! `activity_recognition.rs` to keep files under the workspace's line-count
4//! policy; behavior is unchanged, only file layout.
5
6use scirs2_core::ndarray::{Array1, Array2, Array3};
7use std::collections::HashMap;
8
9/// Advanced-advanced activity_ recognition engine with multi-level analysis
10pub struct ActivityRecognitionEngine {
11    /// Action detection modules
12    pub(super) action_detectors: Vec<ActionDetector>,
13    /// Activity sequence analyzer
14    pub(super) sequence_analyzer: ActivitySequenceAnalyzer,
15    /// Multi-person interaction recognizer
16    pub(super) interaction_recognizer: MultiPersonInteractionRecognizer,
17    /// Context-aware activity_ classifier
18    pub(super) context_classifier: ContextAwareActivityClassifier,
19    /// Temporal activity_ modeler
20    pub(super) temporal_modeler: TemporalActivityModeler,
21    /// Hierarchical activity_ decomposer
22    pub(super) hierarchical_decomposer: HierarchicalActivityDecomposer,
23    /// Activity knowledge base
24    pub(super) knowledge_base: ActivityKnowledgeBase,
25    /// Grayscale intensity channel of the most recently processed frame,
26    /// used by [`Self::extract_motion_features`] to compute real
27    /// frame-to-frame optical flow. `&self`-taking methods update this via
28    /// interior mutability so callers don't need `&mut self` per frame.
29    pub(super) previous_frame: std::cell::RefCell<Option<Array3<f32>>>,
30}
31
32/// Action detection with advanced-high precision
33#[derive(Debug, Clone)]
34pub struct ActionDetector {
35    /// Detector name
36    pub(super) name: String,
37    /// Supported action types
38    pub(super) action_types: Vec<String>,
39    /// Detection confidence threshold
40    pub(super) confidence_threshold: f32,
41    /// Temporal window for action detection
42    pub(super) temporal_window: usize,
43    /// Feature extraction method
44    pub(super) feature_method: String,
45}
46
47/// Activity sequence analysis for understanding complex behaviors
48#[derive(Debug, Clone)]
49pub struct ActivitySequenceAnalyzer {
50    /// Maximum sequence length
51    pub(super) max_sequence_length: usize,
52    /// Sequence pattern models
53    pub(super) pattern_models: Vec<SequencePattern>,
54    /// Transition probabilities
55    pub(super) transition_models: HashMap<String, TransitionModel>,
56    /// Anomaly detection parameters
57    pub(super) anomaly_params: AnomalyDetectionParams,
58}
59
60/// Multi-person interaction recognition
61#[derive(Debug, Clone)]
62pub struct MultiPersonInteractionRecognizer {
63    /// Interaction types
64    pub(super) interaction_types: Vec<InteractionType>,
65    /// Person tracking parameters
66    pub(super) tracking_params: PersonTrackingParams,
67    /// Social distance modeling
68    pub(super) social_distance_model: SocialDistanceModel,
69    /// Group activity_ recognition
70    pub(super) group_recognition: GroupActivityRecognition,
71}
72
73/// Context-aware activity_ classification
74#[derive(Debug, Clone)]
75pub struct ContextAwareActivityClassifier {
76    /// Context features
77    pub(super) context_features: Vec<ContextFeature>,
78    /// Environment classifiers
79    pub(super) environment_classifiers: Vec<EnvironmentClassifier>,
80    /// Object-activity_ associations
81    pub(super) object_associations: HashMap<String, Vec<String>>,
82    /// Scene-activity_ correlations
83    pub(super) scene_correlations: HashMap<String, ActivityDistribution>,
84}
85
86/// Temporal activity_ modeling for understanding dynamics
87#[derive(Debug, Clone)]
88pub struct TemporalActivityModeler {
89    /// Temporal resolution
90    pub(super) temporal_resolution: f32,
91    /// Memory length for temporal modeling
92    pub(super) memory_length: usize,
93    /// Recurrent neural network parameters
94    pub(super) rnn_params: RNNParameters,
95    /// Attention mechanisms
96    pub(super) attention_mechanisms: Vec<TemporalAttention>,
97}
98
99/// Hierarchical activity_ decomposition
100#[derive(Debug, Clone)]
101pub struct HierarchicalActivityDecomposer {
102    /// Activity hierarchy levels
103    pub(super) hierarchy_levels: Vec<ActivityLevel>,
104    /// Decomposition rules
105    pub(super) decomposition_rules: Vec<DecompositionRule>,
106    /// Composition rules for building complex activities
107    pub(super) composition_rules: Vec<CompositionRule>,
108}
109
110/// Activity knowledge base for reasoning
111#[derive(Debug, Clone)]
112pub struct ActivityKnowledgeBase {
113    /// Activity definitions
114    pub(super) activity_definitions: HashMap<String, ActivityDefinition>,
115    /// Activity ontology
116    pub(super) ontology: ActivityOntology,
117    /// Common activity_ patterns
118    pub(super) common_patterns: Vec<ActivityPattern>,
119    /// Cultural activity_ variations
120    pub(super) cultural_variations: HashMap<String, Vec<ActivityVariation>>,
121}
122
123/// Comprehensive activity_ recognition result
124#[derive(Debug, Clone)]
125pub struct ActivityRecognitionResult {
126    /// Detected activities
127    pub activities: Vec<DetectedActivity>,
128    /// Activity sequences
129    pub sequences: Vec<ActivitySequence>,
130    /// Person interactions
131    pub interactions: Vec<PersonInteraction>,
132    /// Overall scene activity_ summary
133    pub scene_summary: ActivitySummary,
134    /// Temporal activity_ timeline
135    pub timeline: ActivityTimeline,
136    /// Confidence scores
137    pub confidence_scores: ConfidenceScores,
138    /// Uncertainty quantification
139    pub uncertainty: ActivityUncertainty,
140}
141
142/// Detected activity_ with rich metadata
143#[derive(Debug, Clone)]
144pub struct DetectedActivity {
145    /// Activity class
146    pub activity_class: String,
147    /// Activity subtype
148    pub subtype: Option<String>,
149    /// Confidence score
150    pub confidence: f32,
151    /// Temporal bounds (start, end)
152    pub temporal_bounds: (f32, f32),
153    /// Spatial region
154    pub spatial_region: Option<(f32, f32, f32, f32)>,
155    /// Involved persons
156    pub involved_persons: Vec<PersonID>,
157    /// Involved objects
158    pub involved_objects: Vec<ObjectID>,
159    /// Activity attributes
160    pub attributes: HashMap<String, f32>,
161    /// Motion characteristics
162    pub motion_characteristics: MotionCharacteristics,
163}
164
165/// Activity sequence representing complex behavior chains
166#[derive(Debug, Clone)]
167pub struct ActivitySequence {
168    /// Sequence ID
169    pub sequence_id: String,
170    /// Component activities
171    pub activities: Vec<DetectedActivity>,
172    /// Sequence type
173    pub sequence_type: String,
174    /// Sequence confidence
175    pub confidence: f32,
176    /// Transition probabilities
177    pub transitions: Vec<ActivityTransition>,
178    /// Sequence completeness
179    pub completeness: f32,
180}
181
182/// Person interaction recognition
183#[derive(Debug, Clone)]
184pub struct PersonInteraction {
185    /// Interaction type
186    pub interaction_type: String,
187    /// Participating persons
188    pub participants: Vec<PersonID>,
189    /// Interaction strength
190    pub strength: f32,
191    /// Duration
192    pub duration: f32,
193    /// Spatial proximity
194    pub proximity: f32,
195    /// Interaction attributes
196    pub attributes: HashMap<String, f32>,
197}
198
199/// Overall activity_ summary for the scene
200#[derive(Debug, Clone)]
201pub struct ActivitySummary {
202    /// Dominant activity_
203    pub dominant_activity: String,
204    /// Activity diversity index
205    pub diversity_index: f32,
206    /// Energy level of the scene
207    pub energy_level: f32,
208    /// Social interaction level
209    pub social_interaction_level: f32,
210    /// Activity complexity score
211    pub complexity_score: f32,
212    /// Unusual activity_ indicators
213    pub anomaly_indicators: Vec<AnomalyIndicator>,
214}
215
216/// Temporal activity_ timeline
217#[derive(Debug, Clone)]
218pub struct ActivityTimeline {
219    /// Timeline segments
220    pub segments: Vec<TimelineSegment>,
221    /// Timeline resolution
222    pub resolution: f32,
223    /// Activity flow patterns
224    pub flow_patterns: Vec<FlowPattern>,
225}
226
227/// Confidence scores for different aspects
228#[derive(Debug, Clone)]
229pub struct ConfidenceScores {
230    /// Overall recognition confidence
231    pub overall: f32,
232    /// Per-activity_ confidences
233    pub per_activity: HashMap<String, f32>,
234    /// Temporal segmentation confidence
235    pub temporal_segmentation: f32,
236    /// Spatial localization confidence
237    pub spatial_localization: f32,
238}
239
240/// Uncertainty quantification for activity_ recognition
241#[derive(Debug, Clone)]
242pub struct ActivityUncertainty {
243    /// Epistemic uncertainty (model uncertainty)
244    pub epistemic: f32,
245    /// Aleatoric uncertainty (data uncertainty)
246    pub aleatoric: f32,
247    /// Temporal uncertainty
248    pub temporal: f32,
249    /// Spatial uncertainty
250    pub spatial: f32,
251    /// Class confusion matrix
252    pub confusion_matrix: Array2<f32>,
253}
254
255// Supporting types for activity_ recognition
256/// Unique identifier for a person in the scene
257pub type PersonID = String;
258/// Unique identifier for an object in the scene
259pub type ObjectID = String;
260
261/// Motion characteristics of detected activities
262#[derive(Debug, Clone)]
263pub struct MotionCharacteristics {
264    /// Velocity of the motion
265    pub velocity: f32,
266    /// Acceleration of the motion
267    pub acceleration: f32,
268    /// Direction of the motion in radians
269    pub direction: f32,
270    /// Smoothness score of the motion
271    pub smoothness: f32,
272    /// Periodicity measure of the motion
273    pub periodicity: f32,
274}
275
276/// Transition between activities
277#[derive(Debug, Clone)]
278pub struct ActivityTransition {
279    /// Source activity_ name
280    pub from_activity: String,
281    /// Target activity_ name
282    pub to_activity: String,
283    /// Transition probability
284    pub probability: f32,
285    /// Typical duration of the transition
286    pub typical_duration: f32,
287}
288
289/// Indicator of anomalous behavior
290#[derive(Debug, Clone)]
291pub struct AnomalyIndicator {
292    /// Type of anomaly detected
293    pub anomaly_type: String,
294    /// Severity level of the anomaly
295    pub severity: f32,
296    /// Description of the anomaly
297    pub description: String,
298    /// Temporal location of the anomaly
299    pub temporal_location: f32,
300}
301
302/// Timeline segment representing a period of activity_
303#[derive(Debug, Clone)]
304pub struct TimelineSegment {
305    /// Start time of the segment
306    pub start_time: f32,
307    /// End time of the segment
308    pub end_time: f32,
309    /// Dominant activity_ in this segment
310    pub dominant_activity: String,
311    /// Mix of activities and their proportions
312    pub activity_mix: HashMap<String, f32>,
313}
314
315/// Flow pattern in activity_ analysis
316#[derive(Debug, Clone)]
317pub struct FlowPattern {
318    /// Type of flow pattern
319    pub pattern_type: String,
320    /// Frequency of the pattern
321    pub frequency: f32,
322    /// Amplitude of the pattern
323    pub amplitude: f32,
324    /// Phase offset of the pattern
325    pub phase: f32,
326}
327
328#[derive(Debug, Clone)]
329pub struct SequencePattern {
330    pub pattern_name: String,
331    pub activity_sequence: Vec<String>,
332    pub temporal_constraints: Vec<TemporalConstraint>,
333    pub occurrence_probability: f32,
334}
335
336#[derive(Debug, Clone)]
337pub struct TemporalConstraint {
338    pub constraint_type: String,
339    pub min_duration: f32,
340    pub max_duration: f32,
341    pub typical_duration: f32,
342}
343
344#[derive(Debug, Clone)]
345pub struct TransitionModel {
346    pub source_activity: String,
347    pub transition_probabilities: HashMap<String, f32>,
348    pub typical_durations: HashMap<String, f32>,
349}
350
351#[derive(Debug, Clone)]
352pub struct AnomalyDetectionParams {
353    pub detection_threshold: f32,
354    pub temporal_window: usize,
355    pub feature_importance: Array1<f32>,
356    pub novelty_detection: bool,
357}
358
359#[derive(Debug, Clone)]
360pub enum InteractionType {
361    Conversation,
362    Collaboration,
363    Competition,
364    Following,
365    Avoiding,
366    Playing,
367    Fighting,
368    Helping,
369    Teaching,
370    Custom(String),
371}
372
373#[derive(Debug, Clone)]
374pub struct PersonTrackingParams {
375    pub max_tracking_distance: f32,
376    pub identity_confidence_threshold: f32,
377    pub re_identification_enabled: bool,
378    pub track_merge_threshold: f32,
379}
380
381#[derive(Debug, Clone)]
382pub struct SocialDistanceModel {
383    pub personal_space_radius: f32,
384    pub social_space_radius: f32,
385    pub public_space_radius: f32,
386    pub cultural_factors: HashMap<String, f32>,
387}
388
389#[derive(Debug, Clone)]
390pub struct GroupActivityRecognition {
391    pub min_group_size: usize,
392    pub max_group_size: usize,
393    pub cohesion_threshold: f32,
394    pub activity_synchronization: bool,
395}
396
397#[derive(Debug, Clone)]
398pub enum ContextFeature {
399    SceneType,
400    TimeOfDay,
401    Weather,
402    CrowdDensity,
403    NoiseLevel,
404    LightingConditions,
405    ObjectPresence(String),
406}
407
408#[derive(Debug, Clone)]
409pub struct EnvironmentClassifier {
410    pub environment_type: String,
411    pub typical_activities: Vec<String>,
412    pub activity_probabilities: HashMap<String, f32>,
413    pub contextual_cues: Vec<String>,
414}
415
416#[derive(Debug, Clone)]
417pub struct ActivityDistribution {
418    pub activities: HashMap<String, f32>,
419    pub temporal_patterns: HashMap<String, TemporalPattern>,
420    pub confidence: f32,
421}
422
423#[derive(Debug, Clone)]
424pub struct TemporalPattern {
425    pub pattern_type: String,
426    pub peak_times: Vec<f32>,
427    pub duration_distribution: Array1<f32>,
428    pub seasonality: Option<SeasonalityInfo>,
429}
430
431#[derive(Debug, Clone)]
432pub struct SeasonalityInfo {
433    pub period: f32,
434    pub amplitude: f32,
435    pub phase_shift: f32,
436}
437
438#[derive(Debug, Clone)]
439pub struct RNNParameters {
440    pub hidden_size: usize,
441    pub num_layers: usize,
442    pub dropout_rate: f32,
443    pub bidirectional: bool,
444}
445
446#[derive(Debug, Clone)]
447pub struct TemporalAttention {
448    pub attention_type: String,
449    pub window_size: usize,
450    pub attention_weights: Array2<f32>,
451    pub learnable: bool,
452}
453
454#[derive(Debug, Clone)]
455pub struct ActivityLevel {
456    pub level_name: String,
457    pub granularity: f32,
458    pub typical_duration: f32,
459    pub complexity: f32,
460}
461
462#[derive(Debug, Clone)]
463pub struct DecompositionRule {
464    pub rule_name: String,
465    pub parent_activity: String,
466    pub child_activities: Vec<String>,
467    pub decomposition_conditions: Vec<String>,
468}
469
470#[derive(Debug, Clone)]
471pub struct CompositionRule {
472    pub rule_name: String,
473    pub component_activities: Vec<String>,
474    pub composite_activity: String,
475    pub composition_conditions: Vec<String>,
476}
477
478#[derive(Debug, Clone)]
479pub struct ActivityDefinition {
480    pub activity_name: String,
481    pub description: String,
482    pub typical_duration: f32,
483    pub required_objects: Vec<String>,
484    pub typical_poses: Vec<String>,
485    pub motion_patterns: Vec<String>,
486    pub contextual_requirements: Vec<String>,
487}
488
489#[derive(Debug, Clone)]
490pub struct ActivityOntology {
491    pub activity_hierarchy: HashMap<String, Vec<String>>,
492    pub activity_relationships: Vec<ActivityRelationship>,
493    pub semantic_similarity: Array2<f32>,
494}
495
496#[derive(Debug, Clone)]
497pub struct ActivityRelationship {
498    pub source_activity: String,
499    pub target_activity: String,
500    pub relationship_type: String,
501    pub strength: f32,
502}
503
504#[derive(Debug, Clone)]
505pub struct ActivityPattern {
506    pub pattern_name: String,
507    pub activity_sequence: Vec<String>,
508    pub temporal_structure: TemporalStructure,
509    pub context_requirements: Vec<String>,
510    pub occurrence_frequency: f32,
511}
512
513#[derive(Debug, Clone)]
514pub struct TemporalStructure {
515    pub sequence_type: String,
516    pub timing_constraints: Vec<TimingConstraint>,
517    pub overlap_patterns: Vec<OverlapPattern>,
518}
519
520#[derive(Debug, Clone)]
521pub struct TimingConstraint {
522    pub constraint_type: String,
523    pub activity_pair: (String, String),
524    pub min_delay: f32,
525    pub max_delay: f32,
526}
527
528#[derive(Debug, Clone)]
529pub struct OverlapPattern {
530    pub activity_pair: (String, String),
531    pub overlap_type: String,
532    pub typical_overlap: f32,
533}
534
535#[derive(Debug, Clone)]
536pub struct ActivityVariation {
537    pub variation_name: String,
538    pub base_activity: String,
539    pub cultural_context: String,
540    pub modifications: HashMap<String, String>,
541    pub prevalence: f32,
542}
543
544// Placeholder/support structures used by the engine's helper methods.
545// Placeholder structures for compilation
546#[derive(Debug, Clone)]
547pub struct ContextClassification {
548    pub scene_type: String,
549    pub environment_factors: HashMap<String, f32>,
550    pub temporal_context: HashMap<String, f32>,
551}
552
553#[derive(Debug, Clone)]
554pub struct HierarchicalActivityStructure {
555    pub levels: Vec<ActivityLevel>,
556    pub activity_tree: ActivityTree,
557    pub decomposition_confidence: f32,
558}
559
560#[derive(Debug, Clone)]
561pub struct ActivityTree {
562    pub root: ActivityNode,
563    pub nodes: Vec<ActivityNode>,
564    pub edges: Vec<ActivityEdge>,
565}
566
567#[derive(Debug, Clone)]
568pub struct ActivityNode {
569    pub node_id: String,
570    pub activity_type: String,
571    pub level: usize,
572    pub children: Vec<String>,
573}
574
575#[derive(Debug, Clone)]
576pub struct ActivityEdge {
577    pub parent: String,
578    pub child: String,
579    pub relationship_type: String,
580}
581
582#[derive(Debug, Clone)]
583pub struct ActivityPrediction {
584    pub predicted_activity: String,
585    pub probability: f32,
586    pub expected_start_time: f32,
587    pub expected_duration: f32,
588    pub confidence_interval: (f32, f32),
589}