如何从图像坐标(z=0)获取世界坐标

问题描述 投票:0回答:1

我的相机捕获物体所在的区域,这就是为什么我不需要“Z”坐标。我最近有这个代码。我有 4 个对象(二维码,位于固定位置),我知道它们的世界坐标和图像坐标。但我的目标是这个:如果我在这 4 个对象之间放置任何对象,我的相机会拍摄一张照片,我的神经网络会为我提供这个新对象的图像坐标,现在我想知道这个新对象的世界坐标。我怎么才能得到它。非常感谢。

import cv2
import numpy as np
 
# Read Image
im = cv2.imread("./kalibrace/pokus1.png");
size = im.shape
 
#2D image points. If you change the image, you need to change vector
image_points = np.array([
                            (0.83724, 0.611574),     # Nose tip
                            (0.83099, 0.037037),     # Chin
                            (0.229427, 0.0402778),     # Left eye left corner
                            (0.220313, 0.937037),     # Right eye right corne
                        ], dtype="double")
 
# 3D model points.
model_points = np.array([
                            (0.0, 0.0, 0.0),             # Nose tip
                            (173, 0, 0.0),        # Chin
                            (173, 323.5, 0.0),     # Left eye left corner
                            (96.5, 323.5, 0.0),      # Right eye right corne
 
                        ])
 
# Camera internals

f_x = 1.08859874e+03
c_x = 9.33429058e+02
f_y = 1.08828073e+03
c_y = 5.68306911e+02
# Matice kamery (intrinsická matice)
camera_matrix = np.array([[f_x, 0, c_x],
                           [0, f_y, c_y],
                           [0, 0, 1]], dtype = "double")
 
print("Camera Matrix :\n {0}".format(camera_matrix))
 
dist_coeffs = np.zeros((4,1)) # Assuming no lens distortion
(success, rotation_vector, translation_vector) = cv2.solvePnP(model_points, image_points, camera_matrix, dist_coeffs)
 
print("Rotation Vector:\n {0}".format(rotation_vector))
print("Translation Vector:\n {0}".format(translation_vector))

我期待 4 个世界坐标

python image opencv camera coordinates
1个回答
0
投票

问题有点不清楚。但是,如果您尝试从图像坐标获取世界坐标,那么这个问题已经涵盖了问题。

请记住,从世界到图像空间是一个投影,其逆过程只是另一个投影(称为向后投影)。 所以如果你的图像坐标T \times P = I。然后你有 I 并计算 T 和 T^{-1} \times T \times P = P。这里T是从世界到相机的投影矩阵,I是投影图像,P是世界坐标中的点

© www.soinside.com 2019 - 2024. All rights reserved.