diff --git a/Azaion.Annotator/Annotator.xaml b/Azaion.Annotator/Annotator.xaml index 3df8359..53bd029 100644 --- a/Azaion.Annotator/Annotator.xaml +++ b/Azaion.Annotator/Annotator.xaml @@ -8,6 +8,7 @@ xmlns:controls1="clr-namespace:Azaion.Common.Controls;assembly=Azaion.Common" xmlns:controls2="clr-namespace:Azaion.Annotator.Controls;assembly=Azaion.Common" mc:Ignorable="d" + xmlns:local="clr-namespace:Azaion.Annotator" Title="Azaion Annotator" Height="800" Width="1100" WindowState="Maximized" > @@ -49,6 +50,8 @@ + + + CanUserResizeColumns="False" + RowStyleSelector="{StaticResource GradientStyleSelector}"> - - - diff --git a/Azaion.Annotator/Annotator.xaml.cs b/Azaion.Annotator/Annotator.xaml.cs index 2b2253b..80a1cd0 100644 --- a/Azaion.Annotator/Annotator.xaml.cs +++ b/Azaion.Annotator/Annotator.xaml.cs @@ -328,7 +328,11 @@ public partial class Annotator var existingResult = _formState.AnnotationResults.FirstOrDefault(x => x.Annotation.Time == time); if (existingResult != null) + { + _logger.LogInformation($"remove annotation {existingResult.TimeStr} {existingResult.ClassName}!"); _formState.AnnotationResults.Remove(existingResult); + } + var dict = _formState.AnnotationResults .Select((x, i) => new { x.Annotation.Time, Index = i }) @@ -339,7 +343,8 @@ public partial class Annotator .Select(x => x.Value + 1) .FirstOrDefault(); - _formState.AnnotationResults.Insert(index, new AnnotationResult(_appConfig.AnnotationConfig.DetectionClassesDict, annotation)); + var annRes = new AnnotationResult(_appConfig.AnnotationConfig.DetectionClassesDict, annotation); + _formState.AnnotationResults.Insert(index, annRes); } private async Task ReloadFiles() @@ -565,6 +570,7 @@ public partial class Annotator await _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Play), ct); } } + AddAnnotation(annotation); if (FollowAI) @@ -574,7 +580,7 @@ public partial class Annotator $"{_appConfig.AnnotationConfig.DetectionClassesDict[det.ClassNumber].Name}: " + $"xy=({det.CenterX:F2},{det.CenterY:F2}), " + $"size=({det.Width:F2}, {det.Height:F2}), " + - $"prob: {det.Probability*100:F0}%")); + $"conf: {det.Confidence*100:F0}%")); Dispatcher.Invoke(() => { @@ -618,3 +624,42 @@ public partial class Annotator throw new NotImplementedException(); } } + +public class GradientStyleSelector : StyleSelector +{ + public override Style? SelectStyle(object item, DependencyObject container) + { + if (container is not DataGridRow row || row.DataContext is not AnnotationResult result) + return null; + + var style = new Style(typeof(DataGridRow)); + var brush = new LinearGradientBrush + { + StartPoint = new Point(0, 0), + EndPoint = new Point(1, 0) + }; + + var gradients = new List(); + if (result.Colors.Count != 0) + { + var color = (Color)ColorConverter.ConvertFromString("#40DDDDDD"); + gradients = [new GradientStop(color, 0.99)]; + } + else + { + var increment = 1.0 / result.Colors.Count; + var currentStop = increment; + foreach (var c in result.Colors) + { + var resultColor = c.Color.ToConfidenceColor(c.Confidence); + brush.GradientStops.Add(new GradientStop(resultColor, currentStop)); + currentStop += increment; + } + } + foreach (var gradientStop in gradients) + brush.GradientStops.Add(gradientStop); + + style.Setters.Add(new Setter(DataGridRow.BackgroundProperty, brush)); + return style; + } +} diff --git a/Azaion.Annotator/Controls/MapMatcher.xaml.cs b/Azaion.Annotator/Controls/MapMatcher.xaml.cs index 99d163a..fcece7b 100644 --- a/Azaion.Annotator/Controls/MapMatcher.xaml.cs +++ b/Azaion.Annotator/Controls/MapMatcher.xaml.cs @@ -38,16 +38,19 @@ public partial class MapMatcher : UserControl SatelliteMap.Position = new PointLatLng(48.295985271707664, 37.14477539062501); SatelliteMap.MultiTouchEnabled = true; - GpsFiles.MouseDoubleClick += async (sender, args) => + GpsFiles.MouseDoubleClick += async (sender, args) => { await OpenGpsLocation(GpsFiles.SelectedIndex); }; + } + + private async Task OpenGpsLocation(int gpsFilesIndex) + { + var media = GpsFiles.Items[gpsFilesIndex] as MediaFileInfo; + var ann = _annotations.GetValueOrDefault(Path.GetFileNameWithoutExtension(media.Name)); + GpsImageEditor.Background = new ImageBrush { - var media = (GpsFiles.SelectedItem as MediaFileInfo)!; - var ann = _annotations.GetValueOrDefault(Path.GetFileNameWithoutExtension(media.Name)); - GpsImageEditor.Background = new ImageBrush - { - ImageSource = await Path.Combine(_currentDir, ann.Name).OpenImage() - }; - SatelliteMap.Position = new PointLatLng(ann.Lat, ann.Lon); + ImageSource = await Path.Combine(_currentDir, ann.Name).OpenImage() }; + if (ann.Lat != 0 && ann.Lon != 0) + SatelliteMap.Position = new PointLatLng(ann.Lat, ann.Lon); } private void GpsFilesContextOpening(object sender, ContextMenuEventArgs e) @@ -104,8 +107,11 @@ public partial class MapMatcher : UserControl _allMediaFiles = mediaFiles; GpsFiles.ItemsSource = new ObservableCollection(_allMediaFiles); var annotations = SetFromCsv(mediaFiles); + Cursor = Cursors.Wait; await Task.Delay(TimeSpan.FromSeconds(10)); SetMarkers(annotations); + Cursor = Cursors.Arrow; + await OpenGpsLocation(0); } private Dictionary SetFromCsv(List mediaFiles) @@ -117,7 +123,9 @@ public partial class MapMatcher : UserControl }).ToDictionary(x => Path.GetFileNameWithoutExtension(x.OriginalMediaName)); var csvResults = GpsCsvResult.ReadFromCsv(Constants.CSV_PATH); - var csvDict = csvResults.ToDictionary(x => x.Image); + var csvDict = csvResults + .Where(x => x.MatchType == "stitched") + .ToDictionary(x => x.Image); foreach (var ann in _annotations) { var csvRes = csvDict.GetValueOrDefault(ann.Key); @@ -137,7 +145,7 @@ public partial class MapMatcher : UserControl var firstAnnotation = annotations.FirstOrDefault(); SatelliteMap.Position = new PointLatLng(firstAnnotation.Value.Lat, firstAnnotation.Value.Lon); - foreach (var ann in annotations) + foreach (var ann in annotations.Where(x => x.Value.Lat != 0 && x.Value.Lon != 0)) { var marker = new GMapMarker(new PointLatLng(ann.Value.Lat, ann.Value.Lon)); var circle = new CircleVisual(marker, System.Windows.Media.Brushes.Blue) @@ -147,6 +155,6 @@ public partial class MapMatcher : UserControl marker.Shape = circle; SatelliteMap.Markers.Add(marker); } - + SatelliteMap.ZoomAndCenterMarkers(null); } } \ No newline at end of file diff --git a/Azaion.Common/Constants.cs b/Azaion.Common/Constants.cs index e665813..4aef98b 100644 --- a/Azaion.Common/Constants.cs +++ b/Azaion.Common/Constants.cs @@ -90,5 +90,5 @@ public class Constants #endregion - public const string CSV_PATH = "D:\\matches.csv"; + public const string CSV_PATH = "matches.csv"; } \ No newline at end of file diff --git a/Azaion.Common/Controls/CanvasEditor.cs b/Azaion.Common/Controls/CanvasEditor.cs index 2d7104f..3056b8f 100644 --- a/Azaion.Common/Controls/CanvasEditor.cs +++ b/Azaion.Common/Controls/CanvasEditor.cs @@ -54,7 +54,7 @@ public class CanvasEditor : Canvas _verticalLine.Fill = value.ColorBrush; _horizontalLine.Stroke = value.ColorBrush; _horizontalLine.Fill = value.ColorBrush; - _classNameHint.Text = value.Name; + _classNameHint.Text = value.ShortName; _newAnnotationRect.Stroke = value.ColorBrush; _newAnnotationRect.Fill = value.ColorBrush; @@ -84,7 +84,7 @@ public class CanvasEditor : Canvas }; _classNameHint = new TextBlock { - Text = CurrentAnnClass?.Name ?? "asd", + Text = CurrentAnnClass?.ShortName ?? "", Foreground = new SolidColorBrush(Colors.Black), Cursor = Cursors.Arrow, FontSize = 16, @@ -313,14 +313,14 @@ public class CanvasEditor : Canvas foreach (var detection in detections) { var annClass = DetectionClass.FromYoloId(detection.ClassNumber, detectionClasses); - var canvasLabel = new CanvasLabel(detection, RenderSize, videoSize, detection.Probability); + var canvasLabel = new CanvasLabel(detection, RenderSize, videoSize, detection.Confidence); CreateDetectionControl(annClass, time, canvasLabel); } } private void CreateDetectionControl(DetectionClass annClass, TimeSpan time, CanvasLabel canvasLabel) { - var detectionControl = new DetectionControl(annClass, time, AnnotationResizeStart, canvasLabel.Probability) + var detectionControl = new DetectionControl(annClass, time, AnnotationResizeStart, canvasLabel.Confidence) { Width = canvasLabel.Width, Height = canvasLabel.Height diff --git a/Azaion.Common/Controls/DetectionClasses.xaml b/Azaion.Common/Controls/DetectionClasses.xaml index eb0d847..47951a8 100644 --- a/Azaion.Common/Controls/DetectionClasses.xaml +++ b/Azaion.Common/Controls/DetectionClasses.xaml @@ -68,7 +68,7 @@ - +