Esempio n. 1
0
        static async Task Main(string[] args)
        {
            CvInvoke.Init();

            if (!DepthAIInvoke.HaveDepthAI)
            {
                Console.WriteLine("The native binary is built without Depth AI support.");
                return;
            }

            String win1 = "Depth AI (Press 'q' to quit)"; //The name of the window

            CvInvoke.NamedWindow(win1);                   //Create the window using the specific name


            MobilenetSsd mobilenet = new MobilenetSsd();

            //This download the models and return the default configuration
            await mobilenet.Init(onDownloadProgressChanged);

            Config config = mobilenet.ModelConfig;

            String[] labels = mobilenet.Labels;

            using (Emgu.CV.DepthAI.Device d = new Device(""))
            {
                //String[] availableStreams = d.GetAvailableStreams();
                using (CNNHostPipeline pipeline = d.CreatePipeline(JsonConvert.SerializeObject(config)))
                {
                    if (pipeline.Ptr == IntPtr.Zero)
                    {
                        Console.WriteLine("Failed to create device pipeline.");
                        return;
                    }
                    while (_is_running)
                    {
                        using (NNetAndDataPackets packets = pipeline.GetAvailableNNetAndDataPackets(false))
                        {
                            HostDataPacket[] dataPackets = packets.HostDataPackets;
                            NNetPacket[]     nnetPackets = packets.NNetPackets;

                            for (int i = 0; i < dataPackets.Length; i++)
                            {
                                if (dataPackets[i].GetPreviewOut(_render))
                                {
                                    using (FrameMetadata fmeta = dataPackets[i].GetFrameMetadata())
                                    {
                                        if (i < nnetPackets.Length)
                                        {
                                            NNetPacket nnetPacket = nnetPackets[i];
                                            using (FrameMetadata meta = nnetPacket.GetFrameMetadata())
                                            {
                                                _mostRecentDetections = nnetPacket.Detections;
                                            }
                                        }

                                        if (_mostRecentDetections != null)
                                        {
                                            for (int j = 0; j < _mostRecentDetections.Length; j++)
                                            {
                                                DrawDetection(_mostRecentDetections[j], _render, labels);
                                            }
                                        }

                                        CvInvoke.Imshow(win1, _render); //Show the image
                                    }
                                }
                                else
                                {
                                    //failed to get preview image
                                }
                            }
                        }

                        if (CvInvoke.WaitKey(1) > 0) //Press any key to stop
                        {
                            _is_running = false;
                        }
                    }
                }
            }

            CvInvoke.DestroyAllWindows(); //Destroy all windows if key is pressed
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            CvInvoke.Init();

            if (!DepthAIInvoke.HaveDepthAI)
            {
                return;
            }

            String win1 = "Depth AI";   //The name of the window

            CvInvoke.NamedWindow(win1); //Create the window using the specific name

            String blobFile       = "D:\\sourceforge\\depthai\\resources\\nn/mobilenet-ssd/mobilenet-ssd.blob.sh14cmx14NCE1";
            String blobFileConfig = "D:\\sourceforge\\depthai\\resources\\nn/mobilenet-ssd/mobilenet-ssd.json";

            Config config    = Emgu.CV.Models.DepthAI.MobilenetSsd.GetConfig(blobFile, blobFileConfig);
            String configStr = JsonConvert.SerializeObject(config);

            String[] labels = ReadLabels(blobFileConfig);

            using (Emgu.CV.DepthAI.Device d = new Device(""))
            {
                //String[] availableStreams = d.GetAvailableStreams();
                using (CNNHostPipeline pipeline = d.CreatePipeline(configStr))
                {
                    while (_is_running)
                    {
                        using (NNetAndDataPackets packets = pipeline.GetAvailableNNetAndDataPackets(false))
                        {
                            HostDataPacket[] dataPackets = packets.HostDataPackets;
                            NNetPacket[]     nnetPackets = packets.NNetPackets;

                            for (int i = 0; i < dataPackets.Length; i++)
                            {
                                if (dataPackets[i].GetPreviewOut(_render))
                                {
                                    using (FrameMetadata fmeta = dataPackets[i].GetFrameMetadata())
                                    {
                                        if (i < nnetPackets.Length)
                                        {
                                            NNetPacket nnetPacket = nnetPackets[i];
                                            using (FrameMetadata meta = nnetPacket.GetFrameMetadata())
                                            {
                                                _mostRecentDetections = nnetPacket.Detections;
                                            }
                                        }

                                        if (_mostRecentDetections != null)
                                        {
                                            for (int j = 0; j < _mostRecentDetections.Length; j++)
                                            {
                                                DrawDetection(_mostRecentDetections[j], _render, labels);
                                            }
                                        }

                                        CvInvoke.Imshow(win1, _render); //Show the image
                                    }
                                }
                                else
                                {
                                }
                            }
                        }

                        if (CvInvoke.WaitKey(1) > 0) //Press any key to stop
                        {
                            _is_running = false;
                        }
                    }
                }
            }


            CvInvoke.DestroyAllWindows(); //Destroy all windows if key is pressed
        }