畸变:桶形畸变和枕形畸变

畸变:畸变的本质是光学系统在不同视场由于镜头屈光度与光阑位置不同引起像高放大率不同导致的
分为桶型畸变和枕型畸变。
在这里插入图片描述
桶形畸变又称桶形失真,它是由镜头引起的成像画面呈桶形膨胀状的失真现象。桶形畸变虽然不影响成像清晰度,但却影响成像的位置精度,这会给图像分析和图像测量带来误差,甚至是误判
在这里插入图片描述
这些都是Camera Tuning无法调试的

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
处理图像的畸变和桶畸变可以使用OpenCV库中的函数来实现。 下面是一个使用Qt和OpenCV库处理图像的畸变和桶畸变的示例代码: ```cpp #include <opencv2/opencv.hpp> #include <QImage> #include <QPixmap> using namespace cv; // 畸变 Mat barrelDistortion(Mat input, double k) { Mat output = input.clone(); int w = input.cols; int h = input.rows; int cx = w / 2; int cy = h / 2; double dx, dy, r, theta; double dtheta = 1.0 / w; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { dx = x - cx; dy = y - cy; r = sqrt(dx*dx + dy*dy); theta = atan(r * dtheta); double rn = r * (1 + k * theta*theta); double scale = rn / r; int nx = dx * scale + cx; int ny = dy * scale + cy; if (nx >= 0 && nx < w && ny >= 0 && ny < h) { output.at<Vec3b>(y, x) = input.at<Vec3b>(ny, nx); } } } return output; } // 桶畸变 Mat pincushionDistortion(Mat input, double k) { Mat output = input.clone(); int w = input.cols; int h = input.rows; int cx = w / 2; int cy = h / 2; double dx, dy, r, theta; double dtheta = 1.0 / w; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { dx = x - cx; dy = y - cy; r = sqrt(dx*dx + dy*dy); theta = atan(r * dtheta); double rn = r / (1 + k * theta*theta); double scale = rn / r; int nx = dx * scale + cx; int ny = dy * scale + cy; if (nx >= 0 && nx < w && ny >= 0 && ny < h) { output.at<Vec3b>(y, x) = input.at<Vec3b>(ny, nx); } } } return output; } // 将Mat转换为QImage QImage Mat2QImage(Mat input) { cv::Mat mat; cvtColor(input, mat, CV_BGR2RGB); QImage image((const uchar*)mat.data, mat.cols, mat.rows, mat.cols * mat.channels(), QImage::Format_RGB888); return image; } // 将QImage转换为Mat Mat QImage2Mat(QImage input) { cv::Mat mat(input.height(), input.width(), CV_8UC4, (uchar*)input.bits(), input.bytesPerLine()); cv::Mat mat2; cvtColor(mat, mat2, CV_RGBA2BGR); return mat2; } // 示例函数 void testDistortion() { // 读取图像 Mat input = imread("input.jpg"); // 畸变 Mat output1 = barrelDistortion(input, 0.5); // 桶畸变 Mat output2 = pincushionDistortion(input, 0.5); // 显示图像 QImage image1 = Mat2QImage(output1); QPixmap pixmap1 = QPixmap::fromImage(image1); QImage image2 = Mat2QImage(output2); QPixmap pixmap2 = QPixmap::fromImage(image2); QLabel label1; label1.setPixmap(pixmap1.scaled(640, 480, Qt::KeepAspectRatio)); QLabel label2; label2.setPixmap(pixmap2.scaled(640, 480, Qt::KeepAspectRatio)); QVBoxLayout layout; layout.addWidget(&label1); layout.addWidget(&label2); QWidget window; window.setLayout(&layout); window.show(); } int main(int argc, char *argv[]) { testDistortion(); return 0; } ``` 在上面的代码中,`barrelDistortion`函数和`pincushionDistortion`函数分别实现了畸变和桶畸变的处理。这两个函数都接受一个`Mat`类型的输入图像和畸变系数`k`,并返回处理后的图像。 `testDistortion`函数演示了如何使用上述函数来处理输入图像并显示结果。在该函数中,先读取输入图像,然后分别对其进行和桶畸变的处理,并将处理后的结果显示出来。为了方便,这里使用了Qt的GUI框架来显示图像。 注意,上述代码中使用的是OpenCV 3.x或更早版本。如果您使用的是OpenCV 4.x或更新版本,可能需要进行一些修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值