blender 世界坐标投影到图像坐标

相机参数

# 相机内参
K = [[2637.5783226764374, 0.0, 960.0],
 [0.0, 2637.5783226764374, 540.0],
 [0.0, 0.0, 1.0]]
K = np.array(K).astype(np.float64)
# 相机位姿以及旋转顺序
camera_loc = [7, -6, 5]
camera_rot = [60, 15, 40]
mode = 'xyz'

旋转矩阵

import numpy as np
from scipy.spatial.transform import Rotation as R

# e 是为了和世界坐标系对齐方向
e = np.eye(3)
e[[1,2],[1,2]] = -1
RT_camera2world = R.from_euler(mode, camera_rot, degrees=True).as_matrix()
RT_camera2world = RT_camera2world @ e

RT_camera2world = np.concatenate((RT_camera2world, np.reshape(camera_loc,[3,1])), axis=1)

RT_camera2world = np.concatenate([RT_camera2world, [[0, 0, 0, 1]]], axis=0)
RT_world2camera = np.linalg.inv(RT_camera2world)


投影

rvec = cv2.Rodrigues(RT_world2camera[:3, :3])[0]
tvec = RT_world2camera[:3, 3]

corner_raw = [
    [1, 1, 1],
    [1, -1, 1],
    [1, 1, -1],
    [-1, 1, 1],
]
corner = np.array(corner_raw).astype(np.float64)

corner_xy = cv2.projectPoints(corner, rvec, tvec, K, np.zeros((1, 5)))[0]
corner_xy = corner_xy.reshape((-1, 2)).astype(np.int16)

可视化点

  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值