I needed to know the size of an object, but I couldn't climb up and measure it. After some thought I came up with an idea: Use a camera, clever math, and a game engine.
The idea is to simulate both the real life camera and real life object in the game engine. With your photo as a background image and the camera in the correct position relative to the object, in real world units, you should be able to adjust the size of the object until it matches the size of the object in the picture, then read off it's scale. It's not super accurate, but it works.
However, for this to work, you need to know the angle of your camera's view frustum at whatever zoom level you want. You will also need to know the distance from the camera to the object and the angle between "up" as far as the object is concerned and "up" as far as the camera is concerned, if you are measuring height.
I am lucky because my dad hunts and consequentially has a range finder, which makes it absurdly easy to find out how far away an object is.
Anyway, here is how to do it.
FIRST: measure the view frustum angle
My plan was to take a picture of something that I can measure and then make a version of that situation inside Unity. I used my doorway. I placed my camera a set distance away from the base of the doorway and took a picture, then measured the dimensions of the doorway and the distance to the camera.
Then, I created a similar scene in unity with a camera at the same distance from a "doorway" (actually a cube) with the same dimensions. Then, I made sure I was using the same aspect ratio as my camera, placed the photo as a background image, and adjusted the view frustum until the cube fit perfectly over the doorway. It came out to 39 degrees.
The next step is similar, but the process is done backwards. The object is photographed, the distance to the object measured, and then the scene is reconstructed inside unity with the photo as a background and a cube representing the object of interest.
Then, the scale of the cube is adjusted until it matches the photo, and the resulting scale is your measurement.
Part 3: compensating for angle and also how to find distances without a rangefinder.
I guess the simplest way to measure would be to practice measuring by counting strides and then approximate the height and use the pythagorean theorem with your measurements. You can also use a measuring tape from the base of the object to the camera and a precise angle measuring tool to figure out the height. You can then use the angle read out directly in unity on your simulated camera.
My rangefinder has an angle mode where it reads off the horizontal distance from you to your target which is good for bowhunting from a tree stand but also helps me out. I can take an angle mode measurement and a direct measurement and then do some right triangle math to position everything correctly in Unity. Here is the script I attached to my camera:
// in yards
var noAngle = 0.00;
var withAngle = 0.00;
function OnDrawGizmos () {
var adjacentOverHypotenuse = withAngle / noAngle;
var angle = Mathf.Acos(adjacentOverHypotenuse);
Debug.Log("Degrees: " + angle* Mathf.Rad2Deg);
// 36 inches per yard
var height = Mathf.Tan(angle) * withAngle * 36;
transform.position = Vector3(0, -height, -withAngle * 36);
transform.localEulerAngles.x = -angle * Mathf.Rad2Deg;
// assuming the object is at (0,0,0)
}
And the setup in unity: (Note: Layers are used here, the ortho cam and photo are just the background picture. All of the real world positioning has to do with the cube and perspective camera(
I tested it on my house. That window is 77 inches tall and the camera method measured ~79 inches. That's a 2.5% innacuracy, which is close to the rangefinder's inaccuracy at that distance. (The rangefinder is + or - a half yard and the window was 17 yards away, so 3%).
Sunday, January 3, 2010
How to measure the size of an object using a camera
Posted by
Forest Johnson
at
3:47 PM
Labels: life, micro projects
Subscribe to:
Post Comments (Atom)



10 comments:
Coach Outlet Online is a good store!
Coach Factory Outlet
Coach outlet online Leading American designer and maker of luxury lifestyle handbags and accessories.Large market in Europe and Canada,UK,USA etc.Welcome to Order!2011 New Style arrive,Free Shipping!
As a Coach Factory Outlet Online, you get paid several ways. The primary way is resale - here is where you sell a product thru your company's Coach Factory Outlet Online. The 2nd way is membership sale - you can sell a club membership and you'll get paid unearned income each time the customer renews their Coach Factory Outlet Online.
You will never buy fashion and cheap Coach Handbags. These benefits, Coach Factory Outlet are the best shopping place for most women. They are the first choice for women.
Your success is my inspiration.Indeed, it is wonderful !!
the article is interesting Coach Factory Outlet although there is a small mistake in the chart.
the article is very interesting..Good!!thank you!!
Coach Outlet Online Build a network monitoring long-term mechanism of action to rectify the vigorous national network finally come to an end.
Making sure your legs are covered is just the first step on Coach Outlet the exciting road to choosing the right morning dress trousers for you.
Post a Comment