getting error while using findFundamentalMat in android opencv and not able to resolve it

1k views Asked by At

i am capturing the continuous images and extracting the fast features and further matching these features to get the get the Rotational and translation matrix. that will help me in 3d scene reconstruction but getting error when i am using Calib3d.findFundamentalMat command and not able to resolve it.

            MatOfDMatch matches = new MatOfDMatch();
            descriptorM.match(firstImgDescriptors, secondImgDescriptors, matches);

           Calib3d calib = new Calib3d();
           MatOfPoint2f imgpts1 = getMatOfPoint2fFromDMatches(matches, keyPoints1, 0);
           MatOfPoint2f imgpts2 = getMatOfPoint2fFromDMatches(matches, keyPoints2, 1);
           Mat F = Calib3d.findFundamentalMat(imgpts1, imgpts2, Calib3d.FM_RANSAC,3, 0.99);


     private static MatOfPoint2f getMatOfPoint2fFromDMatches(MatOfDMatch matches,
                                                         MatOfKeyPoint keyP, int tipo) {
            /* 0 para query, 1 para train*/
            DMatch dm[] = matches.toArray();
            List<Point> lp = new ArrayList<Point>(dm.length);
            KeyPoint tkp[] = keyP.toArray();
            if(tipo == 0){
                for (int i = 0; i < dm.length; i++) {
                    DMatch dmm = dm[i];
                    //if (dmm.queryIdx < tkp.length)
                        lp.add(tkp[dmm.queryIdx].pt);
                }
            }
            if (tipo == 1) {
                for (int i = 0; i < dm.length; i++) {
                    DMatch dmm = dm[i];
                  //  if (dmm.trainIdx < tkp.length)
                        lp.add(tkp[dmm.trainIdx].pt);
                }
            }

            return new MatOfPoint2f(lp.toArray(new Point[0]));
        }




    the Logcat window show the following error

    E/cv::error(): OpenCV Error: Bad argument (The input arrays should be 2D or 3D point sets) in cv::Mat cv::findFundamentalMat(cv::InputArray, cv::InputArray, int, double, double, cv::OutputArray), file /Volumes/Linux/builds/master_pack-android/opencv/modules/calib3d/src/fundam.cpp, line 724
    09-11 15:29:04.578 13625-13625/io.rpng.calibration E/org.opencv.calib3d: calib3d::findFundamentalMat_11() caught cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/calib3d/src/fundam.cpp:724: error: (-5) The input arrays should be 2D or 3D point sets in function cv::Mat cv::findFundamentalMat(cv::InputArray, cv::InputArray, int, double, double, cv::OutputArray)
    09-11 15:29:04.579 13625-13625/io.rpng.calibration D/AndroidRuntime: Shutting down VM
    09-11 15:29:04.588 13625-13625/io.rpng.calibration E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: io.rpng.calibration, PID: 13625
                                                                         CvException [org.opencv.core.CvException: cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/calib3d/src/fundam.cpp:724: error: (-5) The input arrays should be 2D or 3D point sets in function cv::Mat cv::findFundamentalMat(cv::InputArray, cv::InputArray, int, double, double, cv::OutputArray)
                                                                         ]
                                                                             at org.opencv.calib3d.Calib3d.findFundamentalMat_1(Native Method)
                                                                             at org.opencv.calib3d.Calib3d.findFundamentalMat(Calib3d.java:153)
                                                                             at com.pradeep.calibration.activities.MainActivity$5.onImageAvailable(MainActivity.java:529)
                                                                             at android.media.ImageReader$ListenerHandler.handleMessage(ImageReader.java:648)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:111)
                                                                             at android.os.Looper.loop(Looper.java:207)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5769)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
1

There are 1 answers

0
Dave Durbin On

The error is telling you that your imgpoints1 and/or imgpoints2 are not proper 2D or 3D point matrices.

Try printing the dimensions of these directly before calling Calib3d.findFundamentalMat(...)