opencv-undistort

opencv-undistort

官方文档

在这里插入图片描述
根据介绍不难理解此函数主要对图像进行畸变校正,newCameraMatrix作为输入参数主要用来控制输出图像的缩放的,由于畸常常会使一部分像素超出/缩进原尺寸,有时为了看到畸变全貌需要设置改参数,可以很方便使用cv::getOptimalNewCameraMatrix函数来设置该参数。

小例程

cv::Mat distort_img = cv::imread("..\\data\\undistort_image.jpg", 1);
cv::Mat cam_mat, dist_mat;
read_cam_param("..\\data\\undistort_image.camparam", cam_mat, dist_mat);
cv::Mat undistort_img, map1, map2;
//cv::initUndistortRectifyMap(cam_mat, dist_mat.t(), cv::Mat(), cv::getOptimalNewCameraMatrix(cam_mat, dist_mat, distort_img.size(), 1, distort_img.size(), 0),
//    distort_img.size(), CV_16SC2, map1, map2);
//cv::remap(distort_img, undistort_img, map1, map2, cv::INTER_LINEAR);
cv::und
  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
柱面变换是一种将图像从平面投影变换到柱面表面的方法。在计算机视觉中,柱面变换可以用于纠正摄像机的透视畸变,使图像保持水平和垂直线条的正确性。 在 OpenCV 中,可以使用 cv2.remap() 函数进行柱面变换。该函数需要两个输入参数:源图像和一个变换矩阵。变换矩阵可以通过 cv2.getOptimalNewCameraMatrix() 函数计算得出。 下面是一个简单的柱面变换示例: ``` python import cv2 import numpy as np img = cv2.imread('image.jpg') h, w = img.shape[:2] # 计算变换矩阵 f = 500 # 摄像机的焦距 K = np.array([[f, 0, w/2], [0, f, h/2], [0, 0, 1]]) # 内参矩阵 R = np.eye(3) # 旋转矩阵 t = np.array([0, 0, 0]) # 平移向量 new_K, roi = cv2.getOptimalNewCameraMatrix(K, np.eye(3), (w, h), 1, (w, h)) # 计算映射 map_x, map_y = cv2.initUndistortRectifyMap(K, np.eye(3), None, new_K, (w, h), cv2.CV_32FC1) # 进行柱面变换 dst = cv2.remap(img, map_x, map_y, cv2.INTER_LINEAR) cv2.imshow('original', img) cv2.imshow('cylindrical', dst) cv2.waitKey(0) cv2.destroyAllWindows() ``` 在上面的代码中,我们首先读取了一张图像,然后计算了变换矩阵。接着,我们使用 cv2.initUndistortRectifyMap() 函数计算了映射表,最后使用 cv2.remap() 函数进行柱面变换。最终的结果显示在了两个窗口中:原始图像窗口和柱面变换后的图像窗口。 需要注意的是,柱面变换只能纠正摄像机的水平和垂直畸变,而无法纠正其它类型的畸变,比如径向畸变和切向畸变。如果需要纠正这些畸变,可以使用更高级的畸变纠正方法,比如 OpenCV 中的 cv2.undistort() 函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值