问题描述
我正在一个项目中,我必须从两个具有鸟瞰图的非重叠视图的摄像机中检测物体(铁路上的小型汽车)(见下图两个图)
您会看到检测到汽车,并返回了它们的质心坐标。
但是,我试图将这两种视图转换为一张图像,该图像仅代表汽车行驶的铁路。
因此,为了进行模拟,我创建了仅具有铁路的目标图像(上图所示的黑色轨迹),如下所示:
做完一些研究之后,我从openCV的一种名为cv2.findHomography()
的方法着陆,找到了两个平面之间的单应性矩阵。
来自两个摄像机的两个图像分别具有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,[720,1280],[0,720],[640,360]])
#destination correspondences of the pts_src on the destination image (for camera 1)
pts_dst1=np.array([[0,480],[360,240]])
#destination correspondences of the pts_src on the destination image (for camera2)
pts_dst2=np.array( [[720,[1440,[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,pts_dst2)
现在,在此之后,我估计了同形异义词,对于每个检测到的质心,我可以使用同形异义词将其投影(变换)到目标图像上。
运行代码时,我得到以下结果:
如您所见,将检测到的汽车行驶的质心从一个摄像头视场转换为另一摄像头视场所创建的轨迹与模拟铁路的定义轨迹未对齐,并且与图像相比旋转了。
>那么我在做错什么,为什么我的结果看起来像这样?
预先感谢
Khaled Jbaili
解决方法
我通过添加更多对点来解决它。这样反投影误差最小。