python/C++ 去畸变
鱼眼畸变
python
void cv::fisheye::undistortPoints(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray R = noArray(), InputArray P = noArray() ) Python: undistorted = cv.fisheye.undistortPoints( distorted, K, D[, undistorted[, R[, P]]] ) #include <opencv2/calib3d.hpp> Undistorts 2D points using fisheye model. Parameters distorted Array of object points, 1xN/Nx1 2-channel (or vector<Point2f> ), where N is the number of points in the view. K Camera intrinsic matrix cameramatrixK. D Input vector of distortion coefficients (k1,k2,k3,k4). R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel P New camera intrinsic matrix (3x3) or new projection matrix (3x4) undistorted Output array of image points, 1xN/Nx1 2-channel, or vector<Point2f> .
对于python中的 InputArray
输入点需要是一个形状为 的数组(n_points, 1, n_dimensions)
。所以如果你有 2D 坐标,它们应该在 shape 中 (n_points, 1, 2) 。或者对于 3D 坐标,它们应该在 shape 中 (n_points, 1, 3) 。对于大多数OpenCV 函数来说都是如此。AFAIK,这种格式适用于所有OpenCV 函数,而一些 OpenCV 函数也将接受形状中的点(n_points, n_dimensions)
。发现最好保持所有内容的一致性和格式(n_points, 1, n_dimensions)
。
需要明确的是,这意味着四个 32 位浮点 2D 点的数组将如下所示:
points = np.array([[[x1, y1]], [[x2, y2]], [[x3, y3]], [[x4, y4]]], dtype=np.float32)
可以使用 np.newaxis 将 (n_points, n_dimensions) 转换成 (n_points, 1, n_dimensions) :
>>> points = np.array([[1, 2], [3, 4], [5, 6], [7, 8]]) >>> points.shape (4, 2) >>> points = points[:, np.newaxis, :] >>> points.shape (4, 1, 2)