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

Dou*_*ull 0 geometry camera opencv image-processing computer-vision

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

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

当(X> 0且<320)和(> 320和<640)时,如何计算角度?

Fra*_*ari 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()));
Run Code Online (Sandbox Code Playgroud)