Skip to content

Crush when calling stereoRectify. bug ? #1802

@arvisio

Description

@arvisio

Hello,
I get an error when calling stereoRectify:

I study works on dynamic projection.
In particular procamalib and procamtracker.

I received a calibration file through procamcalib and copied it into the procamtracker.
When I start tracking I get that error.

I also tried using the camera-projector.yaml from the PapART project, same bad result.

I found that the reason is in the stereoRectify call:
-MainFrame trackingWorker.execute()
----TrackingWorker.doInBackground
--------new ReflectanceInitializer
------------projectorDevice.getRectifyingHomography
-----------------stereoRectify < exception

java.lang.RuntimeException: OpenCV(4.5.5) D:\a\javacpp-presets\javacpp-presets\opencv\cppbuild\windows-x86_64\opencv-4.5.5\modules\calib3d\src\undistort.dispatch.cpp:416: error: (-215:Assertion failed) CV_IS_MAT(_distCoeffs) && (_distCoeffs->rows == 1 || _distCoeffs->cols == 1) && (_distCoeffs->rows*_distCoeffs->cols == 4 || _distCoeffs->rows*_distCoeffs->cols == 5 || _distCoeffs->rows*_distCoeffs->cols == 8 || _distCoeffs->rows*_distCoeffs->cols == 12 || _distCoeffs->rows*_distCoeffs->cols == 14) in function 'cvUndistortPointsInternal'

	at org.bytedeco.opencv.global.opencv_calib3d.stereoRectify(Native Method)

Herethe code to reproduce the error:

        //left
        
        Mat camera_matrixL = new Mat(3, 3, CvType.CV_64FC1);
        
        DoubleIndexer srcIdx = camera_matrixL.createIndexer();
        srcIdx.put(0, 0, new double[]{
           725.3432277010294,   0.0,   331.91235060120476,
		   0.0,   728.0987748056441,   202.35866017353592,
		   0.0,   0.0,   1.0
        });                        
        
        CvMat distL = CvMat.create(1, 4, CvType.CV_64FC1);
        distL.put( 0.013108245708010578,   -0.09888522377388584,   -0.010077014999011482,   7.506298741617942E-4);
        
        
        //right
        Mat camera_matrixR = new Mat(3, 3, CvType.CV_64FC1);
        DoubleIndexer srcIdx2 = camera_matrixR.createIndexer();
        srcIdx2.put(0, 0, new double[]{
           1940.4781847943073,   0.0,   705.2767131913546,
		   0.0,   1746.0863675456435,   761.9744425794147,
		   0.0,   0.0,   1.0
        });
          
        CvMat distR = CvMat.create(1, 4, CvType.CV_64FC1);
        distR.put(0.0610552152371495,   -0.16205979414801663,   -0.0028666292947557306,   0.001669682933892569);
        
		
        Mat T = new Mat(3, 1, CvType.CV_64FC1);
        DoubleIndexer tValues = T.createIndexer();
        
        tValues.put(0, 0, new double[]{
           -72.9761951228808,
		   -2.1459919519516935,
		   -47.133400408948305
        });
                
        Mat R = new Mat(3, 3, CvType.CV_64FC1);
        DoubleIndexer rValues = R.createIndexer();
        
        rValues.put(0, 0, new double[]{
           0.998994700701929,   0.04283205403325078,   0.01322887435710044,
		   -0.03679788980716183,   0.9520563182488666,   -0.303701633496023,
		   -0.02560279819088608,   0.30290952779618113,   0.952675345904937
        });
        
        Mat R1 = new Mat(3, 3, CvType.CV_64FC1);
        Mat R2 = new Mat(3, 3, CvType.CV_64FC1);
        
        Mat P1 = new Mat(3, 4, CvType.CV_64FC1);
        Mat P2 = new Mat(3, 4, CvType.CV_64FC1);       

        stereoRectify(
                camera_matrixL, cvarrToMat(distL), 
                camera_matrixR, cvarrToMat(distR),
                new Size(320, 240), 
                R, T, 
                R1, R2, P1, P2, 
                new Mat(), 0, -1, new Size(), null, null);

I am expecting the result:

R1: 
[0.824128291367248, 0.2237730892907117, 0.5203250559769267;
 -0.1439411194838274, 0.9712321753526361, -0.1897077111809877;
 -0.5478079166001923, 0.08144732082197473, 0.8326300621771228]
R2: 
[0.8397677716164732, 0.0246948320114914, 0.542383863169091;
 -0.1047061660396974, 0.9875790002570115, 0.1171509156798576;
 -0.5327538911613602, -0.1551704982375387, 0.8319227175219726]
P1: 
[0, 0, 0, 0;
 0, 0, 0, 0;
 0, 0, 0, 0]
P2: 
[0, 0, 0, 0;
 0, 0, 0, 0;
 0, 0, 0, 0]

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions