Use MATLAB cameraParams in OpenCV program -
Use MATLAB cameraParams in OpenCV program -
i have matlab programme loads 2 images , returns 2 photographic camera matrices , cameraparams object distortion coefficients, etc. utilize exact configuration undistort points , on, in opencv programme triangulates points given 2d locations in 2 different videos.
function [cameramatrix1, cameramatrix2, cameraparams] = setupcameracalibration(leftimagefile, rightimagefile, squaresize) % auto-generated cameracalibrator app on 20-feb-2015
the thing is, output of undistortpoints different in matlab , opencv though both utilize same arguments.
as example:
>> undistortpoints([485, 502], defaultcameraparams) ans = 485 502
in java, next test mimics above (it passes).
public void testundistortpoints() { mat srcmat = new mat(2, 1, cvtype.cv_32fc2); mat dstmat = new mat(2, 1, cvtype.cv_32fc2); srcmat.put(0, 0, new float[] { 485, 502 } ); matofpoint2f src = new matofpoint2f(srcmat); matofpoint2f dst = new matofpoint2f(dstmat); mat defaultcameramatrix = mat.eye(3, 3, cvtype.cv_32f); mat defaultdistcoefficientmatrix = new mat(1, 4, cvtype.cv_32f); imgproc.undistortpoints( src, dst, defaultcameramatrix, defaultdistcoefficientmatrix ); system.out.println(dst.dump()); assertequals(dst.get(0, 0)[0], 485d); assertequals(dst.get(0, 0)[1], 502d); }
however, alter first distortion coefficient (k1). in matlab:
changeddist = cameraparameters('radialdistortion', [2 0 0]) >> undistortpoints([485, 502], changeddist) ans = 4.8756 5.0465
in java:
public void testundistortpointschangeddistortion() { mat srcmat = new mat(2, 1, cvtype.cv_32fc2); mat dstmat = new mat(2, 1, cvtype.cv_32fc2); srcmat.put(0, 0, new float[] { 485, 502 } ); matofpoint2f src = new matofpoint2f(srcmat); matofpoint2f dst = new matofpoint2f(dstmat); mat defaultcameramatrix = mat.eye(3, 3, cvtype.cv_32f); mat distcoefficientmatrix = new mat(1, 4, cvtype.cv_32f); distcoefficientmatrix.put(0, 0, 2f); // updated imgproc.undistortpoints( src, dst, defaultcameramatrix, distcoefficientmatrix ); system.out.println(dst.dump()); assertequals(4.8756, dst.get(0, 0)[0]); assertequals(5.0465, dst.get(0, 0)[1]); }
it fails next output:
[0.0004977131, 0.0005151587] junit.framework.assertionfailederror: expected :4.8756 actual :4.977131029590964e-4
why results different? thought java's distortion coefficient matrix includes both radial , tangential distortion coefficients.
also, cv_64fc1 selection of type photographic camera / distortion coefficient matrices?
i trying test effect of changing photographic camera matrix (i.e. value of f_x), it's not possible set 'intrinsicmatrix' parameter when using cameraparams, want solve distortion matrix problem first.
any help appreciated.
there couple of things have take business relationship when working calibration models.
first, note there exist several photographic camera calibration , distortion models: tsai, atan, pinhole, ocam. assume want utilize pinhole model, used opencv , mutual one. models 2 6 parameters radial distortion (denoted k1
...k6
) , 2 tangential distortion (denoted p1
, p2
), can read in opencv doc. bouget's calibration toolbox matlab uses model too.
second, there not standardized way arrange distortion parameters in vector. opencv expects items in order: [k1 k2 p1 p2 k3...k6]
, beingness k3...k6
optional.
so, check documentation of matlab calibration software , model uses , in order parameters arranged. then, create sure meets order in opencv.
the calibration parameters opencv ok cv_32f
, cv_64f
recall.
update
i don't know in java, in c++, when create mat
, initial values unspecified, code may creating matrix 2f
in first item , garbage in remaining ones:
mat distcoefficientmatrix = new mat(1, 4, cvtype.cv_32f); distcoefficientmatrix.put(0, 0, 2f);
could check if problem?
a note future, create things trickier, take business relationship intrinsic calibration matrix in opencv transpose of 1 in matlab.
matlab opencv matlab-cvst calibration
Comments
Post a Comment