mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 09:36:30 +00:00
fix bugs
This commit is contained in:
@@ -69,8 +69,10 @@ public class DatasetExplorerEventHandler(DatasetExplorer datasetExplorer, IGalle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(ImageCreatedEvent notification, CancellationToken cancellationToken)
|
public async Task Handle(ImageCreatedEvent imageCreatedEvent, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var (thumbnailDto, detections) = await galleryManager.CreateThumbnail(imageCreatedEvent.ImagePath, cancellationToken);
|
||||||
|
if (thumbnailDto != null && detections != null)
|
||||||
|
datasetExplorer.AddThumbnail(thumbnailDto, detections);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class GalleryManager(
|
|||||||
private readonly AnnotationConfig _annotationConfig = annotationConfig.Value;
|
private readonly AnnotationConfig _annotationConfig = annotationConfig.Value;
|
||||||
|
|
||||||
private readonly string _thumbnailsCacheFile = Path.Combine(directoriesConfig.Value.ThumbnailsDirectory, Constants.THUMBNAILS_CACHE_FILE);
|
private readonly string _thumbnailsCacheFile = Path.Combine(directoriesConfig.Value.ThumbnailsDirectory, Constants.THUMBNAILS_CACHE_FILE);
|
||||||
public event ThumbnailsUpdatedEventHandler ThumbnailsUpdate;
|
public event ThumbnailsUpdatedEventHandler? ThumbnailsUpdate;
|
||||||
|
|
||||||
|
|
||||||
private readonly SemaphoreSlim _updateLock = new(1);
|
private readonly SemaphoreSlim _updateLock = new(1);
|
||||||
@@ -125,7 +125,7 @@ public class GalleryManager(
|
|||||||
await File.WriteAllTextAsync(_thumbnailsCacheFile, labelsCacheStr);
|
await File.WriteAllTextAsync(_thumbnailsCacheFile, labelsCacheStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default)
|
public async Task<(ThumbnailDto? thumbnailDto, List<int>? classes)> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -149,7 +149,7 @@ public class GalleryManager(
|
|||||||
{
|
{
|
||||||
File.Delete(imgPath);
|
File.Delete(imgPath);
|
||||||
logger.LogInformation($"No labels found for image {imgName}! Image deleted!");
|
logger.LogInformation($"No labels found for image {imgName}! Image deleted!");
|
||||||
return null;
|
return (null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
var labels = (await YoloLabel.ReadFromFile(labelName, cancellationToken))
|
var labels = (await YoloLabel.ReadFromFile(labelName, cancellationToken))
|
||||||
@@ -209,18 +209,19 @@ public class GalleryManager(
|
|||||||
var thumbnailName = Path.Combine(ThumbnailsDirectory.FullName, $"{Path.GetFileNameWithoutExtension(imgPath)}{Constants.THUMBNAIL_PREFIX}.jpg");
|
var thumbnailName = Path.Combine(ThumbnailsDirectory.FullName, $"{Path.GetFileNameWithoutExtension(imgPath)}{Constants.THUMBNAIL_PREFIX}.jpg");
|
||||||
bitmap.Save(thumbnailName, ImageFormat.Jpeg);
|
bitmap.Save(thumbnailName, ImageFormat.Jpeg);
|
||||||
|
|
||||||
return new ThumbnailDto
|
var thumbnailDto = new ThumbnailDto
|
||||||
{
|
{
|
||||||
ThumbnailPath = thumbnailName,
|
ThumbnailPath = thumbnailName,
|
||||||
ImagePath = imgPath,
|
ImagePath = imgPath,
|
||||||
LabelPath = labelName,
|
LabelPath = labelName,
|
||||||
ImageDate = File.GetCreationTimeUtc(imgPath)
|
ImageDate = File.GetCreationTimeUtc(imgPath)
|
||||||
};
|
};
|
||||||
|
return (thumbnailDto, classes);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.LogError(e, e.Message);
|
logger.LogError(e, e.Message);
|
||||||
return null;
|
return (null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,12 +242,12 @@ public class GalleryManager(
|
|||||||
|
|
||||||
public interface IGalleryManager
|
public interface IGalleryManager
|
||||||
{
|
{
|
||||||
event ThumbnailsUpdatedEventHandler ThumbnailsUpdate;
|
event ThumbnailsUpdatedEventHandler? ThumbnailsUpdate;
|
||||||
double ThumbnailsPercentage { get; set; }
|
double ThumbnailsPercentage { get; set; }
|
||||||
Task SaveLabelsCache();
|
Task SaveLabelsCache();
|
||||||
LabelInfo AddToCache(string imgPath, List<int> classes);
|
LabelInfo AddToCache(string imgPath, List<int> classes);
|
||||||
ConcurrentDictionary<string, LabelInfo> LabelsCache { get; set; }
|
ConcurrentDictionary<string, LabelInfo> LabelsCache { get; set; }
|
||||||
Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
|
Task<(ThumbnailDto? thumbnailDto, List<int>? classes)> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
|
||||||
Task RefreshThumbnails();
|
Task RefreshThumbnails();
|
||||||
void ClearThumbnails();
|
void ClearThumbnails();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user