Parallax Mathematics

Miscellaneous news and views...

Moderator: scott

User avatar
LustInBlack
Devotee
Devotee
Posts: 1964
Joined: Thu Apr 06, 2006 10:30 am

Parallax Mathematics

Post by LustInBlack »

Ok I'm really not that good in maths apparently..

I'm trying to make a formula to calculate distance of objects from a camera at 2 different viewpoints that are rotated of about let's say 10 degrees..

So basicly, the object will move to the left from the apparent viewpoint if I rotate the camera to the right..

This relative distance can be plugged in an equation to resolve the distance..

I guess it's going to use sine laws and triangulation, but I don't seem to get it right ..

I resolved this to Distance = RelativeDistance/tan(10)

But the problem is, this is exactly the inverse of what I want.. Objects that are near the camera will have a greater relative distance than objects in the rear thus, let's say for 2 objects ..

We have approximatively 5 and 11 units of distance for relativedistances of 1 and 2 ..

But in reality, object that have 2 reldist must have a smaller Distance than the one at 1 .. SO this doesn't seem to work ..

Unless I have to take into account the maximum distance the camera can see and substract the pseudo distance from it ..


Like : Distance = MaxFiedDistance - (RelativeDistance / TAN(10))

And .. Yes I looked wikipedia and I am a bit confused, they seem to use parallax in space to lookup distances, but they seem to have more information than I have to compute the distance ..
User avatar
LustInBlack
Devotee
Devotee
Posts: 1964
Joined: Thu Apr 06, 2006 10:30 am

re: Parallax Mathematics

Post by LustInBlack »

Well it looks like I should only invert the relative distance..

So basicly reldist = 1/reldist ..

Am I right !? ..

Then it's simply a matter of identifying the units and calibrating with the camera ..
rlortie
Addict
Addict
Posts: 8475
Joined: Thu Jan 06, 2005 6:20 pm
Location: Stanfield Or.

re: Parallax Mathematics

Post by rlortie »

Lib,

A vintage WWII artillery range finder worked by using mirrors.

The viewer look into a device not unlike binoculars, what he was looking into was two 45 degree mirrors turning the view to a 180 degree view through a tube. At each end of the tube were another set of mirrors. These outer mirrors were movable with a set protractor used for indexing.

When the viewer looked into the scope he would equally adjust the outer mirrors until both were concentrated on the target making for one image. The distance from mirror to mirror was a known factor, by reading the angle he could triangulate the distance of the target.

Ralph
User avatar
LustInBlack
Devotee
Devotee
Posts: 1964
Joined: Thu Apr 06, 2006 10:30 am

re: Parallax Mathematics

Post by LustInBlack »

Interesting ..

Actually I cannot do this (But I do get the point, that it explains one possible way to do it). I explain myself ..

I'm actually programming an Artificial Vision system on a robotic platform.. There is only 1 camera onboard, so no stereoscopic imaging, thus the need to take snapshots of 2 or more frames to compute the position of objects ..

Basically, my idea was to simply take a snapshot then rotate the robot (it's on skid tracks) for about 5 degrees or more and take another snapshot.. Then I simply need to compare the two images with a sobel filter and some other proprietary algorithms, to retrieve objects, then compare the objects in the two images .. What will happen is as I said previously, the objects in the back will be closer together (If I were to surperpose the 2 images) and objects in front will be farther apart; thus creating the parallax effect ..

At least, that's the way prey animals do it (Birds, reptiles and all animals that bobs their head up and down, or have eyes on the side of their head; they compute depth with movement) ..

Anyways.. What would be interesting in your example, is a superposition of the 2 images from two mirrors at different angles..

Is your binocular actually precise or is it primitive?! ..

So if I understand correctly, the binoculars are a kind of mechanic lookup table that gives you pre calculated indexes for relative distances ..
User avatar
jim_mich
Addict
Addict
Posts: 7467
Joined: Sun Dec 07, 2003 12:02 am
Location: Michigan
Contact:

re: Parallax Mathematics

Post by jim_mich »

If you are viewing an objects with the camera located at a single position and only rotate the camera side to side then there is no way to triangulate the position of the object. This is because you have only two reference positions, the camera and the object. What is needed is two camera 'sight' positions spaced some distance apart. Using mirrors could work rather than two cameras. The object must be in the center of the 'sight' and the angle that the two 'sights' rotate inward from straight parallel must be known. This inward rotation must be equal for each 'sight' else the math gets more complicated.

See the attached sketch. If you know the distance 'D' between the two sight positions and you know the angle 'A' that each camera or mirror tilts inward then the distance from either camera view is (1/2 × D) / Sin(90 - A). The distance down the center dashed line would be (1/2 × D) / Tan(90 - A).

Hope this helps.


Image
Attachments
Triangulation diagram
Triangulation diagram
User avatar
LustInBlack
Devotee
Devotee
Posts: 1964
Joined: Thu Apr 06, 2006 10:30 am

re: Parallax Mathematics

Post by LustInBlack »

Thanks Jim..

In fact I am looking at doing the exact same opposite thing!

You said that it's impossible to get distance if I only rotate the camera.. I believe this is due to the fact that I am missing one measurement to get the distance and triangulate ..

But, what happens if in your image, the camera is the object that needs to be measured and that the distance D is known!? .. The only missing information would be the 2 angles A right!? .. I believe it's possible to get the missing A angles and then measure object distance, because I know the angle at the camera point (B) .. And I know that the objects are traveling in almost straight lines (relative to camera) when I rotate the viewport ..


Another thing, this is the case of a right angle triangle right!?..

I mean, I only need to divide D by 2 to get the math of right triangle, then, I know B so, basically, SIN(1) = (D/2) / Hypothenuse

Thus, Hypo = (D/2) / SIN(1)

And by pythagoras a2 + b2 = c2

I now have 2 measurements, I can get the distance of that right triangle..

But then, I still have the problem that a larger D will give me a larger distance, when in fact, I should have a lesser distance from the camera..

Anyways, I just want to understand what I am doing wrong ..

Thanks!
Attachments
t_triangulation2.png
User avatar
jim_mich
Addict
Addict
Posts: 7467
Joined: Sun Dec 07, 2003 12:02 am
Location: Michigan
Contact:

Post by jim_mich »

If you know the distance 'D' and you know angle 'B' then if both lines 'AB' are equal then you can split the triangle along the dotted line to form two equal right triangles thus you know that one angle is 90 degrees. Then everything else is solvable using trig formulas. The camera will not know what distance 'D' is because it will appear the same whenever two objects are located anywhere along lines 'AB'. What you need is a camera with a range finder circuit and somehow tap into the logic.


Image
rlortie
Addict
Addict
Posts: 8475
Joined: Thu Jan 06, 2005 6:20 pm
Location: Stanfield Or.

re: Parallax Mathematics

Post by rlortie »

User avatar
LustInBlack
Devotee
Devotee
Posts: 1964
Joined: Thu Apr 06, 2006 10:30 am

Post by LustInBlack »

jim_mich wrote:If you know the distance 'D' and you know angle 'B' then if both lines 'AB' are equal then you can split the triangle along the dotted line to form two equal right triangles thus you know that one angle is 90 degrees. Then everything else is solvable using trig formulas. The camera will not know what distance 'D' is because it will appear the same whenever two objects are located anywhere along lines 'AB'. What you need is a camera with a range finder circuit and somehow tap into the logic.

Actually, no (most of the time), because I choose what angle B is, and the parallax effect makes distance D different..

I'll attach an image of what happens to the camera point of reference..

I'm not sure a range finder would work actually, it would need direct view of the object, so if 2 objects are one behind another (the farther being bigger) I'm not sure what a ranger finder would do ..

I don't want to put more hardware on the robot, it needs to use only the camera to do it, that's the challenge..

Btw, a range finder using the "blurriness" of objects in the background could probably give me a hint of what is the nearest .. but that I already know..

Interesting links Ralph, I'll take some time to browse thru them, at first sight, it's good, but it needs a laser or more hardware..

If I cannot get accurate measures using just camera rotation, I still could move the robot to a new position and really use the formula that Jim gave me, that could do it, but it's more complicated then it seems.. The robot doesn't have accelerometers or any sensors that give him it's position.. only the camera.. But just a simple rotation on it's axis is doable and relatively accurate (just enough for my application) ..
Attachments
parallax_fov.JPG
User avatar
Fletcher
Addict
Addict
Posts: 8723
Joined: Wed Nov 05, 2003 9:03 am
Location: NZ

re: Parallax Mathematics

Post by Fletcher »

Without going to steryoscopic camera's & expensive & weighty extra hardware there may be a couple of simple solutions - one is a sonic range finder that returns a signal & that could be calibrated - probably the most simple is to have two laser point lights that triangulate at a known distance in the field of vision - then have software that can recognize/see these points of light & calculate the distance apart - if the lights are superimposed on the same spot then you know the exact distance - you would need two different coloured lights so that when the beams crossed over [object past focus point] the software could tell the object was behind the focal point.
User avatar
LustInBlack
Devotee
Devotee
Posts: 1964
Joined: Thu Apr 06, 2006 10:30 am

re: Parallax Mathematics

Post by LustInBlack »

All good ideas Fletcher, and valid ones! .. However, it's simply that I want to do it the "natural" way ..

If I were to build a robot that say, drives a car, I don't want to have all that fancy hardware around, I want to do a visual cortex..

This will go into FPGAs and ASICs if I get the result I want ..

Anyways, I will test this as soon as I can and post the final result here.. 8]
User avatar
jim_mich
Addict
Addict
Posts: 7467
Joined: Sun Dec 07, 2003 12:02 am
Location: Michigan
Contact:

Post by jim_mich »

If you want a simple method using only one camera then I'd suggest using three mirrors. One mirror is to the left side of the camera and one to the right side. One mirror is in the middle and is solenoid activated so the camera looks to the right or to the left. This will produce two images, one from off to the right and one from off to the left. From this it would seem like a simple task for the software to triangulate the shift of the object in the two images.


Image
rlortie
Addict
Addict
Posts: 8475
Joined: Thu Jan 06, 2005 6:20 pm
Location: Stanfield Or.

re: Parallax Mathematics

Post by rlortie »

LIB,

(in jest) build a working gravity machine and then you can afford all the high tech stuff!
User avatar
LustInBlack
Devotee
Devotee
Posts: 1964
Joined: Thu Apr 06, 2006 10:30 am

re: Parallax Mathematics

Post by LustInBlack »

Jim, that's actually not a bad idea ..

Instead of doing that, I could easily just make the camera move from left to right on a rack and pinion, that would be easier.

So you are concluding that my theory of doing it is not right!?

Ralph, hehe don't worry, I have other plans .. Inventions much more impossible than perpetual motion ... 8]
User avatar
jim_mich
Addict
Addict
Posts: 7467
Joined: Sun Dec 07, 2003 12:02 am
Location: Michigan
Contact:

re: Parallax Mathematics

Post by jim_mich »

Moving the camera side to side would would work but changing the angle will not work. Moving the camera side to side using a motor driven rack and pinion seems more complicated than a simple hinged mirror and solenoid in the center.

Actually you could use two mirrors in the center thus producing two images in the camera and then split the images using software.

Of course the very simplest method would be to use two cameras spaced some distance apart.


Image
Attachments
Parallax Cameras
Parallax Cameras
Post Reply