首页 > 解决方案 > 在给定 2 张图像的情况下查找对象的 3D 位置

问题描述

您好,我想在给定对象的2 个不同视图的情况下找到对象的 3D 位置。

我可以在这里提供的东西是:

我在这里不能提供的东西是:

这些是我可以用来获得与相机和内在参数相对应的中心坐标的方法。

# This function uses a custom trained fasterrcnn model to detect the object and
# the center of the objects is being calculated using the bounding boxes.
# For simplicity the centers are being hardcoded, since the object won't move
def calculateCenterAndBoundingBox(image):
    ...
    boundingBox1 = [(715.329, 383.64413), (746.09143, 402.87524)]
    boudingBox2 = [(303.78778, 391.57953), (339.4821, 412.69092)]
    if image == 1:
       return (730.7102, 393.2597), boundingBox1  
    else
       return (321.63495, 402.13522), boudingBox2 

#for simplicity reasons, both intrinsic cameras are the same
def calculateIntrinsic():
    ...
    return [[512, 0.0,         512],
            [0.0, 483.0443151, 364],
            [0.0, 0.0,         1.0]]

我试图用 8 点算法确定我的对象的位置,所以我决定使用这个实现用 SIFT 创建一些特征关键点。

%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import pysift
import math
import cv2

def myPlot(img):
    plt.figure(figsize=(15,20)) # display the output image
    plt.imshow(img)
    plt.xticks([])
    plt.yticks([])
    plt.show()

pathToImage1 = "testImage1.png"
c1, bb1 = calculateCenterAndBoundingBox(1)
originalImage1 = cv2.imread(pathToImage1) 
img1 = cv2.imread(pathToImage1, 0)

originalImage1 = originalImage[math.floor(bb1[0][1]): math.floor(bb1[1][1]), math.floor(bb1[0][0]):math.floor(bb1[1][0])]
img1 = img1[math.floor(bb1[0][1]): math.floor(bb1[1][1]), math.floor(bb1[0][0]):math.floor(bb1[1][0])]

keypoints, descriptors = pysift.computeKeypointsAndDescriptors(img1)
img1=cv2.drawKeypoints(img1,keypoints,originalImage1)
myplot(img1)


pathToImage2 = "testImage2.png"
c2, bb2 = calculateCenterAndBoundingBox(2)
originalImage2 = cv2.imread(pathToImage2) 
img2 = cv2.imread(pathToImage2 , 0) 

originalImage2 = originalImage2[math.floor(bb2 [0][1]): math.floor(bb2 [1][1]), math.floor(bb2 [0][0]):math.floor(bb2 [1][0])]
img2 = img2[math.floor(bb2 [0][1]): math.floor(bb2 [1][1]), math.floor(bb2 [0][0]):math.floor(bb2 [1][0])]

keypoints, descriptors = pysift.computeKeypointsAndDescriptors(img2)
img2=cv2.drawKeypoints(img2,keypoints,originalImage2)
myPlot(img2)

但是我只有 1 个特征关键点而不是 8 个或更多

所以在这种情况下,我显然不能使用 8 点算法。但我没有其他想法如何解决这个问题,给出上述约束。

是否可以仅给定每个相机的 2D 点和固有矩阵来计算 3D 位置?

标签: python3dpositiondetectionkeypoint

解决方案


推荐阅读