So far i found formula of actual distance calculation.
distance(mm) = (focal length (mm) * real height of the object (mm) * camera frame height in device (pixels) ) / ( image height (pixels) * sensor height (mm))
parameters.getFocalLength() gives me focal length
parameters.getPreviewSize().height gives me frame height
i assume sensor height 1500mm
but how can i get Real height of object and image height
You will need to know (1) the actual height of the object (in mm), (2) the height of the object in the image (in pixels), and (3) the height of the sensor (in mm).
For (1) you need to measure in the real world or calculate relative to other things (for example, if there is something else of a known height at the same distance, you could determine the height relative to that object.) If you can't do that then you need some sort of calibration routine. Depending on the application you might consider making a database of 'known objects' as an estimation. For example if your app was a dashboard camera where you wanted to measure the distance to vehicles in front of you, you could have standard 'car' 'truck' 'motorcycle' 'bike rider' objects whose sizes you define. Then when you are measuring distances you would apply the correct pre-defined size to the formula. Wouldn't be 100% accurate but would be close (and you can fine-tune your database if you need more options).
For (2) you need to do image processing to find the location of the object in the image. This might also mean classify the object as one of your pre-defined types as described above.
For (3) you can make an assumption or you could have a database of know hardware, detect what hardware is in use and apply the appropriate size. For example, find out what type of sensors are in the Nexus 5 and put that in the DB. Then when a user runs the app, check the phone and if it is a Nexus 5 load the appropriate sensor size.
As to the two links you provided:
The first one you provide does what you want in a very manual way. It does not provide a database of known/expected objects it asks the user to enter the known size (step 1 of my last post). It also relies on the user to do the 'processing' (step 2 of my last post) by drawing two lines around the object of interest. My guess is it is using a fixed guess on the sensor height.
The second height doesn't do what you describe at all - it measures the distance between two GPS points. No image involved.
ibrahim yener wrote:How about, getting GPS location of far_index ? Is that possible?
If you have been there - yes (store location and look it up). If you know the GPS location you are at, the distance and direction of the far object then yes, you could calculate the Lat/Long of the other location also. It would be relatively simple geometry unless your far object is far enough that the earth's curvature will have a big effect.
Also, i know some military equipments can measure distance up to 20-30km but of course i am not going to build military stuff.
There are lots of ways to calculate distances accurately at great distance if you have microwaves or lasers to use... And given some good software and some analysts you can get accurate distance and size of objects in pictures as well - but that requires a lot of work to analyze the picture for known objects sizes to get size calibration and angles of the known things (like the sun or stars, or tall distant buildings) to get reference angle information. If you can get a smartphone to do it, that would be awesome. But these are things that are usually done with a combination of sophisticated software and personal interaction.
ibrahim yener wrote:How about to get Lat/Long of center of camera?
What do you mean?
I guess this is very difficult task to handle or just not for one person development without user interaction.
It might be hard, but maybe there is some ingenuitive way to get at what you want. Sit back and take a deep thought about what you want to do. Write up a document explaining the details of exactly what you want the app to do and why. Break the idea down into smaller parts and tasks. Then look at the parts (pick just one, and if you get stuck put it aside and pick out another one) and start to come up some ideas on how you could conceivably do them. Then research those ideas. The best applications do things that are really tough and make it seem easy. Don't give up because it looks hard, it just might mean you are on to something.
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java