news 2026/6/10 20:55:06

根据相机内参与畸变参数对图像进行畸变校正

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
根据相机内参与畸变参数对图像进行畸变校正

新建data与data-jb文件夹,并将畸变待校正的图像放入到data中,运行以下代码即可进行图像的畸变校正,并输出畸变校正后的图像,保存到data-jb中。

##以下代码用于根据相机内参与畸变参数,对输入图像进行畸变校正,以输出畸变校正后的图像 import cv2 as cv import numpy as np import os import glob # 假设您已经从之前的标定过程中获得了以下参数,代入得到的参数 camera_matrix = np.array([[643.24580489, 0.0, 318.64488952], [0.0, 643.92943431, 236.75374833], [0.0, 0.0, 1.0]], dtype=np.float32) dist_coefs = np.array([-0.29706837, -0.22038399, 0.00303177, 0.00368427, 1.36565465], dtype=np.float32) # 指定要校正的图像文件夹路径 input_folder = 'C:/Users/zhao/Desktop/test/data'##输入路径 output_folder = 'C:/Users/zhao/Desktop/test/data-jb'##输出路径 # 确保输出文件夹存在 if not os.path.exists(output_folder): os.makedirs(output_folder) # 读取文件夹中的所有图像文件 image_files = glob.glob(os.path.join(input_folder, '*.jpg')) # 假设图像是JPEG格式 # 遍历所有图像文件 for image_file in image_files: # 读取图像 img = cv.imread(image_file) if img is None: print(f"Failed to load {image_file}") continue h, w = img.shape[:2] # 获取新的相机矩阵和ROI newcameramtx, roi = cv.getOptimalNewCameraMatrix(camera_matrix, dist_coefs, (w, h), 1, (w, h)) # 对图像进行畸变校正 dst = cv.undistort(img, camera_matrix, dist_coefs, None, newcameramtx) # 裁剪图像 x, y, w, h = roi dst = dst[y:y+h, x:x+w] # 构建输出文件路径 file_name = os.path.basename(image_file) output_file = os.path.join(output_folder, file_name) # 保存校正后的图像 cv.imwrite(output_file, dst) print(f"Undistorted image written to: {output_file}") print('Done')
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/10 20:53:17

Apache 虚拟主机配置指南:从单站点到多站点

一、什么是虚拟主机 虚拟主机(Virtual Host)是 Apache 的核心功能之一,允许在一台物理服务器上托管多个网站。每个网站拥有独立的域名、文档根目录和配置,互不干扰。 Apache 支持三种虚拟主机方式:类型区分依据适用场景…

作者头像 李华
网站建设 2026/6/10 20:43:34

5个Claudian插件使用技巧:快速提升AI交互效率的完整指南

5个Claudian插件使用技巧:快速提升AI交互效率的完整指南 【免费下载链接】claudian An Obsidian plugin that embeds Claude Code/Codex as an AI collaborator in your vault 项目地址: https://gitcode.com/GitHub_Trending/cl/claudian Claudian是一款强大…

作者头像 李华
网站建设 2026/6/10 20:42:12

Windows终极性能优化方案:Atlas-OS开源项目深度解析与完整指南

Windows终极性能优化方案:Atlas-OS开源项目深度解析与完整指南 【免费下载链接】Atlas 🚀 An open and lightweight modification to Windows, designed to optimize performance, privacy and usability. 项目地址: https://gitcode.com/GitHub_Trend…

作者头像 李华
网站建设 2026/6/10 20:40:58

VivienneVMM常见问题排查:解决安装和使用的10个难题

VivienneVMM常见问题排查:解决安装和使用的10个难题 【免费下载链接】VivienneVMM VivienneVMM is a stealthy debugging framework implemented via an Intel VT-x hypervisor. 项目地址: https://gitcode.com/gh_mirrors/vi/VivienneVMM VivienneVMM 是一款…

作者头像 李华
网站建设 2026/6/10 20:35:48

Obsidian效率工具:Claudian插件的批量操作技巧

Obsidian效率工具:Claudian插件的批量操作技巧 【免费下载链接】claudian An Obsidian plugin that embeds Claude Code/Codex as an AI collaborator in your vault 项目地址: https://gitcode.com/GitHub_Trending/cl/claudian Claudian是一款强大的Obsidi…

作者头像 李华