mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:56:30 +00:00
fix editing tiled images
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Azaion.Common.Database;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.Extensions;
|
||||
using MediatR;
|
||||
using Color = System.Windows.Media.Color;
|
||||
using Image = System.Windows.Controls.Image;
|
||||
@@ -473,17 +474,16 @@ public class CanvasEditor : Canvas
|
||||
|
||||
public void CreateDetections(Annotation annotation, List<DetectionClass> detectionClasses, Size mediaSize)
|
||||
{
|
||||
var splitTile = annotation.SplitTile;
|
||||
foreach (var detection in annotation.Detections)
|
||||
{
|
||||
var detectionClass = DetectionClass.FromYoloId(detection.ClassNumber, detectionClasses);
|
||||
CanvasLabel canvasLabel;
|
||||
if (splitTile == null)
|
||||
if (!annotation.IsSplit || mediaSize.FitSizeForAI())
|
||||
canvasLabel = new CanvasLabel(detection, RenderSize, mediaSize, detection.Confidence);
|
||||
else
|
||||
{
|
||||
canvasLabel = new CanvasLabel(detection, new Size(Constants.AI_TILE_SIZE, Constants.AI_TILE_SIZE), null, detection.Confidence)
|
||||
.ReframeFromSmall(splitTile);
|
||||
.ReframeFromSmall(annotation.SplitTile!);
|
||||
|
||||
//From CurrentMediaSize to Render Size
|
||||
var yoloLabel = new YoloLabel(canvasLabel, mediaSize);
|
||||
|
||||
@@ -26,4 +26,14 @@ public static class BitmapExtensions
|
||||
|
||||
public static Color CreateTransparent(this Color color, byte transparency) =>
|
||||
Color.FromArgb(transparency, color.R, color.G, color.B);
|
||||
|
||||
public static async Task SaveImage(this BitmapSource bitmap, string path, CancellationToken ct = default)
|
||||
{
|
||||
await using var stream = new FileStream(path, FileMode.Create);
|
||||
var encoder = new JpegBitmapEncoder();
|
||||
|
||||
encoder.Frames.Add(BitmapFrame.Create(bitmap));
|
||||
encoder.Save(stream);
|
||||
await stream.FlushAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Azaion.Common.Extensions;
|
||||
|
||||
public static class SizeExtensions
|
||||
{
|
||||
public static bool FitSizeForAI(this Size size) =>
|
||||
// Allow to be up to FullHD to save as 1280*1280
|
||||
size.Width <= Constants.AI_TILE_SIZE * 1.5 && size.Height <= Constants.AI_TILE_SIZE * 1.5;
|
||||
}
|
||||
Reference in New Issue
Block a user