|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools |
Rating:
|
Display Modes |
|
#43
|
||||
|
||||
|
Re: Tower Tracker 1.0
Quote:
Code:
y = rec.br().y + rec.height / 2; y= -((2 * (y / matOriginal.height())) - 1); ). Let's rearrange the operationsCode:
double half_image_height = matOriginal.height() / 2; double pixel_y = half_image_height - (rec.br().y + rec.height / 2); y = pixel_y / half_image_height; With that change, this operation makes a bit more sense. The point is to calculate the offset in normalized coordinates from the middle of the target to the horizon. The horizon is assumed to be at (matOriginal.height()/2). First, it subtracts the y-coordinate of the middle of the target from half of the image size in pixels. This results in the pixel offset between the horizon line on the image to the target y-coordinate. Then, the entire thing is normalized by dividing it by half the pixel image height. ![]() Code:
distance = (TOP_TARGET_HEIGHT - TOP_CAMERA_HEIGHT) / Math.tan((y * VERTICAL_FOV / 2.0 + CAMERA_ANGLE) * Math.PI / 180); There are two parts. First, the angle from the horizon to the target is approximated using the small angle approximation. Code:
(y * VERTICAL_FOV / 2.0 + CAMERA_ANGLE) * Math.PI / 180 Code:
angle = arcsin( pixel_y * sin(VERTICAL_FOV/2.0) / half_image_height ) Now the camera may be tilted relative to the field, meaning that its local "horizon" isn't the same, so the offset CAMERA_ANGLE is added, for the angle that the camera is tilted relative to the actual horizon. Now the final part is to calculate the distance using the known height of the target and this calculated angle to the horizon. ![]() h is the distance from the camera's height to the target's height (TOP_TARGET_HEIGHT - TOP_CAMERA_HEIGHT), so tan(alpha) = h/d => d = h/tan(alpha) I hope this explains it. Last edited by euhlmann : 11-07-2016 at 12:15. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|