How do i get the angle of an object in front of my camera?

asked 2019-03-09 11:53:35 -0500

MarviB gravatar image

Hello there,

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, if thats helpful.

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.

This is the code for the angle estimation:

#first the point X coordinate, second the width of the whole sensor (1280 pixels * 4.8um), third the focal length.
angle = (pointInterpolatedX*6.144)/8

Could anybody give me some help here? Thanks!

edit retag flag offensive close merge delete


and how exactly is this related to opencv ?

berak gravatar imageberak ( 2019-03-09 12:04:44 -0500 )edit

Well i am using opencv for it..

MarviB gravatar imageMarviB ( 2019-03-09 12:05:53 -0500 )edit

I'm not sure I understand what you are looking for, but maybe I do?

First you need to figure out what your image center is - if you can calibrate the camera you will get an actual X,Y pixel value, otherwise you can just assume it is centered in the image space. So cx = 639.5 (the midway point of 0 and 1279)

Then a little bit of trig: angle = atan( (X-cx) / f) Where f is the focal length in pixels, (8 / 0.0044) = 1667

So for an image point at 800 you would get atan((800-639.5)/1667) = 5.5 degrees

Be aware that your atan() function probably returns the angle in radians.

You are really better off calibrating your camera first if you need accurate results, particularly if there is optical distortion..

swebb_denver gravatar imageswebb_denver ( 2019-03-09 17:14:15 -0500 )edit