本文整理汇总了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;
}
}
}
}
}
示例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;
}