imgproc::cornerSubPix_10() caught cv::Exception: OpenCV(4.6.0) /home/ci/opencv/modules/imgproc/src/cornersubpix.cpp:66: error: (-215:Assertion failed) src.channels() == 1 in function 'cornerSubPix'
在Android 中集成OpenCV 4.6,采用官方相机标定的示例后获取的相机内参中fx fy值特别大
参考C++代码中看到在findchessboardCorners后,使用灰度图像进行了亚像素角点的提取,调用了cornerSubPix函数,但是在Android中使用cornerSubPix时,总是异常退出,我的代码是这样子的:
Mat imageMat = new Mat();
Utils.bitmapToMat(imageBmp, imageMat);
Mat grayMat = new Mat();
Imgproc.cvtColor(imageMat, grayMat, Imgcodecs.IMREAD_GRAYSCALE);
// 获取角点信息
MatOfPoint2f mCorners = new MatOfPoint2f();
boolean mPatternWasFound = Calib3d.findChessboardCorners(grayMat, mPatternSize,
mCorners, Calib3d.CALIB_CB_ASYMMETRIC_GRID | Calib3d.CALIB_CB_CLUSTERING);
LogUtil.i(TAG, "find chess board corners result = " + mPatternWasFound);
LogUtil.i(TAG, "corners = " + mCorners.dump());
// 添加角点信息
if (mPatternWasFound) {
validImageNum ++;
// 进一步提取亚像素角点 , cornerSubPix 会异常退出
TermCriteria criteria = new TermCriteria(TermCriteria.MAX_ITER | TermCriteria.EPS, 30, 0.1);
Imgproc.cornerSubPix(grayMat, mCorners, new Size(11, 11), new Size(-1, -1), criteria);
LogUtil.i(TAG, "new corners = " + mCorners.dump());
mCornersBuffer.add(mCorners.clone());
}
总是在Imgproc.cornerSubPix处异常退出,退出信息如下:
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.6.0) /home/ci/opencv/modules/imgproc/src/cornersubpix.cpp:66: error: (-215:Assertion failed) src.channels() == 1 in function 'cornerSubPix' ]
at org.opencv.imgproc.Imgproc.cornerSubPix_0(Native Method)
at org.opencv.imgproc.Imgproc.cornerSubPix(Imgproc.java:2635)
求大家给予解答,万分感谢!!