2

私は javacv Face Detection/Recognition コードに従っていますが、顔認識に関して混乱があります..

1) 顔のクロップを検出し、sdcard に保存し、learn.txt ファイルにパスを配置します (学習部分)

2) Detect Face クロップし、存在するかどうかにかかわらず、既存の顔でそれを見つけますが、サンプルの顔に顔が存在しなくても、常に最も近い位置を返します..

私が間違っていることは何ですか?

// 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

編集自信は常に否定的です!

前もって感謝します

4

0 に答える 0