Пример #1
0
        private IEnumerable <YoloItem> Convert(BboxContainer container)
        {
            var yoloItems = new List <YoloItem>();

            foreach (var item in container.candidates.Where(o => o.h > 0 || o.w > 0))
            {
                if (!this._objectType.TryGetValue((int)item.obj_id, out var objectType))
                {
                    objectType = "unknown key";
                }

                var yoloItem = new YoloItem
                {
                    X          = (int)item.x,
                    Y          = (int)item.y,
                    Height     = (int)item.h,
                    Width      = (int)item.w,
                    Confidence = item.prob,
                    Type       = objectType
                };

                yoloItems.Add(yoloItem);
            }

            return(yoloItems);
        }
Пример #2
0
        public IEnumerable <YoloItem> Detect(string filepath)
        {
            if (!File.Exists(filepath))
            {
                throw new FileNotFoundException("Cannot find the file", filepath);
            }

            var container = new BboxContainer();
            var count     = 0;

            switch (this.DetectionSystem)
            {
            case DetectionSystem.CPU:
                count = DetectImageCpu(filepath, ref container);
                break;

            case DetectionSystem.GPU:
                count = DetectImageGpu(filepath, ref container);
                break;
            }

            if (count == -1)
            {
                throw new NotImplementedException("C++ dll compiled incorrectly");
            }

            return(this.Convert(container));
        }
Пример #3
0
        public IEnumerable <YoloItem> Detect(byte[] imageData)
        {
            if (!this._imageAnalyzer.IsValidImageFormat(imageData))
            {
                throw new Exception("Invalid image data, wrong image format");
            }

            var container = new BboxContainer();
            var size      = Marshal.SizeOf(imageData[0]) * imageData.Length;
            var pnt       = Marshal.AllocHGlobal(size);

            try
            {
                // Copy the array to unmanaged memory.
                Marshal.Copy(imageData, 0, pnt, imageData.Length);
                var count = 0;
                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;
                }

                if (count == -1)
                {
                    throw new NotImplementedException("C++ dll compiled incorrectly");
                }
            }
            catch (Exception exception)
            {
                return(null);
            }
            finally
            {
                // Free the unmanaged memory.
                Marshal.FreeHGlobal(pnt);
            }

            return(this.Convert(container));
        }
Пример #4
0
 internal static extern int DetectImageGpu(IntPtr pArray, int nSize, ref BboxContainer container);
Пример #5
0
 internal static extern int DetectImageGpu(string filename, ref BboxContainer container);