当前位置: 首页>>代码示例>>C#>>正文


C# Mat.PushBack方法代码示例

本文整理汇总了C#中Mat.PushBack方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.PushBack方法的具体用法?C# Mat.PushBack怎么用?C# Mat.PushBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mat的用法示例。


在下文中一共展示了Mat.PushBack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: computeAndExtract

        public void computeAndExtract()
        {
            using (detector = new SURF(30))
            using (matcher = new BFMatcher(DistanceType.L2))
            {
                bowDE = new BOWImgDescriptorExtractor(detector, matcher);
                BOWKMeansTrainer bowTrainer = new BOWKMeansTrainer(100, new MCvTermCriteria(100, 0.01), 3, Emgu.CV.CvEnum.KMeansInitType.PPCenters);

                foreach(FileInfo[] folder in _folders)
                    foreach (FileInfo file in folder)
                    {
                        using (Image<Bgr, Byte> model = new Image<Bgr, byte>(file.FullName))
                        using (VectorOfKeyPoint modelKeyPoints = new VectorOfKeyPoint())
                        //Detect SURF key points from images
                        {
                            detector.DetectRaw(model, modelKeyPoints);
                            //Compute detected SURF key points & extract modelDescriptors
                            Mat modelDescriptors = new Mat();
                            detector.Compute(model, modelKeyPoints, modelDescriptors);
                            //Add the extracted BoW modelDescriptors into BOW trainer
                            bowTrainer.Add(modelDescriptors);
                        }
                        input_num++;
                    }

                //Cluster the feature vectors
                bowTrainer.Cluster(vocabulary);

                //Store the vocabulary
                bowDE.SetVocabulary(vocabulary);

                //training descriptors
                tDescriptors = new Mat();

                labels = new Matrix<int>(1, input_num);
                int index = 0;
                //compute and store BOWDescriptors and set labels
                for (int i = 1; i <= _folders.Count; i++)
                {
                    FileInfo[] files = _folders[i-1];
                    for (int j = 0; j < files.Length; j++)
                    {
                        FileInfo file = files[j];
                        using (Image<Bgr, Byte> model = new Image<Bgr, Byte>(file.FullName))
                        using (VectorOfKeyPoint modelKeyPoints = new VectorOfKeyPoint())
                        using (Mat modelBOWDescriptor = new Mat())
                        {
                            detector.DetectRaw(model, modelKeyPoints);
                            bowDE.Compute(model, modelKeyPoints, modelBOWDescriptor);

                            tDescriptors.PushBack(modelBOWDescriptor);
                            labels[0, index++] = i;

                        }
                    }
                }
            }
        }
开发者ID:Ragnar87,项目名称:TrackingAndClassifying,代码行数:58,代码来源:Classifier.cs

示例2: TrainData

        public CvKNearest TrainData(IList<ImageInfo> trainingImages)
        {
            var samples = new Mat();
            foreach (var trainingImage in trainingImages)
            {
                samples.PushBack(trainingImage.Image);
            }

            var labels = trainingImages.Select(x => x.ImageGroupId).ToArray();
            var responses = new Mat(labels.Length, 1, MatType.CV_32SC1, labels);
            var tmp = responses.Reshape(1, 1); //make continuous
            var responseFloat = new Mat();
            tmp.ConvertTo(responseFloat, MatType.CV_32FC1); // Convert  to float

            var kNearest = new CvKNearest();
            kNearest.Train(samples, responseFloat); // Train with sample and responses
            return kNearest;
        }
开发者ID:kauser-cse-buet,项目名称:OpenCVSharp-Samples,代码行数:18,代码来源:SimpleOCR.cs


注:本文中的Mat.PushBack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。