使用javacv android进行人脸识别

时间:2013-01-29 10:31:57

标签: android javacv

我正在关注javacv人脸检测/识别代码,关于人脸识别存在困惑..我正在做的事情(抱歉,如果它听起来很愚蠢,但我被卡住了)

1)检测Face裁剪并将其保存到SD卡并将路径放在learn.txt文件中(学习部分)

2)检测面部裁剪并在现有面部中找到它是否存在,但即使面部在样本面中不存在,它也始终返回最近位置。

我做错了什么?

// Method, I'm using to recognize face

public Integer recognizeFace(Bitmap face, Context context) {
    Log.i(TAG, "===========================================");
    Log.i(TAG, "recognizeFace (single face)");


    float[] projectedTestFace;
    float confidence = 0.0f;
    int nearest = -1; // closest match -- -1 for nothing. 
    int iNearest;


    if (trainPersonNumMat == null) {
        return null;
    }

    Log.i(TAG, "NUMBER OF EIGENS: " + nEigens);
    // project the test images onto the PCA subspace
    projectedTestFace = new float[nEigens];
    // Start timing recognition
    long startTime = System.nanoTime();

    testFaceImg = bmpToIpl(face);
//  saveBmp(face, "blah");
    // convert Bitmap it IplImage
    //testFaceImg = IplImage.create(face.getWidth(), face.getHeight(),
    //      IPL_DEPTH_8U, 4);

    //face.copyPixelsToBuffer(testFaceImg.getByteBuffer());

    // project the test image onto the PCA subspace
    cvEigenDecomposite(testFaceImg, // obj
            nEigens, // nEigObjs
            new PointerPointer(eigenVectArr), // eigInput (Pointer)
            0, // ioFlags
            null, // userData
            pAvgTrainImg, // avg
            projectedTestFace); // coeffs

    // LOGGER.info("projectedTestFace\n" +
    // floatArrayToString(projectedTestFace));
    Log.i(TAG, "projectedTestFace\n" + floatArrayToString(projectedTestFace));

    final FloatPointer pConfidence = new FloatPointer(confidence);
    iNearest = findNearestNeighbor(projectedTestFace, new FloatPointer(pConfidence));
    confidence = pConfidence.get();
    // truth = personNumTruthMat.data_i().get(i);
    nearest = trainPersonNumMat.data_i().get(iNearest); // result

    // get endtime and calculate time recognition process takes
    long endTime = System.nanoTime();
    long duration = endTime - startTime;
    double seconds = (double) duration / 1000000000.0;
    Log.i(TAG, "recognition took: " + String.valueOf(seconds));

    Log.i(TAG, "nearest = " + nearest + ". Confidence = " + confidence);
    Toast.makeText(context, "Nearest: "+nearest+" Confidence: "+confidence, Toast.LENGTH_LONG).show();

    //Save the IplImage so we can see what it looks like
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "/sdcard/saved_images/" + nearest + " " + String.valueOf(seconds) + " " + String.valueOf(confidence) + " " + n + ".jpg";

    Log.i(TAG, "Saving image as: " + fname);

    cvSaveImage(fname, testFaceImg);


    return nearest;
} // end of recognizeFace

编辑信心永远是负面的!

提前致谢

0 个答案:

没有答案
相关问题