简体   繁体   English

如何在 Emgu CV 中执行模板匹配

[英]How to perform to Template Matching in Emgu CV

Sir,先生,

I am new to Emgu CV.I am making a face recognition software.I was able to detect the faces using HaarCascade xml Classifiers.But im stuck up at the next step regarding how to recognise the face.Anyone please tell me how to use MatchTemplate function...我是 Emgu CV 的新手。我正在制作人脸识别软件。我能够使用 HaarCascade xml 分类器检测人脸。但我坚持下一步如何识别人脸。请告诉我如何使用 MatchTemplate function...

I found this code on the internet我在网上找到了这段代码

Image<Gray, Byte> templateImage = new Image<Gray, Byte>(bmpSnip);
Image<Gray, float> resultImage = sourceImage.MatchTemplate(templateImage,Emgu.CV.CvEnum.TM_TYPE.CV_TM_CCOEFF_NORMED);

float[,,] matches = resultImage.Data;
for (int x = 0; x < matches.GetLength(1); x++)
{
for (int y = 0; y < matches.GetLength(0); y++)
{
double matchScore = matches[y, x, 0];
if (matchScore > 0.75)
{
Rectangle rect = new Rectangle(new Point(x,y), new Size(1, 1));
imgSource.Draw(rect, new Bgr(Color.Blue), 1);
}
}

I didnt understand this code...First of all this code is not working....Secondly if anyone know how to do it correctly... Please post the code.....我不明白这段代码......首先,这段代码不起作用......其次,如果有人知道如何正确地做......请发布代码......

The MatchTemplate method is designed preliminary for matching objects with defining features. MatchTemplate 方法最初设计用于匹配具有定义特征的对象。 A face, while to you and I may have defining features to the FFT method employed in MatchTemplate the defining features are simply not large enough for face recognition.一张脸,而对于您和我来说,可能对 MatchTemplate 中使用的 FFT 方法具有定义特征,但定义特征根本不足以进行人脸识别。 Surya is correct as a comparison would be interesting and I would suggest the best approach would to be match areas of the template face image to the recognised face from the camera. Surya 是正确的,因为比较会很有趣,我建议最好的方法是将模板面部图像的区域与相机识别的面部进行匹配。 So for example you would take the the position of the eyes and apply MatchTemplate to the same location and take an average of matching these features to estimate overall accuracy.因此,例如,您将使用眼睛的 position 并将 MatchTemplate 应用到同一位置,然后对这些特征进行匹配以估计整体准确度。

The significant problem you will inherently have however is execution time.但是,您固有的重大问题是执行时间。 With a large database of faces MatchTemplate does not reduce the dataset significantly to allow real time processing.使用大型人脸数据库,MatchTemplate 不会显着减少数据集以允许实时处理。

The Eigen Recogniser is a far safer and efficient method.特征识别器是一种更安全、更有效的方法。 It will be more reliable than creating your own algorithm and significantly faster.它比创建自己的算法更可靠,速度也更快。 Please see my article here on how to implement it:请在此处查看我的文章,了解如何实现它:

http://www.codeproject.com/Articles/261550/EMGU-Multiple-Face-Recognition-using-PCA-and-Paral http://www.codeproject.com/Articles/261550/EMGU-Multiple-Face-Recognition-using-PCA-and-Paral

Hope this helps,希望这可以帮助,

Cheers,干杯,

Chris克里斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM