How to get Confidence value in face recognition using EMGU CV?

回眸只為那壹抹淺笑 提交于 2019-12-04 11:31:59

There is no exact confidence value however there is a variable scale that can be used and roughly interpreted as such which is the Eigen Distance.

The value that classifies as a good match changes according to the amount of data you have and the training parameters so you will have to test the values with different faces to work out your threshold.

You will have to add a function to the Eigen class to obtain this value. First we will overwrite the EigenObjectRecognizer we use. This is really simple loacte the file EigenObjectRecognizer.cs, it is locates in the \EMGU Installation directory\Emgu.CV or where ever you extracted the files you should be able to lacate it as it's in the same folder as the bin folder with all the .dlls you use.

Add the file to you project by right clicking on the project name in the solution explorer in visual studion and selecting Add>Existing Item... Navigate to the file and add it. Your project will automatically use this rather than the one held with EMGU.CV.dll in your references.

Open the EigenObjectRecognizer.cs now in your project, don't worry it's a copy of the original so any change you make won't effect the original source. To start of with make things easier by holding the Ctrl the pressing the m key followed by the o key this will collapse all method fields.

To start of with we need to overwrite the namespace I called mine Emgu.Custom.

Now at the top of the code add the following variable underneath the others

private float eigenDistance;

Add the following method to class,

  /// <summary>
  /// Get the calculated Eignen Distance for the last proceessed frame
  /// </summary>
  public float GetEignenDistance
  {
      get { return eigenDistance; }
  }

You can place this anywhere you but obviously within the class and outside a method, now the important bit. We have made eigenDistance global but it's privately created when we call the .Recognize(Image image) method.

Find this method within EigenObjectRecognizer.cs and change

float eigenDistance;

to

eigenDistance = -1;

you could delete the float eigenDistance; line but I like to ensure it's overwritten with a value that I can observe for an error as it should always be positive if recognition has been applied correctly. You will notice that the following section of code includes:

FindMostSimilarObject(image, out index, out eigenDistance, out label);
  • index
  • eigenDistance
  • label

Are all outputs available for use with a little extra coding.

We no need to point our Eigen recognizer variable to the write one:

Emgu.Custom.EigenObjectRecognizer recognizer;

We can now obtain the EigenDistance with this function call:

float EigenDistance = recognizer.GetEignenDistance;

Hope this clears things up,

Cheers,

Chris

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!