From b1dddf02ccf8dcfaadee4e8a5ed8726725ec1b93 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Sun, 12 Aug 2018 23:43:45 +0000
Subject: [PATCH] Fixed AVX compiled bug

---
 build/darknet/YoloWrapper.cs |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/build/darknet/YoloWrapper.cs b/build/darknet/YoloWrapper.cs
index ade0059..f0c1b0c 100644
--- a/build/darknet/YoloWrapper.cs
+++ b/build/darknet/YoloWrapper.cs
@@ -6,18 +6,19 @@
     public class YoloWrapper : IDisposable
     {
         private const string YoloLibraryName = "yolo_cpp_dll.dll";
+        private const int MaxObjects = 1000;
 
         [DllImport(YoloLibraryName, EntryPoint = "init")]
-        public static extern int InitializeYolo(string configurationFilename, string weightsFilename, int gpu);
+        private static extern int InitializeYolo(string configurationFilename, string weightsFilename, int gpu);
 
         [DllImport(YoloLibraryName, EntryPoint = "detect_image")]
-        public static extern int DetectImage(string filename, ref BboxContainer container);
+        private static extern int DetectImage(string filename, ref BboxContainer container);
 
         [DllImport(YoloLibraryName, EntryPoint = "detect_mat")]
-        public static extern int DetectImage(IntPtr pArray, int nSize, ref BboxContainer container);
+        private static extern int DetectImage(IntPtr pArray, int nSize, ref BboxContainer container);
 
         [DllImport(YoloLibraryName, EntryPoint = "dispose")]
-        public static extern int DisposeYolo();
+        private static extern int DisposeYolo();
 
         [StructLayout(LayoutKind.Sequential)]
         public struct bbox_t
@@ -29,10 +30,10 @@
             public UInt32 frames_counter;
         };
 
-        [StructLayout(LayoutKind.Sequential, Size = 10)]
+        [StructLayout(LayoutKind.Sequential)]
         public struct BboxContainer
         {
-            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
+            [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxObjects)]
             public bbox_t[] candidates;
         }
 
@@ -65,7 +66,11 @@
             {
                 // Copy the array to unmanaged memory.
                 Marshal.Copy(imageData, 0, pnt, imageData.Length);
-                DetectImage(pnt, imageData.Length, ref container);
+                var count = DetectImage(pnt, imageData.Length, ref container);
+                if (count == -1)
+                {
+                    throw new NotSupportedException($"{YoloLibraryName} has no OpenCV support");
+                }
             }
             catch (Exception exception)
             {

--
Gitblit v1.10.0