Hi.
Working with a fisheye lens and want to undistort the picture. Did this plenty in Python before so I thought I just transfer the code. Turned out Matrix definition is not as simple, but I found a work-around. However, now all I get is an about half the size image (which comes from the halfed new matrix), but no correction for distortion. Maybe my matrices weren't correct after all. Here my code ("this" is a camera class that contains a frame):
double[] Kval=new double[]{369.8206061505334, 0.0, 653.979059378939, 0.0, 369.4813834030355, 375.6647592958235, 0.0, 0.0, 1.0};
double[] Dval=new double[]{-0.020327154188024447, -0.0034195654392881036, -2.6653078505195146e-05, -0.00010493184049784981};
Mat K=new Mat(new Size(3,3),0);
K.put(0,0,Kval);
Mat nk=K.clone();
Mat D=new Mat(new Size(4,1),0);
D.put(0,0,Dval);
nk.put(0,0,nk.get(0,0)[0]/2.0);
nk.put(1,1,nk.get(1,1)[0]/2.0);
Mat map1=new Mat();
Mat map2=new Mat();
Imgproc.initUndistortRectifyMap(K,D,Mat.eye(3,3,0), nk, new Size(frame.cols(),frame.rows()),CV_16SC2, map1,map2);
Imgproc.remap(this.frame,this.frame,map1,map2,Imgproc.INTER_LINEAR,BORDER_CONSTANT);