mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 09:06:30 +00:00
splitting python complete
This commit is contained in:
+31
-27
@@ -22,52 +22,56 @@ public abstract class Label
|
||||
|
||||
public class CanvasLabel : Label
|
||||
{
|
||||
public double X { get; set; } //left
|
||||
public double Y { get; set; } //top
|
||||
public double Left { get; set; }
|
||||
public double Top { get; set; }
|
||||
public double Width { get; set; }
|
||||
public double Height { get; set; }
|
||||
public double Confidence { get; set; }
|
||||
|
||||
public double Bottom
|
||||
{
|
||||
get => Y + Height;
|
||||
set => Height = value - Y;
|
||||
get => Top + Height;
|
||||
set => Height = value - Top;
|
||||
}
|
||||
|
||||
public double Right
|
||||
{
|
||||
get => X + Width;
|
||||
set => Width = value - X;
|
||||
get => Left + Width;
|
||||
set => Width = value - Left;
|
||||
}
|
||||
|
||||
public double CenterX => Left + Width / 2.0;
|
||||
public double CenterY => Top + Height / 2.0;
|
||||
public Size Size => new(Width, Height);
|
||||
|
||||
public CanvasLabel() { }
|
||||
|
||||
public CanvasLabel(double left, double right, double top, double bottom)
|
||||
{
|
||||
X = left;
|
||||
Y = top;
|
||||
Left = left;
|
||||
Top = top;
|
||||
Width = right - left;
|
||||
Height = bottom - top;
|
||||
Confidence = 1;
|
||||
ClassNumber = -1;
|
||||
}
|
||||
|
||||
public CanvasLabel(int classNumber, double x, double y, double width, double height, double confidence = 1) : base(classNumber)
|
||||
public CanvasLabel(int classNumber, double left, double top, double width, double height, double confidence = 1) : base(classNumber)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Left = left;
|
||||
Top = top;
|
||||
Width = width;
|
||||
Height = height;
|
||||
Confidence = confidence;
|
||||
}
|
||||
|
||||
public CanvasLabel(YoloLabel label, Size canvasSize, Size? videoSize = null, double confidence = 1)
|
||||
public CanvasLabel(YoloLabel label, Size canvasSize, Size? mediaSize = null, double confidence = 1)
|
||||
{
|
||||
var cw = canvasSize.Width;
|
||||
var ch = canvasSize.Height;
|
||||
var canvasAr = cw / ch;
|
||||
var videoAr = videoSize.HasValue
|
||||
? videoSize.Value.Width / videoSize.Value.Height
|
||||
var videoAr = mediaSize.HasValue
|
||||
? mediaSize.Value.Width / mediaSize.Value.Height
|
||||
: canvasAr;
|
||||
|
||||
ClassNumber = label.ClassNumber;
|
||||
@@ -80,8 +84,8 @@ public class CanvasLabel : Label
|
||||
var realHeight = cw / videoAr; //real video height in pixels on canvas
|
||||
var blackStripHeight = (ch - realHeight) / 2.0; //height of black strips at the top and bottom
|
||||
|
||||
X = left * cw;
|
||||
Y = top * realHeight + blackStripHeight;
|
||||
Left = left * cw;
|
||||
Top = top * realHeight + blackStripHeight;
|
||||
Width = label.Width * cw;
|
||||
Height = label.Height * realHeight;
|
||||
}
|
||||
@@ -90,8 +94,8 @@ public class CanvasLabel : Label
|
||||
var realWidth = ch * videoAr; //real video width in pixels on canvas
|
||||
var blackStripWidth = (cw - realWidth) / 2.0; //height of black strips at the top and bottom
|
||||
|
||||
X = left * realWidth + blackStripWidth;
|
||||
Y = top * ch;
|
||||
Left = left * realWidth + blackStripWidth;
|
||||
Top = top * ch;
|
||||
Width = label.Width * realWidth;
|
||||
Height = label.Height * ch;
|
||||
}
|
||||
@@ -99,10 +103,10 @@ public class CanvasLabel : Label
|
||||
}
|
||||
|
||||
public CanvasLabel ReframeToSmall(CanvasLabel smallTile) =>
|
||||
new(ClassNumber, X - smallTile.X, Y - smallTile.Y, Width, Height, Confidence);
|
||||
new(ClassNumber, Left - smallTile.Left, Top - smallTile.Top, Width, Height, Confidence);
|
||||
|
||||
public CanvasLabel ReframeFromSmall(CanvasLabel smallTile) =>
|
||||
new(ClassNumber, X + smallTile.X, Y + smallTile.Y, Width, Height, Confidence);
|
||||
new(ClassNumber, Left + smallTile.Left, Top + smallTile.Top, Width, Height, Confidence);
|
||||
|
||||
}
|
||||
|
||||
@@ -132,13 +136,13 @@ public class YoloLabel : Label
|
||||
public RectangleF ToRectangle() =>
|
||||
new((float)(CenterX - Width / 2.0), (float)(CenterY - Height / 2.0), (float)Width, (float)Height);
|
||||
|
||||
public YoloLabel(CanvasLabel canvasLabel, Size canvasSize, Size? videoSize = null)
|
||||
public YoloLabel(CanvasLabel canvasLabel, Size canvasSize, Size? mediaSize = null)
|
||||
{
|
||||
var cw = canvasSize.Width;
|
||||
var ch = canvasSize.Height;
|
||||
var canvasAr = cw / ch;
|
||||
var videoAr = videoSize.HasValue
|
||||
? videoSize.Value.Width / videoSize.Value.Height
|
||||
var videoAr = mediaSize.HasValue
|
||||
? mediaSize.Value.Width / mediaSize.Value.Height
|
||||
: canvasAr;
|
||||
|
||||
ClassNumber = canvasLabel.ClassNumber;
|
||||
@@ -146,20 +150,20 @@ public class YoloLabel : Label
|
||||
double left, top;
|
||||
if (videoAr > canvasAr) //100% width
|
||||
{
|
||||
left = canvasLabel.X / cw;
|
||||
left = canvasLabel.Left / cw;
|
||||
Width = canvasLabel.Width / cw;
|
||||
var realHeight = cw / videoAr; //real video height in pixels on canvas
|
||||
var blackStripHeight = (ch - realHeight) / 2.0; //height of black strips at the top and bottom
|
||||
top = (canvasLabel.Y - blackStripHeight) / realHeight;
|
||||
top = (canvasLabel.Top - blackStripHeight) / realHeight;
|
||||
Height = canvasLabel.Height / realHeight;
|
||||
}
|
||||
else //100% height
|
||||
{
|
||||
top = canvasLabel.Y / ch;
|
||||
top = canvasLabel.Top / ch;
|
||||
Height = canvasLabel.Height / ch;
|
||||
var realWidth = ch * videoAr; //real video width in pixels on canvas
|
||||
var blackStripWidth = (cw - realWidth) / 2.0; //height of black strips at the top and bottom
|
||||
left = (canvasLabel.X - blackStripWidth) / realWidth;
|
||||
left = (canvasLabel.Left - blackStripWidth) / realWidth;
|
||||
Width = canvasLabel.Width / realWidth;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user