Log in or register to post comments

Vuforia Matrix to opencv X Y value

July 21, 2016 - 1:03am #1

Hi :) First I am poor at speaking English. 

 

My scenario is     Four FrameMarker edge get ModelViewMatrix ->  screen capture and make BitMap

                               -> BitMap to Mat , Warping use Marker edge location -> save warping img-> lol 

 

opencv Warping function need Point(x,y) , but I don't know vuforia Matrix -> opencv X, Y value

 

ModelViewMatrix[12],[13] Can not be used opencv  

 

Because of opencv start Left Top (0,0) but vuforia start center (0,0) and opencv read the resolution of bitmap to 1920x1080.

but vuforia recorded resolution, the resolution of bitmap constantly chainge by distance.

So i wonder to find both opencv and vuforia ratio and calibrate Matrix values.

 

Wating you are advice !

 

this is My code .   code base vuforia sample FrameMarkerRenderer.java

 

void renderFrame()

 {

            ....

            switch (marker.getMarkerId())
            {
                case 0:
                    vertices = qObject.getVertices();
                    normals = qObject.getNormals();
                    indices = qObject.getIndices();
                    texCoords = qObject.getTexCoords();
                    numIndices = qObject.getNumObjectIndex();

                    Matrix.translateM(modelViewMatrix, 0, kLetterTranslate,
                            -kLetterTranslate, 0.f);
                   Matrix.scaleM(modelViewMatrix, 0, kLetterScale/4, kLetterScale/4,
                        kLetterScale/4);
                    Matrix.multiplyMM(modelViewProjection, 0, vuforiaAppSession
                            .getProjectionMatrix().getData(), 0, modelViewMatrix, 0);
                    PQ=new Point((double)modelViewMatrix[12],(double)modelViewMatrix[13]);
                    Q=true;
                    break;

....

              }

.....

}

Screen Capture code use this

https://developer.vuforia.com/library//articles/Solution/How-To-Capture-the-AR-View-on-Android

 

public Bitmap warping(Bitmap bmp) 
    {

        Mat input = new Mat(bmp.getWidth(),bmp.getHeight(),CvType.CV_32FC2);
        Utils.bitmapToMat(bmp,input);
       //Bmp -> Mat
        SystemClock.sleep(3000);
   

        Point ocvin1= new Point(PA.x,PA.y); // Marker Edge
        Point ocvin2= new Point(PQ.x,PQ.y);
        Point ocvin3= new Point(PC.x,PC.y);
        Point ocvin4= new Point(PR.x,PR.y);

 

        List<Point> source = new ArrayList<Point>();
        source.add(ocvin1);
        source.add(ocvin2);
        source.add(ocvin3);
        source.add(ocvin4);


        Mat startM = Converters.vector_Point2f_to_Mat(source);

        Point ocvout1= new Point(0,0);
        Point ocvout2= new Point(1080,0);
        Point ocvout3= new Point(1080,1920);
        Point ocvout4= new Point(0,1920);

        List<Point> dest = new ArrayList<Point>();
        dest.add(ocvout1);
        dest.add(ocvout2);
        dest.add(ocvout3);
        dest.add(ocvout4);

        Mat endM = Converters.vector_Point2f_to_Mat(dest);



        try {
            Mat perspectiveTransform = Imgproc.getPerspectiveTransform(startM, endM);
            //perspectiveTransform

            Mat output = new Mat(1080, 1920, CvType.CV_32FC2);
    

            Imgproc.warpPerspective(input, output, perspectiveTransform, new org.opencv.core.Size(1080, 1920));
            //Warping

        
            Bitmap out = Bitmap.createBitmap(1080,1920, Bitmap.Config.ARGB_8888);
            Utils.matToBitmap(output, out);

            SystemClock.sleep(3000);

            //crate Bitmap Mat -> Bitmap */

            return out;
        }

AttachmentSize
Image icon 20160720_135338.jpg2.62 MB
Image icon image.png998.39 KB
Log in or register to post comments