diff --git a/src/Alturos.Yolo.UnitTest/BasicTest.cs b/src/Alturos.Yolo.UnitTest/BasicTest.cs
index ac4110e..5cd7ea5 100644
--- a/src/Alturos.Yolo.UnitTest/BasicTest.cs
+++ b/src/Alturos.Yolo.UnitTest/BasicTest.cs
@@ -1,6 +1,6 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.IO;
+using System.IO;
using System.Linq;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Alturos.Yolo.UnitTest
{
@@ -27,7 +27,7 @@ public void DetectFromFilePath()
using (var yoloWrapper = new YoloWrapper(configuration))
{
var items = yoloWrapper.Detect(this._imagePath);
- Assert.IsTrue(items.Count() > 0);
+ Assert.IsTrue(items.Any());
}
}
@@ -39,7 +39,7 @@ public void DetectFromFileData()
{
var imageData = File.ReadAllBytes(this._imagePath);
var items = yoloWrapper.Detect(imageData);
- Assert.IsTrue(items.Count() > 0);
+ Assert.IsTrue(items.Any());
}
}
}
diff --git a/src/Alturos.Yolo/Alturos.Yolo.csproj b/src/Alturos.Yolo/Alturos.Yolo.csproj
index 118256f..be343a6 100644
--- a/src/Alturos.Yolo/Alturos.Yolo.csproj
+++ b/src/Alturos.Yolo/Alturos.Yolo.csproj
@@ -16,6 +16,7 @@
3.0.6-alpha
3.0.6
3.0.6
+ true
diff --git a/src/Alturos.Yolo/YoloWrapper.cs b/src/Alturos.Yolo/YoloWrapper.cs
index 7dc344f..4196de5 100644
--- a/src/Alturos.Yolo/YoloWrapper.cs
+++ b/src/Alturos.Yolo/YoloWrapper.cs
@@ -205,7 +205,7 @@ public IEnumerable Detect(string filepath)
///
/// Thrown when the yolo_cpp dll is wrong compiled
/// Thrown when the byte array is not a valid image
- public IEnumerable Detect(byte[] imageData)
+ public unsafe IEnumerable Detect(byte[] imageData)
{
if (!this._imageAnalyzer.IsValidImageFormat(imageData))
{
@@ -213,33 +213,28 @@ public IEnumerable Detect(byte[] imageData)
}
var container = new BboxContainer();
- var size = Marshal.SizeOf(imageData[0]) * imageData.Length;
- var pnt = Marshal.AllocHGlobal(size);
+ var size = imageData.Length;
var count = 0;
try
{
- // Copy the array to unmanaged memory.
- Marshal.Copy(imageData, 0, pnt, imageData.Length);
- switch (this.DetectionSystem)
- {
- case DetectionSystem.CPU:
- count = DetectImageCpu(pnt, imageData.Length, ref container);
- break;
- case DetectionSystem.GPU:
- count = DetectImageGpu(pnt, imageData.Length, ref container);
- break;
+ fixed (byte* pnt = imageData)
+ {
+ switch (this.DetectionSystem)
+ {
+ case DetectionSystem.CPU:
+ count = DetectImageCpu((IntPtr)pnt, imageData.Length, ref container);
+ break;
+ case DetectionSystem.GPU:
+ count = DetectImageGpu((IntPtr)pnt, imageData.Length, ref container);
+ break;
+ }
}
}
catch (Exception)
{
return null;
}
- finally
- {
- // Free the unmanaged memory.
- Marshal.FreeHGlobal(pnt);
- }
if (count == -1)
{