Ejemplo n.º 1
0
        public IEnumerable <DetectedItemInfo> Detect(byte[] imageData)
        {
            var container = new BoundingBoxContainer();

            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 (DetectionHardware)
                {
                case DetectionHardwares.CPU:
                    count = DetectImageInCpu(pnt, imageData.Length, ref container);
                    break;

                case DetectionHardwares.GPU:
                    count = DetectImageInGpu(pnt, imageData.Length, ref container);
                    break;
                }
            }
            catch (Exception exception)
            {
                return(null);
            }
            finally
            {
                // Free the unmanaged memory.
                Marshal.FreeHGlobal(pnt);
            }

            return(Convert(container));
        }
Ejemplo n.º 2
0
        public IEnumerable <DetectedItemInfo> Detect(string imageFilePath)
        {
            if (!File.Exists(imageFilePath))
            {
                throw new FileNotFoundException("Cannot find the file", imageFilePath);
            }

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

            DetectImageInGpu(imageFilePath, ref container);
            return(Convert(container));
        }
Ejemplo n.º 3
0
        private IEnumerable <DetectedItemInfo> Convert(BoundingBoxContainer container)
        {
            var netItems = new List <DetectedItemInfo>();

            foreach (var item in container.candidates.Where(o => o.height > 0 || o.width > 0))
            {
                var objectType = m_ObjectType[(int)item.obj_id];
                var netItem    = new DetectedItemInfo()
                {
                    X = (int)item.leftTopX, Y = (int)item.leftTopY, Height = (int)item.height, Width = (int)item.width, Confidence = item.prob, Type = objectType
                };
                netItems.Add(netItem);
            }

            return(netItems);
        }
Ejemplo n.º 4
0
        public IEnumerable <DetectedItemInfo> Detect(string imageFilePath)
        {
            if (!File.Exists(imageFilePath))
            {
                throw new FileNotFoundException("Cannot find the file", imageFilePath);
            }

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

            switch (DetectionHardware)
            {
            case DetectionHardwares.CPU:
                count = DetectImageInCpu(imageFilePath, ref container);
                break;

            case DetectionHardwares.GPU:
                count = DetectImageInGpu(imageFilePath, ref container);
                break;
            }

            return(Convert(container));
        }
Ejemplo n.º 5
0
 internal static extern int DetectImageInGpu(IntPtr pArray, int nSize, ref BoundingBoxContainer container);
Ejemplo n.º 6
0
 internal static extern int DetectImageInGpu(string filename, ref BoundingBoxContainer container);