splitting python complete

This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-08-12 14:48:56 +03:00
parent fc6e5db795
commit ad782bcbaa
31 changed files with 834 additions and 369 deletions
+18 -23
View File
@@ -18,10 +18,8 @@ public class TileResult
public static class TileProcessor
{
private const int MaxTileWidth = 1280;
private const int MaxTileHeight = 1280;
private const int Border = 10;
public const int BORDER = 10;
public static List<TileResult> Split(Size originalSize, List<CanvasLabel> detections, CancellationToken cancellationToken)
{
var results = new List<TileResult>();
@@ -30,7 +28,7 @@ public static class TileProcessor
while (processingDetectionList.Count > 0 && !cancellationToken.IsCancellationRequested)
{
var topMostDetection = processingDetectionList
.OrderBy(d => d.Y)
.OrderBy(d => d.Top)
.First();
var result = GetDetectionsInTile(originalSize, topMostDetection, processingDetectionList);
@@ -42,11 +40,8 @@ public static class TileProcessor
private static TileResult GetDetectionsInTile(Size originalSize, CanvasLabel startDet, List<CanvasLabel> allDetections)
{
var tile = new CanvasLabel(
left: Math.Max(startDet.X - Border, 0),
right: Math.Min(startDet.Right + Border, originalSize.Width),
top: Math.Max(startDet.Y - Border, 0),
bottom: Math.Min(startDet.Bottom + Border, originalSize.Height));
var tile = new CanvasLabel(startDet.Left, startDet.Right, startDet.Top, startDet.Bottom);
var maxSize = new List<double> { startDet.Width + BORDER, startDet.Height + BORDER, Constants.AI_TILE_SIZE }.Max();
var selectedDetections = new List<CanvasLabel>{startDet};
foreach (var det in allDetections)
@@ -55,26 +50,26 @@ public static class TileProcessor
continue;
var commonTile = new CanvasLabel(
left: Math.Max(Math.Min(tile.X, det.X) - Border, 0),
right: Math.Min(Math.Max(tile.Right, det.Right) + Border, originalSize.Width),
top: Math.Max(Math.Min(tile.Y, det.Y) - Border, 0),
bottom: Math.Min(Math.Max(tile.Bottom, det.Bottom) + Border, originalSize.Height)
left: Math.Min(tile.Left, det.Left),
right: Math.Max(tile.Right, det.Right),
top: Math.Min(tile.Top, det.Top),
bottom: Math.Max(tile.Bottom, det.Bottom)
);
if (commonTile.Width > MaxTileWidth || commonTile.Height > MaxTileHeight)
if (commonTile.Width + BORDER > maxSize || commonTile.Height + BORDER > maxSize)
continue;
tile = commonTile;
selectedDetections.Add(det);
}
//normalization, width and height should be at least half of 1280px
tile.Width = Math.Max(tile.Width, MaxTileWidth / 2.0);
tile.Height = Math.Max(tile.Height, MaxTileHeight / 2.0);
//boundaries check after normalization
tile.Right = Math.Min(tile.Right, originalSize.Width);
tile.Bottom = Math.Min(tile.Bottom, originalSize.Height);
// boundary-aware centering
var centerX = selectedDetections.Average(x => x.CenterX);
var centerY = selectedDetections.Average(d => d.CenterY);
tile.Width = maxSize;
tile.Height = maxSize;
tile.Left = Math.Max(0, Math.Min(originalSize.Width - maxSize, centerX - tile.Width / 2.0));
tile.Top = Math.Max(0, Math.Min(originalSize.Height - maxSize, centerY - tile.Height / 2.0));
return new TileResult(tile, selectedDetections);
}