Example #1
0
        /// <summary>
        /// Initiate the DNN model. If needed, it will download the model from internet.
        /// </summary>
        /// <returns>null if successful. Otherwise, it will return the error message</returns>
        private String InitDetector()
        {
            if (_maskRcnnDetector == null)
            {
                InitPath();

                String url =
                    "https://github.com/emgucv/models/raw/master/mask_rcnn_inception_v2_coco_2018_01_28/";

                String graphFile = "frozen_inference_graph.pb";
                try
                {
                    graphFile = DnnDownloadFile(url, graphFile, _path);
                }
                catch (Exception e)
                {
                    return(String.Format("Failed to download the file {0} from {1}: {2}", graphFile, url, e.Message));
                }


                String lookupFile = "coco-labels-paper.txt";
                try
                {
                    lookupFile = DnnDownloadFile(url, lookupFile, _path);
                }
                catch (Exception e)
                {
                    return(String.Format("Failed to download the file {0} from {1}: {2}", lookupFile, url, e.Message));
                }

                String url2       = "https://github.com/opencv/opencv_extra/raw/4.1.0/testdata/dnn/";
                String configFile = "mask_rcnn_inception_v2_coco_2018_01_28.pbtxt";
                try
                {
                    configFile = DnnDownloadFile(
                        url2,
                        configFile,
                        _path);
                }
                catch (Exception e)
                {
                    return(String.Format("Failed to download the file {0} from {1}: {2}", configFile, url2, e.Message));
                }

                _maskRcnnDetector = Emgu.CV.Dnn.DnnInvoke.ReadNetFromTensorflow(graphFile, configFile);


                //prefer cuda backend if available
                foreach (BackendTargetPair p in DnnInvoke.GetAvailableBackends())
                {
                    if (p.Backend == Dnn.Backend.Cuda && p.Target == Target.Cuda)
                    {
                        _maskRcnnDetector.SetPreferableBackend(Dnn.Backend.Cuda);
                        _maskRcnnDetector.SetPreferableTarget(Target.Cuda);
                        break;
                    }
                }

                //_maskRcnnDetector.SetPreferableBackend(Dnn.Backend.OpenCV);
                //_maskRcnnDetector.SetPreferableTarget(Dnn.Target.Cpu);

                _labels = File.ReadAllLines(lookupFile);
                _colors = new MCvScalar[_labels.Length];
                Random r = new Random(12345);
                for (int i = 0; i < _colors.Length; i++)
                {
                    _colors[i] = new MCvScalar(r.Next(256), r.Next(256), r.Next(256));
                }
            }

            return(null);
        }
Example #2
0
        public AboutPage()
        {
            String openclTxt = String.Format("Has OpenCL: {0}", CvInvoke.HaveOpenCL);

            String lineBreak = "<br/>";

            if (CvInvoke.HaveOpenCL)
            {
                openclTxt = String.Format("{0}{1}Use OpenCL: {2}{1}<textarea rows=\"5\">{3}</textarea>{1}",
                                          openclTxt, lineBreak,
                                          CvInvoke.UseOpenCL,
                                          CvInvoke.OclGetPlatformsSummary());
            }


            var           dnnBackends     = DnnInvoke.GetAvailableBackends();
            List <String> dnnBackendsText = new List <string>();

            foreach (var dnnBackend in dnnBackends)
            {
                dnnBackendsText.Add(String.Format("{0} - {1}", dnnBackend.Backend, dnnBackend.Target));
            }

            String dnnText = String.Join(";", dnnBackendsText.ToArray());


            String osDescription = Emgu.Util.Platform.OperationSystem.ToString();

            Content =
                new WebView()
            {
                WidthRequest  = 1000,
                HeightRequest = 1000,
                Source        = new HtmlWebViewSource()
                {
                    Html =
                        @"<html>
<head>
<style>body { background-color: #EEEEEE; }</style>
<style type=""text/css"">
textarea { width: 100%; margin: 0; padding: 0; border - width: 0; }
</style>
</head>
<body>
<H2> Emgu CV Examples </H2>
<a href=http://www.emgu.com>Visit our website</a> <br/><br/>
<a href=mailto:[email protected]>Email Support</a> <br/><br/>
<H4> OpenCL Info </H4>
" + openclTxt + @"
<H4> OS: </H4>
" + osDescription + @"
<H4> OS Architecture: </H4>
" + RuntimeInformation.OSArchitecture + @"
<H4> Framework Description: </H4>
" + RuntimeInformation.FrameworkDescription + @"
<H4> Process Architecture: </H4>
" + RuntimeInformation.ProcessArchitecture + @"
<H4> Dnn Backends: </H4>
" + dnnText + @"
<H4> Build Info </H4>
<textarea rows=""30"">"
                        + CvInvoke.BuildInformation + @"
</textarea>
</body>
</html>"
                }
            };
        }