mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:56:30 +00:00
add ai recognition: stage 1, works, but doesn't show
This commit is contained in:
@@ -49,7 +49,7 @@ public class GalleryManager : IGalleryManager
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_thumbnailsCacheFile = Path.Combine(config.ThumbnailsDirectory, Config.ThumbnailsCacheFile);
|
||||
_thumbnailsCacheFile = Path.Combine(config.ThumbnailsDirectory, Config.THUMBNAILS_CACHE_FILE);
|
||||
}
|
||||
|
||||
public void ClearThumbnails()
|
||||
@@ -63,7 +63,7 @@ public class GalleryManager : IGalleryManager
|
||||
await _updateLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
var prefixLen = Config.ThumbnailPrefix.Length;
|
||||
var prefixLen = Config.THUMBNAIL_PREFIX.Length;
|
||||
|
||||
var thumbnails = ThumbnailsDirectory.GetFiles()
|
||||
.Select(x => Path.GetFileNameWithoutExtension(x.Name)[..^prefixLen])
|
||||
@@ -122,7 +122,7 @@ public class GalleryManager : IGalleryManager
|
||||
await File.WriteAllTextAsync(_thumbnailsCacheFile, labelsCacheStr);
|
||||
}
|
||||
|
||||
public async Task CreateThumbnail(string imgPath, CancellationToken cancellationToken = default)
|
||||
public async Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var width = (int)_config.ThumbnailConfig.Size.Width;
|
||||
var height = (int)_config.ThumbnailConfig.Size.Height;
|
||||
@@ -144,9 +144,9 @@ public class GalleryManager : IGalleryManager
|
||||
{
|
||||
File.Move(imgPath, Path.Combine(_config.UnknownImages, imgName));
|
||||
_logger.LogInformation($"No labels found for image {imgName}! Moved image to the {_config.UnknownImages} folder.");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
var labels = (await YoloLabel.ReadFromFile(labelName))
|
||||
var labels = (await YoloLabel.ReadFromFile(labelName, cancellationToken))
|
||||
.Select(x => new CanvasLabel(x, size, size))
|
||||
.ToList();
|
||||
|
||||
@@ -204,13 +204,16 @@ public class GalleryManager : IGalleryManager
|
||||
g.FillRectangle(brush, rectangle);
|
||||
}
|
||||
|
||||
var thumbnailName = Path.Combine(ThumbnailsDirectory.FullName, $"{Path.GetFileNameWithoutExtension(imgPath)}{Config.THUMBNAIL_PREFIX}.jpg");
|
||||
bitmap.Save(thumbnailName, ImageFormat.Jpeg);
|
||||
|
||||
|
||||
if (bitmap != null)
|
||||
return new ThumbnailDto
|
||||
{
|
||||
var thumbnailName = Path.Combine(ThumbnailsDirectory.FullName, $"{Path.GetFileNameWithoutExtension(imgPath)}{Config.ThumbnailPrefix}.jpg");
|
||||
bitmap.Save(thumbnailName, ImageFormat.Jpeg);
|
||||
}
|
||||
ThumbnailPath = thumbnailName,
|
||||
ImagePath = imgPath,
|
||||
LabelPath = labelName,
|
||||
ImageDate = File.GetCreationTimeUtc(imgPath)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +223,7 @@ public interface IGalleryManager
|
||||
double ThumbnailsPercentage { get; set; }
|
||||
Task SaveLabelsCache();
|
||||
ConcurrentDictionary<string, LabelInfo> LabelsCache { get; set; }
|
||||
Task CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
|
||||
Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
|
||||
Task RefreshThumbnails();
|
||||
void ClearThumbnails();
|
||||
}
|
||||
Reference in New Issue
Block a user