Calib3d.undistort - OpenCV(3.4.0-dev) Error: Assertion failed (distorted.type()

asked 2019-09-21 17:01:47 -0500

Hi,

I am a new user of OpenCV and I am trying to execute the example to Calibrate the Camera, but I am with a problem in this method:

@Override
public Mat render(CvCameraViewFrame inputFrame) {
    Mat undistortedFrame = new Mat(inputFrame.rgba().size(), inputFrame.rgba().type());
    Calib3d.undistort(inputFrame.rgba(), undistortedFrame,
            mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());

    Mat comparisonFrame = inputFrame.rgba();
    undistortedFrame.colRange(new Range(0, mWidth / 2)).copyTo(comparisonFrame.colRange(new Range(mWidth / 2, mWidth)));
    List<MatOfPoint> border = new ArrayList<MatOfPoint>();
    final int shift = (int)(mWidth * 0.005);
    border.add(new MatOfPoint(new Point(mWidth / 2 - shift, 0), new Point(mWidth / 2 + shift, 0),
            new Point(mWidth / 2 + shift, mHeight), new Point(mWidth / 2 - shift, mHeight)));
    Imgproc.fillPoly(comparisonFrame, border, new Scalar(255, 255, 255));

    Imgproc.putText(comparisonFrame, mResources.getString(R.string.original), new Point(mWidth * 0.1, mHeight * 0.1),
            Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 0));
    Imgproc.putText(comparisonFrame, mResources.getString(R.string.undistorted), new Point(mWidth * 0.6, mHeight * 0.1),
            Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 0));

    return comparisonFrame;
}

The problem is on the version (3.4.0), I don`t find this method Calib3d.undistort and because of this I already tried the methods undistortPoints and undistortImage, but in both of them the error bellow is showed:

 2019-09-21 18:27:51.030 12982-13108/com.example.camera_calibration E/cv::error(): OpenCV(3.4.0-dev) Error: Assertion failed (distorted.type() == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3)) || distorted.type() == (((6) & ((1 << 3) - 1)) + (((2)-1) << 3))) in void cv::fisheye::undistortPoints(cv::InputArray, cv::OutputArray, cv::InputArray, cv::InputArray, cv::InputArray, cv::InputArray), file ../../modules/calib3d/src/fisheye.cpp, line 324
2019-09-21 18:27:51.030 12982-12982/com.example.camera_calibration D/ViewRootImpl@3c0c3bc[PopupWindow:99a8389]: MSG_WINDOW_FOCUS_CHANGED 0 1
2019-09-21 18:27:51.030 12982-13108/com.example.camera_calibration E/org.opencv.calib3d: calib3d::undistortPoints_11() caught cv::Exception: OpenCV(3.4.0-dev) ../../modules/calib3d/src/fisheye.cpp:324: error: (-215) distorted.type() == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3)) || distorted.type() == (((6) & ((1 << 3) - 1)) + (((2)-1) << 3)) in function void cv::fisheye::undistortPoints(cv::InputArray, cv::OutputArray, cv::InputArray, cv::InputArray, cv::InputArray, cv::InputArray)
2019-09-21 18:27:51.031 12982-13108/com.example.camera_calibration E/AndroidRuntime: FATAL EXCEPTION: Thread-6
    Process: com.example.camera_calibration, PID: 12982
    CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.0-dev) ../../modules/calib3d/src/fisheye.cpp:324: error: (-215) distorted.type() == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3)) || distorted.type() == (((6) & ((1 << 3) - 1)) + (((2)-1) << 3)) in function void cv::fisheye::undistortPoints(cv::InputArray, cv::OutputArray, cv::InputArray, cv::InputArray, cv::InputArray, cv::InputArray)
    ]
        at org.opencv.calib3d.Calib3d.undistortPoints_1(Native Method)
        at org.opencv.calib3d.Calib3d.undistortPoints(Calib3d.java:1400)
        at com.example.camera_calibration.UndistortionFrameRender.render(OnCameraFrameRender.java:54)
        at com.example.camera_calibration.OnCameraFrameRender.render(OnCameraFrameRender.java:101)
        at com.example.camera_calibration.CameraCalibrationActivity.onCameraFrame(CameraCalibrationActivity.java:229)
        at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame ...
(more)
edit retag flag offensive close merge delete