opencv 三维重建基础

import cv2

import numpy as np

假设已经获取了相机矩阵和畸变系数

camera_matrix = np.array(...)

dist_coeffs = np.array(...)

读取校正前的图像

img1 = cv2.imread('left01.jpg')

校正图像

map1, map2 = cv2.fisheye.initUndistortRectifyMap(camera_matrix, dist_coeffs, np.eye(3), camera_matrix, img1.shape[0:2][::-1], cv2.CV_16SC2)

undistorted_img1 = cv2.remap(img1, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)

计算投影矩阵

proj_matrix = cv2.fisheye.getOptimizedProjectionMatrix(camera_matrix, dist_coeffs, undistorted_img1.shape[1], undistorted_img1.shape[0], alpha=0.0)

将校正后的图像投影到三维空间

img1_3d = cv2.fisheye.projectImageTo3D(undistorted_img1, proj_matrix)

显示三维点云

points = np.reshape(img1_3d, (3, -1)).T

points = np.hstack((points, np.ones((1, points.shape[1]))))

print(points)

相关推荐
算家计算几秒前
6GB显存玩转SD微调!LoRA-scripts本地部署教程,一键炼出专属AI画师
人工智能·开源
YYXZZ。。几秒前
PyTorch——非线性激活(5)
人工智能·pytorch·python
孤独野指针*P3 分钟前
释放模型潜力:浅谈目标检测微调技术(Fine-tuning)
人工智能·深度学习·yolo·计算机视觉·目标跟踪
橙色小博8 分钟前
python中的经典视觉模块:OpenCV(cv2)全面解析
人工智能·opencv·计算机视觉
蹦蹦跳跳真可爱5898 分钟前
Python----目标检测(YOLO简介)
人工智能·python·yolo·目标检测·计算机视觉·目标跟踪
数智大号12 分钟前
AI“实体化”革命:具身智能如何重构体育、工业与未来生活
人工智能
凯禾瑞华实训室建设16 分钟前
老年生活照护实训室建设规划:照护质量评估与持续改进实训体系
大数据·人工智能·物联网·ar·vr
声网24 分钟前
ElevenLabs 新 TTS 模型支持音频标签;NotebookLM 前产品经理新项目曝光:将邮件日历新闻转为互动音频丨日报
人工智能
hrw_embedded29 分钟前
办公提效的AI免费工具使用感悟
人工智能·办公软件
攻城狮7号30 分钟前
Cursor 1.0正式推出:全面解析你的AI 编程助手
人工智能·深度学习·ai编程·cursor 1.0