将屏幕坐标[x,y]转换为摄像机平移和倾斜角度 [英] Translating Screen Coordinates [ x, y ] to Camera Pan and Tilt angles

查看:624
本文介绍了将屏幕坐标[x,y]转换为摄像机平移和倾斜角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以PTZ的IP摄像机。我目前正在将实时供稿流式传输到浏览器中,并希望允许用户单击屏幕上的一个点,并且摄像机将平移和倾斜,以便用户单击的位置现在将成为中心视点。

I have a IP Camera which can PTZ. I am currently streaming live feed into the browser and want to allow user to click a point on the screen and the camera will pan and tilt so that the user clicked position will now become the center point of view.

我的摄影机可以360度旋转,并从-55倾斜到90度。

my Camera Pan 360 degrees and Tilt from -55 to 90.

任何可以指导我实现目标的算法

any algorithm that will guide to me achieve my goal ??

推荐答案

首先声明一个围绕相机(原点)的3D坐标系。我将使用以下内容:z轴指向上方。 x轴是相机方向,其中 pan = tilt = 0 ,正向平移角度会将相机移向正y轴。

Let's start by declaring a 3D coordinate system around the camera (the origin). I will use the following: The z-axis points upwards. The x-axis is the camera direction with pan=tilt=0 and positive pan angles will move the camera towards the positive y-axis.

然后,给定的水平/倾斜配置的转换为:

Then, the transform for a given pan/tilt configuration is:

T = Ry(-tilt) * Rz(pan)

这是将虚拟图像平面定位在3D空间中的变换。让我们牢记这一点,然后转到图像平面。

This is the transform that positions our virtual image plane in 3D space. Let's keep that in mind and go to the image plane.

如果我们知道垂直和水平视场并假设已经校正了镜头畸变,则可以设置我们的图像平面如下:图像平面在视图方向上距离相机1单位(仅通过声明)。让中心为飞机的本地原点。然后,其水平范围为 +-tan(fovx / 2),垂直范围为 +-tan(fovy / 2)

If we know the vertical and horizontal field of view and assume that lens distortions are already corrected, we can set up our image plane as follows: The image plane is 1 unit away from the camera (just by declaration) in the view direction. Let the center be the plane's local origin. Then, its horizontal extents are +- tan(fovx / 2) and its vertical extents are +- tan(fovy / 2).

现在,给定该图像中的像素位置(x,y)(原点位于左上角),我们首先需要将此位置转换为3D方向。我们首先计算图像平面中的局部坐标。这是针对图像的像素宽度 w 和像素高度 h

Now, given a pixel position (x, y) in this image (origin in the top left corner), we first need to convert this location into a 3D direction. We start by calculating the local coordinates in the image plane. This is for the image's pixel width w and pixel height h:

lx = (2 * x / w - 1) * tan(fovx / 2)
ly = (-2 * y / h + 1) * tan(fovy / 2)   (local y-axis points upwards)
lz = 1                                  (image plane is 1 unit away)

这是在假设没有平移或倾斜的情况下包含相应像素的光线。但是现在该摆脱这个假设了。这就是我们最初的转变发挥作用的地方。我们只需要变换此光线即可:

This is the ray that contains the according pixel under the assumption that there is no pan or tilt yet. But now it is time to get rid of this assumption. That's where our initial transform comes into play. We just need to transform this ray:

tx = cos(pan) * cos(tilt) * lx - cos(tilt) * sin(pan) * ly - sin(tilt) * lz
ty = sin(pan)             * lx + cos(pan)             * ly
tz = cos(pan) * sin(tilt) * lx - sin(pan) * sin(tilt) * ly + cos(tilt) * lz

结果现在,方向描述了在开始时设置的全局坐标系中包含指定像素的射线。剩下的就是计算新的声相/倾斜参数:

The resulting direction now describes the ray that contains the specified pixel in the global coordinate system that we set up in the beginning. All that's left is calculate the new pan/tilt parameters:

tilt = atan2(tz, tx)
pan  = asin(ty / sqrt(tx^2 + ty^2 + tz^2))

这篇关于将屏幕坐标[x,y]转换为摄像机平移和倾斜角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆