1

谁能帮我解决我的问题?我似乎无法从互联网上得到任何答案。我整天都在寻找。所以这是我的问题。我正在使用 opencv4android 2.4.10 和 Android Studio 作为我的 IDE 创建一个人脸识别 android 应用程序。

我需要使用 FaceRecognition.predict(Mat src, int[] labels, double[] confidence) 来获取被检测到的人。但是我研究过的大多数教程只有 FaceRecognition.predict(Mat src) 我不确定从哪里获得 int[] 标签和 double[] 信心。如果有人能教我如何做到这一点,我将不胜感激。

示例代码:

File[] imageFiles = root.listFiles(imgFilter);

Mat labels = new Mat(imageFiles.length, 1, CvType.CV_32SC1);
List<Mat> images = (List<Mat>) new Mat(imageFiles.length);

int counter = 0;
int label;

//get all person id and images
for (File image : imageFiles) {
    Mat img = Highgui.imread(image.getAbsolutePath(), 0);
    images.add(counter, img);

    label = Integer.parseInt(image.getName().split("-")[0]);
    labels.put(counter, 0, label);

    counter++;
}
//I created a java wrapper for this method
//this works just fine.
FaceRecognizer facerec = new FisherFacesRecognizer();

facerec.train(images, labels);

//my problem is here, the parameters are supposed to be
//*Mat src, int[] labels, double[] confidence*
//but most tutorials only have *Mat src*
int predictedLabel = facerec.predict(grayImg);
4

1 回答 1

3

这两个函数本质上做同样的事情——返回识别的 id。

另一个重载另外将距离值返回到数据库中的最佳项目(更小==更好)。因为不能从 java(或 c++)中的函数返回超过 1 个值,所以这是通过引用传递完成的。所以要么使用:

   int predictedLabel = facerec.predict(grayImg);

或者,(如果你知道距离):

   int[] prediction = {0};
   double[] distance = {0};

   facerec.predict(grayImg, prediction, distance);

   int predictedLabel = prediction[0];
   double dist = distance[0];
于 2015-02-28T09:08:47.040 回答