I’m working on the localization problem using cameras. i.e., given an image and some knowledge of the 3-D world, find the position of the camera in that 3-D world.
Previously, we have used knowledge of a vision target to do this. Given that we know the 3D position of the corners of the vision target, and we have successfully found the rectangle of the vision target in the image, we can call the openCV function solvePNP, and get our position relative to the target.
So far so good, but what if you don’t have the exact points? Specifically, what if you have a line? Like a piece of gaffer’s tape that you happen to know is on the floor. If you can find the corresponding line in the image, how can you use this information to compute your distance from that line? (You can’t get a complete 3-D position without using some other information.)
If you happen to be at right angles to the line, I know how to solve the problem. If the camera axis is horizontal to the floor, and at height h, and the camera is facing perpendicular to the line, it’s fairly straightforward.
let h=height of camera
Y=point in image space, pixels (since you approaching it perpendicularly, the line witll be horizontal)
f=focal length of camera (in pixels)
d=distance to the line (the thing you’re trying to find)
From similar triangles, d=h*f/Y. (Be careful on signs and units, and in this case I’m assuming the center of the image is 0.) Now you know where you are, or at least how far you have to drive to get to the line. (You don’t know horizontal position)
However, suppose you are not approaching the line perpendicularly. In the image, there is now a non-horizontal line. And now my math skills fail me. I can’t work out how to translate the angle of the line in the image to the angle of the line in the 3-D world, with respect to my camera.
I’m sure this problem has been solved many times in the past, and it looks like fairly straightforward trigonometry, but I just haven’t figured it out, and my google skills have so far been inadequate to find a description of the problem on the web. Any help would be appreciated.
I’m sure there is, somewhere, a solution to the more general problem of, given a known iine in 3D space, and a projection of that line onto an image, determine the camera position and orientation with respect to the line. In other words, I’m sure there is a description of the problem where it is not assumed that the camera is horizontal or that the line is on the floor. However, I would be content just to have a solution for the simpler problem described above.
ETA: And for those interested, a thread from last summer discussed the simpler problem of using solvePNP to find your position if you have exact points. I would link to it, but I’m running late for work, so I must run.