OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 09 Mar 2019 17:14:15 -0600How do i get the angle of an object in front of my camera?http://answers.opencv.org/question/210066/how-do-i-get-the-angle-of-an-object-in-front-of-my-camera/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!Sat, 09 Mar 2019 11:53:35 -0600http://answers.opencv.org/question/210066/how-do-i-get-the-angle-of-an-object-in-front-of-my-camera/Comment by swebb_denver for <p>Hello there,</p>
<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, if thats helpful.</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>
<pre><code>#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
</code></pre>
<p>Could anybody give me some help here?
Thanks!</p>
http://answers.opencv.org/question/210066/how-do-i-get-the-angle-of-an-object-in-front-of-my-camera/?comment=210073#post-id-210073I'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..Sat, 09 Mar 2019 17:14:15 -0600http://answers.opencv.org/question/210066/how-do-i-get-the-angle-of-an-object-in-front-of-my-camera/?comment=210073#post-id-210073Comment by MarviB for <p>Hello there,</p>
<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, if thats helpful.</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>
<pre><code>#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
</code></pre>
<p>Could anybody give me some help here?
Thanks!</p>
http://answers.opencv.org/question/210066/how-do-i-get-the-angle-of-an-object-in-front-of-my-camera/?comment=210068#post-id-210068Well i am using opencv for it..Sat, 09 Mar 2019 12:05:53 -0600http://answers.opencv.org/question/210066/how-do-i-get-the-angle-of-an-object-in-front-of-my-camera/?comment=210068#post-id-210068Comment by berak for <p>Hello there,</p>
<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, if thats helpful.</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>
<pre><code>#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
</code></pre>
<p>Could anybody give me some help here?
Thanks!</p>
http://answers.opencv.org/question/210066/how-do-i-get-the-angle-of-an-object-in-front-of-my-camera/?comment=210067#post-id-210067and how exactly is this related to opencv ?Sat, 09 Mar 2019 12:04:44 -0600http://answers.opencv.org/question/210066/how-do-i-get-the-angle-of-an-object-in-front-of-my-camera/?comment=210067#post-id-210067