OpenCV: cvPosit berechnet falsche Werte



  • Hallo zusammen,

    ich habe ein Problem mit cvPosit().
    Ich möchte damit die Orientierung eines Gesichts berechnen. Dazu habe ich beispielhaft mal dieses Bild hier:
    http://s1.directupload.net/images/121005/en7u2vhf.jpg

    Die 5 weißen Punkte sind meine KeyPoints, deren Pixelkoordinaten ich von außerhalb bekomme. Augen und Mundwinkel liegen in einer Ebene, die Nase liegt natürlich nicht in dieser. Somit sollte die Vorraussetzung für POSIT (4 nichtkomplanare Punkte) erfüllt sein.

    Hier mein Code, der größtenteils aus dem POSIT-Tutorial stammt:

    int main()
        int depth = 40; //Nasenhoehe
        calculateHeadPosition(depth);
    }
    
    void HeadPosition::calculateHeadPosition(float depth)
    {
    
    //create the model points
    std::vector<CvPoint3D32f> modelPoints;
    modelPoints.push_back(cvPoint3D32f(  0.0f,   0.0f, 0.0f));  //Nose - (the first must be 0,0,0)
    modelPoints.push_back(cvPoint3D32f(-52.0f, -58.0f, depth)); //left eye
    modelPoints.push_back(cvPoint3D32f( 52.0f, -58.0f, depth)); //right eye
    modelPoints.push_back(cvPoint3D32f(-43.0f,  60.0f, depth)); //left mouth corner
    modelPoints.push_back(cvPoint3D32f( 43.0f,  60.0f, depth)); //right mouth corner
    
    //create the image points 
    std::vector<CvPoint2D32f> srcImagePoints;
    srcImagePoints.push_back( cvPoint2D32f( 256, 256) ); //hier sind die Pixelwerte fest kodiert, normal
    srcImagePoints.push_back( cvPoint2D32f( 205, 200) ); //bekomme ich sie, wie gesagt, übergeben
    srcImagePoints.push_back( cvPoint2D32f( 306, 200) );
    srcImagePoints.push_back( cvPoint2D32f( 216, 316) );
    srcImagePoints.push_back( cvPoint2D32f( 296, 316) );
    
    //create the POSIT object with the model points
    CvPOSITObject* positObject = cvCreatePOSITObject( &modelPoints[0], (int)modelPoints.size() );
    
    //calculate the orientation
    float* rotation_matrix = new float[9];
    float* translation_vector = new float[3];
    CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 100, 1.0e-4f);
    double FOCAL_LENGTH = 760.0;
    cvPOSIT( positObject, &srcImagePoints[0], FOCAL_LENGTH, criteria, rotation_matrix, translation_vector );
    
    //calculate rotation angles
    double beta  = atan2((double)(-rotation_matrix[2]), (double)(sqrt(pow(rotation_matrix[0], 2) + pow(rotation_matrix[3], 2))));
    double alpha = atan2((rotation_matrix[3]/cos(beta)),(rotation_matrix[0]/cos(beta)));
    double gamma = atan2((rotation_matrix[7]/cos(beta)),(rotation_matrix[8]/cos(beta)));
    
    //conversion and prints
    beta = beta * 180 / M_PI;
    alpha = alpha * 180 / M_PI;
    gamma = gamma * 180 / M_PI;
    printf("beta:  %f\t", beta);
    printf("alpha: %f\t", alpha);
    printf("gamma: %f\n", gamma);
    }
    

    Da das Bild eine Frontalansicht des Gesichts zeigt erwarte ich für die Rotationswinkel (0, 0, 0), ich bekomme aber immer ca. (-16, -5, -18).
    Woran liegt das?

    Für Hilfe und/oder einen Tipp bin ich sehr dankbar!

    Gruß



  • Hilfe, stehe gerade vor genau dem selben Problem. Hast du denn eine Antwort gefunden? Wäre schön wenn du sie hier posten könntest. Danke, mfg!


Anmelden zum Antworten