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)

相关推荐
迈火43 分钟前
ComfyUI-3D-Pack:3D创作的AI神器
人工智能·gpt·3d·ai·stable diffusion·aigc·midjourney
Moshow郑锴2 小时前
机器学习的特征工程(特征构造、特征选择、特征转换和特征提取)详解
人工智能·机器学习
CareyWYR2 小时前
每周AI论文速递(250811-250815)
人工智能
AI精钢2 小时前
H20芯片与中国的科技自立:一场隐形的博弈
人工智能·科技·stm32·单片机·物联网
whaosoft-1433 小时前
51c自动驾驶~合集14
人工智能
Jinkxs3 小时前
自动化测试的下一站:AI缺陷检测工具如何实现“bug提前预警”?
人工智能·自动化
小幽余生不加糖3 小时前
电路方案分析(二十二)适用于音频应用的25-50W反激电源方案
人工智能·笔记·学习·音视频
柠檬味拥抱4 小时前
优化AI智能体行为:Q学习、深度Q网络与动态规划在复杂任务中的研究
人工智能
玄明Hanko4 小时前
程序员如何使用 cursor 写代码?
人工智能
用户5191495848454 小时前
HITCON CTF 2018 - 单行PHP挑战:会话上传与流过滤器链的极致利用
人工智能·aigc