use calib3.findhomography OR solvePnP for augmented reality?

asked 2013-09-28 08:43:51 -0600

sara1010 gravatar image

hi,i use opencv for android.I want to implement the marker based augmented reality by using opencv.I have the bitmap of marker stored in sd card.my main part of code:

 List<DMatch> matches = new ArrayList<DMatch>();
    Log.d(TAG, "Match "+objectDesc.size()+" "+sceneDesc.size());
    matcher.match(objectDesc, sceneDesc, matches);

    Log.d(TAG, "Found "+matches.size()+" matches");

    double max_dist = 0;
    double min_dist = 100;


    for (int i = 0; i < objectDesc.rows(); i++) {
        double dist = matches.get(i).distance;
        if (dist < min_dist)
            min_dist = dist;
        if (dist > max_dist)
            max_dist = dist;
    }


    List<DMatch> matches_good = new ArrayList<DMatch>();

    for (int i = 0; i < objectDesc.rows(); i++) {
        if (matches.get(i).distance < 2 * min_dist) {
            matches_good.add(matches.get(i));
        }
    }

    List<Point> scene = new ArrayList<Point>();

     List<Point> objList = new LinkedList<Point>();
     List<Point> sceneList = new LinkedList<Point>();

    for (int i = 0; i < matches_good.size(); i++) {

        scene.add(sceneKeys.get(matches_good.get(i).trainIdx).pt);
        objList.add(sceneKeys.get(matches_good.get(i).queryIdx).pt);
        sceneList.add(sceneKeys.get(matches_good.get(i).trainIdx).pt);
    }




    Mat hg = Calib3d.findHomography(objList,sceneList);

now my question is what is hg matrix?can I use it in opengl to augment virtual object? I could calibrate my phone camera and get camera matrix and distortion coefficients.a person offer me use solvePNP function,this function takes as inputs the 3D coordinates, 2D coordinates, the camera matrix (focal distance and center of projection) and the distortion coefficients.but how can I get 2d and 3d coefficients?

edit retag flag offensive close merge delete