title: OpenCV: Calculate Angle between camera and object
body: <p>how can i compute the angle of an object in front of my camera? The resolution of my camera is 1280x1024, the focal length of my lens is 8mm and the pixel size of each pixel on the CMOS is 4.8 micrometer. Surely it must be possible to compute the angle from that. Also i computed the distance of the object to the camera and everything is on one level. So only the X coordinate is interesting, right?</p>
  
  <p>I am using OpenCV and Python for the processing.</p>
  
  <p>My idea was to use the focal length of the lens in combination with the X-Offset of the detected object from the sensor middle, but i do get weird angles from that.</p>
  
  <p>This is the code for the angle estimation:</p>
  
  <blockquote>
    <p>first the point X coordinate, second the width of the whole sensor (1280 pixels * 4.8um) in mm, third the focal length in mm.</p>
    
    <p>angle = (pointInterpolatedX*6.144)/8</p>
  </blockquote>
  
  <p>Could anybody give me some help here? Thanks!</p>
  
  <p>Also, i had a look at this topic <a href="https://stackoverflow.com/questions/17499409/opencv-calculate-angle-between-camera-and-pixel">here</a>, but i can't quite understand it. I have a lot more informations about my camera and also my object can only move in 2 Dimensions and not three. So there might be a clever way of estimating its position on the ground in front of the camera.
  Does OpenCV have any function i could use for that?</p>