我正在捕获连续图像并提取快速特征并进一步匹配这些特征以获得旋转和 翻译矩阵。这将帮助我进行 3D 场景重建,但得到 当我使用 Calib3d.findFundamentalMat 命令时出现错误并且无法解决它。
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)
错误告诉您您的
imgpoints1
和/或 imgpoints2
不是正确的 2D 或 3D 点矩阵。
在调用之前尝试直接打印这些尺寸
Calib3d.findFundamentalMat(...)