0

My program needs to compute the angle of a pixel from a computer vision camera that has 120 degrees horizontal field of view, and resolution of 640 pixels wide and 480 pixels high.

Program receives an X,Y array of pixels for each image frame from camera. For left-most pixel, X would be 0 and angle would be -60 degrees. For right-most pixel, X would be 639 and angle 60 degrees. For center pixel, X would be 320 and angle 0.

How is angle computed when (X is > 0 and < 320) and (>320 and <640)?

Doug Null
  • 7,989
  • 15
  • 69
  • 148

3 Answers3

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()));
Francesco Callari
  • 11,300
  • 2
  • 25
  • 40
0

This is simplest and seems to work:

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 );
Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
Doug Null
  • 7,989
  • 15
  • 69
  • 148
  • Franscesco: Does this make sense? I tried your complete solution, but got wrong angle. Then I realized solving for x was just a simple trig function of x and f. – Doug Null Sep 21 '15 at 15:34
  • Wrong again, sorry. Replace atan(x/f) with atan((x - 0.5 * image_width) / f), since you want the angle w.r.t. the center ray. My original expression gives the angle between the rays backprojecting the image center and a generic pixel from the optical center of the camera. Your intended expression above is the angle between the rays backprojecting the image center and the projection of the same generic pixel onto the horizontal image axis passing by the image center. – Francesco Callari Oct 24 '17 at 15:29
-1

I found answer at: here

I think the answer is:

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

where:

pix_X = Pixel * coordinate
Hres = horizontal resolution = 640 pixels
HFOV = horizontal field of view angle = 120 degrees
Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
Doug Null
  • 7,989
  • 15
  • 69
  • 148
  • Wrong. The tangent of an angle is not a linear function of the angle. – Francesco Callari Sep 11 '15 at 19:27
  • But each x-coordinate is equidistant from camera. The camera's field of view is an arc along which all pixels appear equidistant to camera. So each pixel along x is equal angle apart. The horizontal axis of pixels is not along a line, relative to the camera, it's along an arc. – Doug Null Sep 11 '15 at 20:44
  • Check out the answer at 'here'. – Doug Null Sep 11 '15 at 20:45
  • Re: "So each pixel along x is an equal angle apart" - The question does not mention that you have a spherical sensor. If it's a standard camera with a planar sensor (i.e. one modelled by a standard pinhole model) your assertion is plainly wrong. angle(x - c_x) = atan((x - cx) / focal_length) – Francesco Callari Sep 14 '15 at 16:51
  • Agreed. I am wrong. Each camera pixel sensor is on same plane. That's why calibration is essential. Thanks!! – Doug Null Sep 15 '15 at 15:04