mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:56:30 +00:00
fix editing non-timed annotations
This commit is contained in:
@@ -24,19 +24,18 @@ public class FormState
|
||||
public TimeSpan? GetTime(string name)
|
||||
{
|
||||
var timeStr = name.Split("_").LastOrDefault();
|
||||
if (string.IsNullOrEmpty(timeStr))
|
||||
if (string.IsNullOrEmpty(timeStr) || timeStr.Length < 7)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
//For some reason, TimeSpan.ParseExact doesn't work on every platform.
|
||||
return new TimeSpan(
|
||||
days: 0,
|
||||
hours: int.Parse(timeStr[0..1]),
|
||||
minutes: int.Parse(timeStr[1..3]),
|
||||
seconds: int.Parse(timeStr[3..5]),
|
||||
milliseconds: int.Parse(timeStr[5..6]) * 100);
|
||||
}
|
||||
catch (Exception e) { return null; }
|
||||
|
||||
//For some reason, TimeSpan.ParseExact doesn't work on every platform.
|
||||
if (!int.TryParse(timeStr[0..1], out var hours))
|
||||
return null;
|
||||
if (!int.TryParse(timeStr[1..3], out var minutes))
|
||||
return null;
|
||||
if (!int.TryParse(timeStr[3..5], out var seconds))
|
||||
return null;
|
||||
if (!int.TryParse(timeStr[5..6], out var milliseconds))
|
||||
return null;
|
||||
return new TimeSpan(0, hours, minutes, seconds, milliseconds * 100);
|
||||
}
|
||||
}
|
||||
@@ -135,31 +135,24 @@ public class YoloLabel : Label
|
||||
|
||||
var strings = s.Replace(',', '.').Split(' ');
|
||||
if (strings.Length != 5)
|
||||
return null;
|
||||
throw new Exception("Wrong labels format!");
|
||||
|
||||
try
|
||||
var res = new YoloLabel
|
||||
{
|
||||
var res = new YoloLabel
|
||||
{
|
||||
ClassNumber = int.Parse(strings[0], CultureInfo.InvariantCulture),
|
||||
CenterX = double.Parse(strings[1], CultureInfo.InvariantCulture),
|
||||
CenterY = double.Parse(strings[2], CultureInfo.InvariantCulture),
|
||||
Width = double.Parse(strings[3], CultureInfo.InvariantCulture),
|
||||
Height = double.Parse(strings[4], CultureInfo.InvariantCulture)
|
||||
};
|
||||
return res;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ClassNumber = int.Parse(strings[0], CultureInfo.InvariantCulture),
|
||||
CenterX = double.Parse(strings[1], CultureInfo.InvariantCulture),
|
||||
CenterY = double.Parse(strings[2], CultureInfo.InvariantCulture),
|
||||
Width = double.Parse(strings[3], CultureInfo.InvariantCulture),
|
||||
Height = double.Parse(strings[4], CultureInfo.InvariantCulture)
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<List<YoloLabel>> ReadFromFile(string filename)
|
||||
{
|
||||
var str = await File.ReadAllTextAsync(filename);
|
||||
|
||||
return str.Split(Environment.NewLine)
|
||||
return str.Split('\n')
|
||||
.Select(Parse)
|
||||
.Where(ann => ann != null)
|
||||
.ToList()!;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Azaion.Annotator.Extensions;
|
||||
@@ -26,6 +27,7 @@ public class ThumbnailDto : INotifyPropertyChanged
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public string ImageName => Path.GetFileName(ImagePath);
|
||||
|
||||
public void UpdateImage() => _image = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user