mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 06:46:30 +00:00
fix saving scale for datasetexplorer and annotation
This commit is contained in:
@@ -313,11 +313,13 @@ public class AnnotatorEventHandler(
|
|||||||
private async Task<List<Annotation>> SaveAnnotationInner(string imgPath, CancellationToken cancellationToken = default)
|
private async Task<List<Annotation>> SaveAnnotationInner(string imgPath, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var canvasDetections = mainWindow.Editor.CurrentDetections.Select(x => x.ToCanvasLabel()).ToList();
|
var canvasDetections = mainWindow.Editor.CurrentDetections.Select(x => x.ToCanvasLabel()).ToList();
|
||||||
|
|
||||||
|
var source = (mainWindow.Editor.BackgroundImage.Source as BitmapSource)!;
|
||||||
|
var mediaSize = new Size(source.PixelWidth, source.PixelHeight);
|
||||||
var annotationsResult = new List<Annotation>();
|
var annotationsResult = new List<Annotation>();
|
||||||
if (!File.Exists(imgPath))
|
if (!File.Exists(imgPath))
|
||||||
{
|
{
|
||||||
var source = (mainWindow.Editor.BackgroundImage.Source as BitmapSource)!;
|
if (mediaSize.FitSizeForAI())
|
||||||
if (new Size(source.PixelWidth, source.PixelHeight).FitSizeForAI())
|
|
||||||
await source.SaveImage(imgPath, cancellationToken);
|
await source.SaveImage(imgPath, cancellationToken);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -356,7 +358,7 @@ public class AnnotatorEventHandler(
|
|||||||
var timeImg = formState.BackgroundTime ?? TimeSpan.FromMilliseconds(mediaPlayer.Time);
|
var timeImg = formState.BackgroundTime ?? TimeSpan.FromMilliseconds(mediaPlayer.Time);
|
||||||
var annName = formState.MediaName.ToTimeName(timeImg);
|
var annName = formState.MediaName.ToTimeName(timeImg);
|
||||||
var currentDetections = canvasDetections.Select(x =>
|
var currentDetections = canvasDetections.Select(x =>
|
||||||
new Detection(annName, new YoloLabel(x, mainWindow.Editor.RenderSize)))
|
new Detection(annName, new YoloLabel(x, mainWindow.Editor.RenderSize, mediaSize)))
|
||||||
.ToList();
|
.ToList();
|
||||||
var annotation = await annotationService.SaveAnnotation(formState.MediaName, annName, timeImg, currentDetections, token: cancellationToken);
|
var annotation = await annotationService.SaveAnnotation(formState.MediaName, annName, timeImg, currentDetections, token: cancellationToken);
|
||||||
return [annotation];
|
return [annotation];
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace Azaion.Dataset;
|
namespace Azaion.Dataset;
|
||||||
@@ -16,4 +17,8 @@ public static class BitmapExtensions
|
|||||||
image.Freeze();
|
image.Freeze();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Size Size(this BitmapImage image) =>
|
||||||
|
new(image.PixelWidth, image.PixelHeight);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ public partial class DatasetExplorer
|
|||||||
private readonly IConfigUpdater _configUpdater;
|
private readonly IConfigUpdater _configUpdater;
|
||||||
|
|
||||||
public bool ThumbnailLoading { get; set; }
|
public bool ThumbnailLoading { get; set; }
|
||||||
|
public string CurrentFilter { get; set; } = "";
|
||||||
|
|
||||||
public AnnotationThumbnail? CurrentAnnotation { get; set; }
|
public AnnotationThumbnail? CurrentAnnotation { get; set; }
|
||||||
|
|
||||||
@@ -201,7 +202,7 @@ public partial class DatasetExplorer
|
|||||||
SwitchTab(toEditor: true);
|
SwitchTab(toEditor: true);
|
||||||
|
|
||||||
ExplorerEditor.RemoveAllAnns();
|
ExplorerEditor.RemoveAllAnns();
|
||||||
ExplorerEditor.CreateDetections(ann, _appConfig.AnnotationConfig.DetectionClasses, new Size(image.PixelWidth, image.PixelHeight));
|
ExplorerEditor.CreateDetections(ann, _appConfig.AnnotationConfig.DetectionClasses, image.Size());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -261,7 +262,7 @@ public partial class DatasetExplorer
|
|||||||
SelectedAnnotationDict.Clear();
|
SelectedAnnotationDict.Clear();
|
||||||
var annThumbnails = _annotationsDict[ExplorerEditor.CurrentAnnClass.YoloId]
|
var annThumbnails = _annotationsDict[ExplorerEditor.CurrentAnnClass.YoloId]
|
||||||
.WhereIf(withDetectionsOnly, x => x.Value.Detections.Any())
|
.WhereIf(withDetectionsOnly, x => x.Value.Detections.Any())
|
||||||
.WhereIf(TbSearch.Text.Length > 2, x => x.Key.ToLower().Contains(TbSearch.Text))
|
.WhereIf(!string.IsNullOrEmpty(CurrentFilter), x => x.Key.Contains(CurrentFilter, StringComparison.CurrentCultureIgnoreCase))
|
||||||
.Select(x => new AnnotationThumbnail(x.Value, _azaionApi.CurrentUser.Role.IsValidator()))
|
.Select(x => new AnnotationThumbnail(x.Value, _azaionApi.CurrentUser.Role.IsValidator()))
|
||||||
.OrderBy(x => !x.IsSeed)
|
.OrderBy(x => !x.IsSeed)
|
||||||
.ThenByDescending(x =>x.Annotation.CreatedDate);
|
.ThenByDescending(x =>x.Annotation.CreatedDate);
|
||||||
@@ -300,6 +301,11 @@ public partial class DatasetExplorer
|
|||||||
private void TbSearch_OnTextChanged(object sender, TextChangedEventArgs e)
|
private void TbSearch_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
TbSearch.Foreground = TbSearch.Text.Length > 2 ? Brushes.Black : Brushes.Gray;
|
TbSearch.Foreground = TbSearch.Text.Length > 2 ? Brushes.Black : Brushes.Gray;
|
||||||
ThrottleExt.Throttle(ReloadThumbnails, SearchActionId, TimeSpan.FromMilliseconds(400));;
|
if (TbSearch.Text.Length > 2 || string.IsNullOrEmpty(TbSearch.Text))
|
||||||
|
{
|
||||||
|
CurrentFilter = TbSearch.Text;
|
||||||
|
ThrottleExt.Throttle(ReloadThumbnails, SearchActionId, TimeSpan.FromMilliseconds(400));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
using Azaion.Common.Database;
|
using Azaion.Common.Database;
|
||||||
using Azaion.Common.DTO;
|
using Azaion.Common.DTO;
|
||||||
using Azaion.Common.Events;
|
using Azaion.Common.Events;
|
||||||
@@ -66,8 +67,9 @@ public class DatasetExplorerEventHandler(
|
|||||||
|
|
||||||
var a = datasetExplorer.CurrentAnnotation!.Annotation;
|
var a = datasetExplorer.CurrentAnnotation!.Annotation;
|
||||||
|
|
||||||
|
var mediaSize = ((BitmapImage)datasetExplorer.ExplorerEditor.BackgroundImage.Source).Size();
|
||||||
var detections = datasetExplorer.ExplorerEditor.CurrentDetections
|
var detections = datasetExplorer.ExplorerEditor.CurrentDetections
|
||||||
.Select(x => new Detection(a.Name, x.ToYoloLabel(datasetExplorer.ExplorerEditor.RenderSize)))
|
.Select(x => new Detection(a.Name, x.ToYoloLabel(datasetExplorer.ExplorerEditor.RenderSize, mediaSize)))
|
||||||
.ToList();
|
.ToList();
|
||||||
var index = datasetExplorer.ThumbnailsView.SelectedIndex;
|
var index = datasetExplorer.ThumbnailsView.SelectedIndex;
|
||||||
var annotation = await annotationService.SaveAnnotation(a.OriginalMediaName, a.Name, a.Time, detections, token: token);
|
var annotation = await annotationService.SaveAnnotation(a.OriginalMediaName, a.Name, a.Time, detections, token: token);
|
||||||
@@ -125,24 +127,24 @@ public class DatasetExplorerEventHandler(
|
|||||||
var selectedClass = datasetExplorer.LvClasses.CurrentClassNumber;
|
var selectedClass = datasetExplorer.LvClasses.CurrentClassNumber;
|
||||||
|
|
||||||
datasetExplorer.AddAnnotationToDict(annotation);
|
datasetExplorer.AddAnnotationToDict(annotation);
|
||||||
if (annotation.Classes.Contains(selectedClass) || selectedClass == -1)
|
if (!annotation.Classes.Contains(selectedClass) && selectedClass != -1)
|
||||||
{
|
return;
|
||||||
var index = 0;
|
|
||||||
var annThumb = new AnnotationThumbnail(annotation, azaionApi.CurrentUser.Role.IsValidator());
|
|
||||||
if (datasetExplorer.SelectedAnnotationDict.ContainsKey(annThumb.Annotation.Name))
|
|
||||||
{
|
|
||||||
datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name);
|
|
||||||
var ann = datasetExplorer.SelectedAnnotations.FirstOrDefault(x => x.Annotation.Name == annThumb.Annotation.Name);
|
|
||||||
if (ann != null)
|
|
||||||
{
|
|
||||||
index = datasetExplorer.SelectedAnnotations.IndexOf(ann);
|
|
||||||
datasetExplorer.SelectedAnnotations.Remove(ann);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
datasetExplorer.SelectedAnnotations.Insert(index, annThumb);
|
var index = 0;
|
||||||
datasetExplorer.SelectedAnnotationDict.Add(annThumb.Annotation.Name, annThumb);
|
var annThumb = new AnnotationThumbnail(annotation, azaionApi.CurrentUser.Role.IsValidator());
|
||||||
|
if (datasetExplorer.SelectedAnnotationDict.ContainsKey(annThumb.Annotation.Name))
|
||||||
|
{
|
||||||
|
datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name);
|
||||||
|
var ann = datasetExplorer.SelectedAnnotations.FirstOrDefault(x => x.Annotation.Name == annThumb.Annotation.Name);
|
||||||
|
if (ann != null)
|
||||||
|
{
|
||||||
|
index = datasetExplorer.SelectedAnnotations.IndexOf(ann);
|
||||||
|
datasetExplorer.SelectedAnnotations.Remove(ann);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datasetExplorer.SelectedAnnotations.Insert(index, annThumb);
|
||||||
|
datasetExplorer.SelectedAnnotationDict.Add(annThumb.Annotation.Name, annThumb);
|
||||||
});
|
});
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user