Numpy 如何使用单应性将两个摄像头FOV转换为一个显示图像

Numpy 如何使用单应性将两个摄像头FOV转换为一个显示图像,numpy,opencv,image-processing,computer-vision,homography,Numpy,Opencv,Image Processing,Computer Vision,Homography,我正在做一个项目,我必须用鸟瞰的非重叠视图从两个摄像机中检测物体(铁路上的小车)(见下图) 如您所见,车辆被检测到,并返回其质心坐标 然而,我试图将这两个视图转换为一个图像,该图像仅表示汽车行驶的铁路 因此,为了模拟,我创建了只包含铁路的目的地图像(上图中显示的黑色轨迹),如下所示: 在做了一些研究之后,我使用了openCV中的一种方法:cv2.findHomography()whcih查找两个平面之间的单应矩阵 来自两台摄像机的两幅图像的分辨率分别为1280x720。对于目标图像,其分辨率

我正在做一个项目,我必须用鸟瞰的非重叠视图从两个摄像机中检测物体(铁路上的小车)(见下图)

如您所见,车辆被检测到,并返回其质心坐标

然而,我试图将这两个视图转换为一个图像,该图像仅表示汽车行驶的铁路

因此,为了模拟,我创建了只包含铁路的目的地图像(上图中显示的黑色轨迹),如下所示:

在做了一些研究之后,我使用了openCV中的一种方法:
cv2.findHomography()
whcih查找两个平面之间的单应矩阵

来自两台摄像机的两幅图像的分辨率分别为1280x720。对于目标图像,其分辨率为1440x480

我的代码编写如下:

import numpy as np
import cv2

def Perspective_transf(src_point,h):
 a = np.array([src_point]) 
 a=np.array(a.transpose())
 a=np.vstack((a,np.array(1)))
 a_transformed_homo = np.dot(h,a)
 scale_factor=a_transformed_homo[2][0]
 a_transformed_euk=np.divide(a_transformed_homo,scale_factor)
 return a_transformed_euk

# Source points: from camera image which are the same as the two cameras have the same resolution 
pts_src=np.array([[0,0],[1280,0],[720,1280],[0,720],[640,360]])
#destination correspondences of the pts_src on the destination image (for camera 1)
pts_dst1=np.array([[0,0],[720,0],[720,480],[0,480],[360,240]])
#destination correspondences of the pts_src on the destination image (for camera2)
pts_dst2=np.array( [[720,0],[1440,0],[1440,480],[720,480],[1080,240]])

#homography between the first camera image plane and the destination image
h1, status1 = cv2.findHomography(pts_src, pts_dst1)
#homography between the second camera image plane and the destination image
h2, status1 = cv2.findHomography(pts_src, pts_dst2) 
现在,我估计了同形图,对于每个检测到的质心,我可以使用同形图将其投影(变换)到目标图像上

当我运行代码时,我得到以下结果:

如您所见,将检测到的车辆质心从一个摄像头视场转换到另一个摄像头视场时创建的轨迹与模拟铁路的定义轨迹不对齐,并且与图像相比旋转

那么我做错了什么,为什么我的结果看起来如此

提前谢谢


Khaled Jbaili

我只是通过添加更多的点对来解决这个问题。这样可以将反投影误差降至最低