cv2.error: /home/michael/workspace/opencv-2.4.8/modules/imgproc/src/undistort.cpp:282: error: (-215) CV_IS_MAT(_cameraMatrix) && _cameraMatrix->rows == 3 && _cameraMatrix->cols == 3 in function cvUndistortPoints
K = np.array([[776.65250589, 0, 645.53907335],
[0, 770.65916345, 374.76352079],
[0.0,0.0, 1.0]], dtype = np.float64)
dist_coef = np.array([6.47285370e-02, -1.55334472e-01, -1.29510733e-03, 1.95433144e-05, 4.63095096e-02], dtype = np.float32)
cv2.undistortPoints(src, dst, K, dist_coef)
def undistort_point(pt, K, dist_coeffs):# see link for reference on the equationu, v = ptk1,k2,p1,p2, k3 = dist_coeffsu0 = K[0,2] # cxv0 = K[1,2] # cyfx = K[0,0]fy = K[1,1]_fx = 1.0/fx_fy = 1.0/fyy = (v - v0)*_fyx = (u - u0)*_fxr = np.sqrt(x**2 + y**2)u_undistort = (x * (1+ (k1*r**2) + (k2*r**4) + (k3*r**6))) + 2*p1*x*y + p2*(r**2 + 2*x**2)v_undistort = (y * (1+ (k1*r**2) + (k2*r**4) + (k3*r**6))) + 2*p2*y*x + p1*(r**2 + 2*y**2)x_undistort = fx*u_undistort+ u0y_undistort = fy*v_undistort+ v0return x_undistort[0], y_undistort[0](this may be this most helpful answer I have given so far in this forum :-) )best,Moritz
--
You received this message because you are subscribed to the Google Groups "pupil-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pupil-discus...@googlegroups.com.
To post to this group, send email to pupil-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pupil-discuss/fe32548a-1833-4d01-a34d-8f7b28a65d0f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
newCameraMatrix, _ = cv2.getOptimalNewCameraMatrix(self.K, self.dist_coef, fieldcam_res, 1, fieldcam_res, 0)
self.map1, self.map2 = cv2.initUndistortRectifyMap(self.K, self.dist_coef, np.identity(3), newCameraMatrix, fieldcam_res, cv2.CV_16SC2)
point = point.reshape(2)
res.append(self.map1[point[1]][point[0]])
initUndistortRectifyMap
returns map1 which contains the undistorted pixel position for each original pixel position. What map2 is good for I didn't find out till now...[[[ 950.83978271 290.43954468]]
[[ 950.43261719 345.45806885]]
[[ 1007.75939941 344.32891846]]
[[ 1008.68023682 288.5925293 ]]]
[[ 965 286]
[ 965 344]
[1025 343]
[1026 284]]
[[ 952.97440459 289.68448081]
[ 952.44679391 345.10943655]
[ 1010.41879156 343.88709266]
[ 1011.4226513 287.71192094]]
Seems that I didn't found a solution yet... any ideas?
Kind regards,
Michael
The function actually builds the maps for the inverse mapping algorithm that is used by remap() . That is, for each pixelin the destination (corrected and rectified) image, the function computes the corresponding coordinates in the source image (that is, in the original image from camera).