From ea7c4874934a5c769ae9d755d4d1cf433090d2f1 Mon Sep 17 00:00:00 2001 From: Alex Bezdieniezhnykh Date: Thu, 3 Jul 2025 12:53:43 +0300 Subject: [PATCH] fix show image, fix zoom --- Azaion.Annotator/Annotator.xaml.cs | 32 +++++++++++----------- Azaion.Annotator/AnnotatorEventHandler.cs | 6 ++-- Azaion.Common/Controls/CanvasEditor.cs | 3 ++ Azaion.Common/Controls/DetectionControl.cs | 21 ++++++++++++-- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/Azaion.Annotator/Annotator.xaml.cs b/Azaion.Annotator/Annotator.xaml.cs index f150808..958cce2 100644 --- a/Azaion.Annotator/Annotator.xaml.cs +++ b/Azaion.Annotator/Annotator.xaml.cs @@ -40,8 +40,7 @@ public partial class Annotator private readonly IDbFactory _dbFactory; private readonly IInferenceService _inferenceService; private readonly IInferenceClient _inferenceClient; - - private ObservableCollection AnnotationClasses { get; set; } = new(); + private bool _suspendLayout; private bool _gpsPanelVisible = false; @@ -181,21 +180,22 @@ public partial class Annotator { if (_formState.CurrentMrl == _mediaPlayer.Media?.Mrl) return; //already loaded all the info - + + await Dispatcher.Invoke(async () => await ReloadAnnotations()); + + //show image + if (_formState.CurrentMedia?.MediaType == MediaTypes.Image) + { + await Task.Delay(100); //wait to load the frame and set on pause + ShowTimeAnnotations(TimeSpan.FromMilliseconds(_mediaPlayer.Time), showImage: true); + return; + } + _formState.CurrentMrl = _mediaPlayer.Media?.Mrl ?? ""; uint vw = 0, vh = 0; _mediaPlayer.Size(0, ref vw, ref vh); _formState.CurrentVideoSize = new Size(vw, vh); _formState.CurrentVideoLength = TimeSpan.FromMilliseconds(_mediaPlayer.Length); - - await Dispatcher.Invoke(async () => await ReloadAnnotations()); - - if (_formState.CurrentMedia?.MediaType == MediaTypes.Image) - { - await Task.Delay(100); //wait to load the frame and set on pause - ShowTimeAnnotations(TimeSpan.FromMilliseconds(_mediaPlayer.Time)); - _mediaPlayer.SetPause(true); - } }; LvFiles.MouseDoubleClick += async (_, _) => @@ -268,7 +268,7 @@ public partial class Annotator Editor.ClearExpiredAnnotations(res.Annotation.Time); }); - ShowAnnotations(res.Annotation, showImage: true); + ShowAnnotation(res.Annotation, showImage: true); } private void SaveUserSettings() { @@ -281,7 +281,7 @@ public partial class Annotator _configUpdater.Save(_appConfig); } - private void ShowTimeAnnotations(TimeSpan time) + private void ShowTimeAnnotations(TimeSpan time, bool showImage = false) { Dispatcher.Invoke(() => { @@ -290,10 +290,10 @@ public partial class Annotator Editor.ClearExpiredAnnotations(time); }); - ShowAnnotations(TimedAnnotations.Query(time).FirstOrDefault()); + ShowAnnotation(TimedAnnotations.Query(time).FirstOrDefault(), showImage); } - private void ShowAnnotations(Annotation? annotation, bool showImage = false) + private void ShowAnnotation(Annotation? annotation, bool showImage = false) { if (annotation == null) return; diff --git a/Azaion.Annotator/AnnotatorEventHandler.cs b/Azaion.Annotator/AnnotatorEventHandler.cs index 3b244d4..37d1aba 100644 --- a/Azaion.Annotator/AnnotatorEventHandler.cs +++ b/Azaion.Annotator/AnnotatorEventHandler.cs @@ -229,13 +229,13 @@ public class AnnotatorEventHandler( mainWindow.Editor.ResetBackground(); formState.CurrentMedia = mediaInfo; + mainWindow.Title = $"Azaion Annotator - {mediaInfo.Name}"; + + //need to wait a bit for correct VLC playback event handling await Task.Delay(100, ct); mediaPlayer.Stop(); - mainWindow.Title = $"Azaion Annotator - {mediaInfo.Name}"; mediaPlayer.Play(new Media(libVLC, mediaInfo.Path)); - if (formState.CurrentMedia.MediaType == MediaTypes.Image) - mediaPlayer.SetPause(true); } //SAVE: MANUAL diff --git a/Azaion.Common/Controls/CanvasEditor.cs b/Azaion.Common/Controls/CanvasEditor.cs index 5760db1..3d93002 100644 --- a/Azaion.Common/Controls/CanvasEditor.cs +++ b/Azaion.Common/Controls/CanvasEditor.cs @@ -149,6 +149,9 @@ public class CanvasEditor : Canvas _matrixTransform.Matrix = matrix; _isZoomedIn = true; } + + foreach (var detection in CurrentDetections) + detection.UpdateAdornerScale(scale: _matrixTransform.Matrix.M11); } private void Init(object sender, RoutedEventArgs e) diff --git a/Azaion.Common/Controls/DetectionControl.cs b/Azaion.Common/Controls/DetectionControl.cs index ed69144..4c6bfe8 100644 --- a/Azaion.Common/Controls/DetectionControl.cs +++ b/Azaion.Common/Controls/DetectionControl.cs @@ -43,6 +43,7 @@ public class DetectionControl : Border private readonly Rectangle _selectionFrame; private bool _isSelected; + public bool IsSelected { get => _isSelected; @@ -53,6 +54,21 @@ public class DetectionControl : Border } } + public void UpdateAdornerScale(double scale) + { + if (Math.Abs(scale) < 0.0001) + return; + + var inverseScale = 1.0 / scale; + BorderThickness = new Thickness(4 * inverseScale); + foreach (var rect in _resizedRectangles) + { + rect.Width = 2 * RESIZE_RECT_SIZE * inverseScale; + rect.Height = 2 * RESIZE_RECT_SIZE * inverseScale;; + rect.Margin = new Thickness(-RESIZE_RECT_SIZE * 0.7); + } + } + public (HorizontalAlignment Horizontal, VerticalAlignment Vertical) DetectionLabelPosition { get => (DetectionLabelContainer.HorizontalAlignment, DetectionLabelContainer.VerticalAlignment); @@ -66,14 +82,15 @@ public class DetectionControl : Border private string _detectionLabelText(string detectionClassName) => _confidence >= 0.995 ? detectionClassName : $"{detectionClassName}: {_confidence * 100:F0}%"; //double - public DetectionControl(DetectionClass detectionClass, TimeSpan time, Action resizeStart, CanvasLabel canvasLabel) + public DetectionControl(DetectionClass detectionClass, TimeSpan time, Action resizeStart, CanvasLabel canvasLabel) { Width = canvasLabel.Width; Height = canvasLabel.Height; Time = time; _resizeStart = resizeStart; _confidence = canvasLabel.Confidence; - + DetectionLabelContainer = new Canvas { HorizontalAlignment = HorizontalAlignment.Right,