如何从计算机视觉相机计算像素的水平角度

时间:2015-09-11 13:34:07

标签: opencv image-processing camera geometry computer-vision

我的程序需要从具有120度水平视野的计算机视觉相机计算像素的角度,分辨率为640像素宽,480像素高。

程序从相机接收每个图像帧的X,Y像素阵列。 对于最左边的像素,X将为0,角度为-60度。 对于最右边的像素,X将是639并且角度是60度。 对于中心像素,X将为320且角度为0。

当(X是> 0和< 320)和(> 320和< 640)?

时如何计算角度?

3 个答案:

答案 0 :(得分:5)

// In pseudocode.

// Compute focal length in pixels from FOV
double f = (0.5 * image_width) / tan(0.5 * fov_radians);

// Vectors subtending image center and pixel from optical center
// in camera coordinates.
Vector3D center(0, 0, f), pixel(x - center_x, y - center_y, f);

// angle between vector (0, 0, f) and pixel
double dot = dot_product(center, pixel)
double alpha = acos(dot / (center.length() * pixel.length()));

答案 1 :(得分:0)

这是最简单的,似乎有效:

double image_width_pixels = CAMERA_HORIZONTAL_RESOLUTION_PIXELS;
double fov_radians = CAMERA_HORIZONTAL_FIELD_OF_VIEW_RADIANS;
double f = ( image_width_pixels / 2.0 ) / tan( fov_radians / 2.0 );
int x = <<< horizontal pixel coordinate >>>;
double angle_radians = atan( x / f );

答案 2 :(得分:-1)

我找到了答案: here

我认为答案是:

angle =  ( pix_X - (Hres/2) ) / (Hres/2)  * HFOV/2

其中:

pix_X = Pixel * coordinate
Hres = horizontal resolution = 640 pixels
HFOV = horizontal field of view angle = 120 degrees