-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
1,436 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace YoloEase.Cvat.Shared; | ||
|
||
public record CvatAnnotationImage | ||
{ | ||
[XmlAttribute("id")] public int Id { get; set; } | ||
|
||
[XmlAttribute("name")] public string Name { get; set; } | ||
|
||
[XmlAttribute("subset")] public string Subset { get; set; } | ||
|
||
[XmlAttribute("task_id")] public int TaskId { get; set; } | ||
|
||
[XmlAttribute("width")] public int Width { get; set; } | ||
|
||
[XmlAttribute("height")] public int Height { get; set; } | ||
|
||
[XmlElement("box")] public List<CvatBox> Boxes { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace YoloEase.Cvat.Shared; | ||
|
||
[XmlRoot("annotations")] | ||
public record CvatAnnotations | ||
{ | ||
[XmlElement("image")] public List<CvatAnnotationImage> Images { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace YoloEase.Cvat.Shared; | ||
|
||
public record CvatBox | ||
{ | ||
[XmlAttribute("label")] public string Label { get; set; } | ||
|
||
[XmlAttribute("source")] public string Source { get; set; } | ||
|
||
[XmlAttribute("occluded")] public int Occluded { get; set; } | ||
|
||
[XmlAttribute("xtl")] public double Xtl { get; set; } | ||
|
||
[XmlAttribute("ytl")] public double Ytl { get; set; } | ||
|
||
[XmlAttribute("xbr")] public double Xbr { get; set; } | ||
|
||
[XmlAttribute("ybr")] public double Ybr { get; set; } | ||
|
||
[XmlAttribute("z_order")] public int ZOrder { get; set; } | ||
|
||
public double Width() => Xbr - Xtl; | ||
public double Height() => Ybr - Ytl; | ||
|
||
public double Area(){ | ||
var width = Xbr - Xtl; | ||
var height = Ybr - Ytl; | ||
return width * height; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace YoloEase.Cvat.Shared; | ||
|
||
public readonly record struct CvatRectangleD | ||
{ | ||
public CvatRectangleD(double x, double y, double width, double height) | ||
{ | ||
X = x; | ||
Y = y; | ||
Width = width; | ||
Height = height; | ||
} | ||
|
||
public double X { get; init; } | ||
public double Y { get; init; } | ||
public double Width { get; init; } | ||
public double Height { get; init; } | ||
|
||
public double CenterX => X + Width / 2; | ||
|
||
public double CenterY => Y + Height / 2; | ||
|
||
/// <summary> | ||
/// The first number represents the normalized x-coordinate of the center of the bounding box relative to the width of the image. In your example, the x-coordinate is approximately 0.695, indicating that the center of the bounding box is located around 69.5% of the image width. | ||
/// The second number represents the normalized y-coordinate of the center of the bounding box relative to the height of the image.In your example, the y-coordinate is approximately 0.645, indicating that the center of the bounding box is located around 64.5% of the image height. | ||
/// The third number represents the normalized width of the bounding box relative to the width of the image.In your example, the width is approximately 0.0325, indicating that the bounding box width is around 3.25% of the image width. | ||
/// The fourth number represents the normalized height of the bounding box relative to the height of the image. In your example, the height is approximately 0.00664, indicating that the bounding box height is around 0.664% of the image height. | ||
/// These numbers together specify the position and size of the bounding box that encloses an object within an image. The normalized values allow the annotations to be consistent across different image sizes and resolutions. | ||
/// e.g. | ||
/// 0.6949948072433472 0.6448148488998413 0.03246873617172241 0.006638884544372559 | ||
/// </summary> | ||
public static CvatRectangleD FromYolo(double centerX, double centerY, double width, double height) => | ||
new CvatRectangleD(x: centerX - width / 2, y: centerY - height / 2, width, height); | ||
|
||
public static CvatRectangleD FromLTRB(double left, double top, double right, double bottom) => | ||
new CvatRectangleD(left, top, right - left, bottom - top); | ||
} | ||
|
||
// Class definitions for XML deserialization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Sources/YoloEase.Tests/UI/Augmentations/FlipImageEffectFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using PoeShared.Tests.Helpers; | ||
using Shouldly; | ||
using SixLabors.ImageSharp; | ||
using SixLabors.ImageSharp.Processing; | ||
using YoloEase.UI.Augmentations; | ||
|
||
namespace YoloEase.Tests.UI.Augmentations; | ||
|
||
public class FlipImageEffectFixture | ||
{ | ||
[Test] | ||
[TestCaseSource(nameof(ShouldMutateBoundingBoxCases))] | ||
public void ShouldMutateBoundingBox(FlipMode flipMode, Size imageSize, RectangleF initialBox, RectangleF expected) | ||
{ | ||
//Given | ||
var instance = CreateInstance(); | ||
instance.FlipMode = flipMode; | ||
|
||
//When | ||
var result = instance.Mutate(imageSize, initialBox); | ||
|
||
|
||
//Then | ||
result.ShouldBe(expected); | ||
} | ||
|
||
public static IEnumerable<NamedTestCaseData> ShouldMutateBoundingBoxCases() | ||
{ | ||
// Flip horizontal | ||
yield return new NamedTestCaseData(FlipMode.Horizontal, new Size(10, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "Horizontal - In-place" }; | ||
yield return new NamedTestCaseData(FlipMode.Horizontal, new Size(20, 10), new RectangleF(0, 0, 10, 10), new RectangleF(10, 0, 10, 10)) { TestName = "Horizontal - Landscape" }; | ||
yield return new NamedTestCaseData(FlipMode.Horizontal, new Size(20, 20), new RectangleF(0, 0, 10, 10), new RectangleF(10, 0, 10, 10)) { TestName = "Horizontal - Square" }; | ||
yield return new NamedTestCaseData(FlipMode.Horizontal, new Size(10, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "Horizontal - Portrait" }; | ||
|
||
// Flip vertical | ||
yield return new NamedTestCaseData(FlipMode.Vertical, new Size(10, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "Vertical - In-place" }; | ||
yield return new NamedTestCaseData(FlipMode.Vertical, new Size(20, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "Vertical - Landscape" }; | ||
yield return new NamedTestCaseData(FlipMode.Vertical, new Size(20, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 10, 10, 10)) { TestName = "Vertical - Square" }; | ||
yield return new NamedTestCaseData(FlipMode.Vertical, new Size(10, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 10, 10, 10)) { TestName = "Vertical - Portrait" }; | ||
|
||
// No flip | ||
yield return new NamedTestCaseData(FlipMode.None, new Size(10, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "None - No rotation" }; | ||
yield return new NamedTestCaseData(FlipMode.None, new Size(20, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "None - Landscape" }; | ||
yield return new NamedTestCaseData(FlipMode.None, new Size(20, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "None - Square" }; | ||
yield return new NamedTestCaseData(FlipMode.None, new Size(10, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "None - Portrait" }; | ||
} | ||
|
||
private FlipImageEffect CreateInstance() | ||
{ | ||
return new FlipImageEffect(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Sources/YoloEase.Tests/UI/Augmentations/RotateImageEffectFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using PoeShared.Tests.Helpers; | ||
using Shouldly; | ||
using SixLabors.ImageSharp; | ||
using SixLabors.ImageSharp.Processing; | ||
using YoloEase.UI.Augmentations; | ||
|
||
namespace YoloEase.Tests.UI.Augmentations; | ||
|
||
public class RotateImageEffectFixture | ||
{ | ||
[Test] | ||
[TestCaseSource(nameof(ShouldMutateBoundingBoxCases))] | ||
public void ShouldMutateBoundingBox(RotateMode rotateMode, Size imageSize, RectangleF initialBox, RectangleF expected) | ||
{ | ||
//Given | ||
var instance = CreateInstance(); | ||
instance.Rotation = rotateMode; | ||
|
||
//When | ||
var result = instance.Mutate(imageSize, initialBox); | ||
|
||
|
||
//Then | ||
result.ShouldBe(expected); | ||
} | ||
|
||
public static IEnumerable<NamedTestCaseData> ShouldMutateBoundingBoxCases() | ||
{ | ||
// Rotate 90 degrees | ||
yield return new NamedTestCaseData(RotateMode.Rotate90, new Size(10, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "90 degrees - In-place" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate90, new Size(20, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "90 degrees - Landscape" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate90, new Size(20, 20), new RectangleF(0, 0, 10, 10), new RectangleF(10, 0, 10, 10)) { TestName = "90 degrees - Square" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate90, new Size(10, 20), new RectangleF(0, 0, 10, 10), new RectangleF(10, 0, 10, 10)) { TestName = "90 degrees - Portrait" }; | ||
|
||
// Rotate 180 degrees | ||
yield return new NamedTestCaseData(RotateMode.Rotate180, new Size(10, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "180 degrees - In-place" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate180, new Size(20, 10), new RectangleF(0, 0, 10, 10), new RectangleF(10, 0, 10, 10)) { TestName = "180 degrees - Landscape" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate180, new Size(20, 20), new RectangleF(0, 0, 10, 10), new RectangleF(10, 10, 10, 10)) { TestName = "180 degrees - Square" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate180, new Size(10, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 10, 10, 10)) { TestName = "180 degrees - Portrait" }; | ||
|
||
// Rotate 270 degrees | ||
yield return new NamedTestCaseData(RotateMode.Rotate270, new Size(10, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "270 degrees - In-place" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate270, new Size(20, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 10, 10, 10)) { TestName = "270 degrees - Landscape" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate270, new Size(20, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 10, 10, 10)) { TestName = "270 degrees - Square" }; | ||
yield return new NamedTestCaseData(RotateMode.Rotate270, new Size(10, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "270 degrees - Portrait" }; | ||
|
||
// Rotate 0 degrees (no rotation) | ||
yield return new NamedTestCaseData(RotateMode.None, new Size(10, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "0 degrees - No rotation" }; | ||
yield return new NamedTestCaseData(RotateMode.None, new Size(20, 10), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "0 degrees - Landscape" }; | ||
yield return new NamedTestCaseData(RotateMode.None, new Size(20, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "0 degrees - Square" }; | ||
yield return new NamedTestCaseData(RotateMode.None, new Size(10, 20), new RectangleF(0, 0, 10, 10), new RectangleF(0, 0, 10, 10)) { TestName = "0 degrees - Portrait" }; | ||
} | ||
|
||
private RotateImageEffect CreateInstance() | ||
{ | ||
return new RotateImageEffect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.