示例#1
0
        public string resim_tani(Image <Bgr, byte> resim)
        {
            Emgu.CV.Dnn.Importer caffe = Emgu.CV.Dnn.Importer.CreateCaffeImporter("Text.prototxt", "Model.caffemodel");
            Emgu.CV.Dnn.Net      net   = new Emgu.CV.Dnn.Net();


            caffe.PopulateNet(net);

            Mat prob;
            Mat resim_Mat = resim.Mat;

            Size      size   = new Size(224, 224);
            MCvScalar scalar = new MCvScalar(104, 117, 123);
            Mat       blob   = Emgu.CV.Dnn.DnnInvoke.BlobFromImage(resim_Mat, 0.78, size, scalar, true);

            net.SetInput(blob, "data");
            prob = net.Forward("prob");
            //   var asd = net.Forward("detection_out");
            //  var asd = net.Forward("concat");

            int    classId   = 0;
            double classProb = 0;

            getMaxClass(ref prob, ref classId, ref classProb);

            var classNames = readClassNames("synset_words.txt");

            var bestClass = classNames[classId];

            Console.WriteLine("Best: id:" + classId + ", val: " + bestClass);
            Console.WriteLine("Prob: " + classProb * 100 + "%");

            return(bestClass);
        }
示例#2
0
        public string clsImg(Image <Bgr, byte> img)
        {
            Emgu.CV.Dnn.Importer caffe = Emgu.CV.Dnn.Importer.CreateCaffeImporter("Text.prototxt", "Model.caffemodel");
            Emgu.CV.Dnn.Net      net   = new Emgu.CV.Dnn.Net();
            caffe.PopulateNet(net);

            //Emgu.CV.Dnn.Net net = Emgu.CV.Dnn.DnnInvoke.ReadNetFromCaffe("Text.prototxt", "Model.caffemodel");
            //THIS COMMAND CAN BE USED FOR THREE LINES AT THE TOP. For Emgucv 3.4.3 or later versions. Thanks to JacobC. for this statement.

            Mat prob;
            Mat img_Mat = img.Mat;

            Size      size   = new Size(224, 224);
            MCvScalar scalar = new MCvScalar(104, 117, 123);
            Mat       blob   = Emgu.CV.Dnn.DnnInvoke.BlobFromImage(img_Mat, 0.78, size, scalar, true);

            net.SetInput(blob, "data");
            prob = net.Forward("prob");
            // var detection_ou = net.Forward("detection_out");
            // var concat = net.Forward("concat");

            int    classId   = 0;
            double classProb = 0;

            getMaxClass(ref prob, ref classId, ref classProb);

            var classNames = readClassNames("synset_words.txt");

            var bestClass = classNames[classId];

            Console.WriteLine("Best: id:" + classId + ", val: " + bestClass);
            Console.WriteLine("Prob: " + classProb * 100 + "%");

            return(bestClass);
        }