if you check this thread started from me (Calculate the distance between the iPhone and a door, knowing their physical widths) I accepted an answer, that states, correctly, that if you do not know focal lens data of the camera of the iPhone, there is no easy way to calculate the distance between an iPhone and, let's say, a door, knowing its width.
I have to start another thread now asking:
I know the physical (not only in pixel) size of the screen of the iPhone (for iPhone 5 is 2.31 inches)
Also I know the width of a door.
Now, if I am in the position where the width of the door fits perfectly in the width of the iPhone itself (not of the camera), and the iPhone stands perfectly vertical, is it possible to know the distance between the iPhone and the door in that moment?
Thank you for your kind help!
I assume you mean that there is some outside image capturing device (be it a human eye or another camera) and the image capturing device, the phone, and the door are all in a line such that the phone appears to be the same width as the door.
In this case, you still need a) the distance between the image capturing device and the phone and b) the optical information (such as focal length) of the image capturing device. Just sit down with a pen and paper and draw out the geometry for a little bit and you'll see that.
This is going to involve a trigonometric calculation. I think you might have done R&D on Gyroscope, if not then surely you should refer it.
1) Find angle your phone is making with ground. Like when you point the device's camera to bottom of the object.
2) Now you are having one angle and you are making 90 degree with ground. So basically you are forming a right angled triangle. And you had just found one of your angle near your hand.
3) You can approximate distance of your phone from surface to your hand. So you got one side of triangle and one angle. Thus you can find second side i.e distance between you and object.
Hope this helps. :)
I am trying to get 'picking' working in a 3D scene, where the view is rotated such that the iPhone is being held in a landscape mode. I'm using OpenGL ES 2.0 (so all shaders, no fixed-function pipeline).
I'm performing the unproject from within the rendering code and immediately drawing the resulting ray using GL_LINES (ray only gets calculated the 1st time that I touch the screen, so afterwards I can move the camera around to observe the resulting line from various angles).
My unproject code/call is fine (lots of examples of gluUnproject online). My matrix-inversion code is fine (even compared with excel for a few matrices). However, the resulting ray is off by at least 5-15 degrees from where I actually 'clicked' (in the Simulator it really is a click, so I'm expecting a lot more precision from the unproject).
My view is rotated to landscape (after I create the perspective-projection matrix, I rotate it around the Z by -90 degrees; the aspect ratio remains at a portrait one). I believe that the problem with the math being off lies here.
Does anyone have any experience doing picking/unprojection with specifically a landscape view?
Is it possible you simply have the field of view off? Assuming you've stuck to something a lot like the traditional pipeline, if you were inverting your modelview matrix then using generic unproject code (ie, code that assumes a 90 degree field of view in both directions to fill eye space) then that would explain it.
A quick diagnostic test is to see how far off it is for different touches. Touches nearer the centre of projection should be closer to the correct answer.
On a screen with square pixels like the iPhone, the aspect ratio is just the proportion of the horizontal field compared to the vertical. So if you want to be unscientific about it, find the field of view you're using, say f, and try multiplying your results by 90/f or f/90. If that doesn't work, try also throwing a factor of 480/320 or 320/480 in there.
A better solution is to follow your code through and figure out what your actual horizontal and vertical fields of view are. And multiply your results by that over 90.
I have a need to measure a room (if possible) from within an iPhone application, and I'm looking for some ideas on how I can achieve this. Extreme accuracy is not important, but accuracy down to say 1 foot would be good. Some ideas I've had so far are:
Walk around the room and measure using GPS. Unlikely to be anywhere near accurate enough, particularly for iPod touch users
Emit sounds from the microphone and measure how long they take to return. There are some apps out there that do this already, such as PocketMeter. I suspect this would not be user friendly, and more gimmicky than practical.
Anyone have any other ideas?
You could stand in one corner and throw the phone against the far corner. The phone could begin measurement at a certain point of acceleration and end measurement at deceleration
1) Set iPhone down on the floor starting at one wall with base against the wall.
2) Mark line where iPhone ends at top.
3) Pick iPhone up and move base to where the line is you just drew.
4) Repeat steps 1->3 until you reach the other wall.
5) Multiply number of lines it took to reach other wall by length of iPhone to reach final measurement.
=)
I remember seeing programs for realtors that involved holding a reference object up in a picture. The program would identify the reference object and other flat surfaces in the image and calculate dimensions from that. It was intended for measuring the exterior of houses. It could follow connected walls that it could assume were at right angles.
Instead of shipping with a reference object, as those programs did, you might be able to use a few common household objects like a piece of printer paper. Let the user pick from a list of common objects what flat item they are holding up to the wall.
Detecting the edges of walls, and of the reference object, is some tricky pattern recognition, followed by some tricky math to convert the found edges to planes. Still better than throwing you phone at the far wall though.
Emit sounds from the microphone and measure how long they take to return. There are some apps out there that do this already, such as PocketMeter. I suspect this would not be user friendly, and more gimmicky than practical.
Au contraire, mon frère.
This is the most user friendly, not to mention accurate, way of measuring the dimensions of a room.
PocketMeter measures the distance to one wall with an accuracy of half an inch.
If you use the same formulas to measure distance, but have the person stand near a corner of the room (so that the distances to the walls, floor, and ceiling are all different), you should be able to calculate all three measurements (length, width, and height) with one sonar pulse.
Edited, because of the comment, to add:
In an ideal world, you would get 6 pulses, one from each of the surfaces. However, we don't live in an ideal world. Here are some things you'll have to take into account:
The sound pulse causes the iPhone to vibrate. The iPhone microphone picks up this vibration.
The type of floor (carpet, wood, tile) will affect the time that the sound travels to the floor and back to the device.
The sound reflects of off more than one surface (wall) and returns to the iPhone.
If I had to guess, because I've done something similar in the past, you're going to have to emit a multi-frequency tone, made up of a low frequency, a medium frequency, and a high frequency. You'll have to perform a fast Fourier Transform on the sound wave you receive to pick out the frequencies that you transmitted.
Now, I don't want to discourage you. The calculations can be done. However, it's going to take some work. After all PocketMeter has been at it for a while, and they only measure the distance to one wall.
I think an easier way to do this would be to use the Pythagorean theorem. Most rooms are 8 or 10 feet tall and if the user can guess accurately, you can use the camera to do some analysis and crunch the numbers. (You might have to have some clever way to detect the angle)
How to do it
I expect 5 points off of your bottom line for this ;)
Let me see if it helps. Take an object of known length and keep it beside the wall and with Iphone, take pic of wall along with the object that you kept beside the wall. Now get the ratio of wall width and object width from the image in Iphone. And as you know the width of the object, you can easily calcualte the width of wall. repeat it for each wall and you will have a room measurement.
Your users could measure a known distance by pacing it off, and thereby calibrate the length of their pace. Then they could enter the distance of each wall in paces, and the phone would convert it to feet. This would probably be very convenient, and would probably be accurate to within 10%.
If they may need more accurate readings, then give them the option of entering in a measurement from a tape measure.
This answer is somewhat similar to Jitendra's answer, but the method he suggests will only work where you can fit the whole wall in a single shot.
Get an object of know size and photograph it held against the wall with the iphone held against the other wall (two people or blutac needed). Then you can calculate the distance between the walls by looking at the size of the object (in pixels) in the photo. You could use a PDF to make a printed document the object of known size and use a 2D barcode to get the iphone to pick it up.
When the user wants to measure something, he takes a picture of it, but you're actually taking two separate images, one with flash on, one with flash off. Then you can analyze the lighting differences in the image and the flash reflection to determine the scale of the image. This will only work for close and not too shining objects I guess.
But that's about the only other way I thought about deducting scale from an image without any fixed objects.
How do i calculate Dip and Strike from iphone. They are used to measure rocks.
i have to use compass api how do i get the angle from it.
anyone has idea please give me some idea.
Thank you.
The "compass API" is not so much a compass as a magnetometer. (In other words, if you put your phone near some strong local magnetic field - say, a CRT monitor - you won't only be measuring the Earth's magnetic field.)
This sample ought to help you on your way. It demonstrates the use of the CLLocationManager.
To determine the orientation of the rockface you need to use the UIAccelerometer class. Have your ViewController or whatever implement the UIAccelerometerDelegate protocol. The BubbleLevel sample application will show you how to use the API.
The magnetometer then allows you to turn that phone orientation into an orientation relative to magnetic North.
Instead of asking the same question. I offer part but not full answer.
Strike => (Geology) horizontal surface crossing bedding in question: this can be achieved by reading the heading from the CLLocationDirection.magneticHeading
Dip.angle => (Geology) horizontal surface & bedding angle: this can be achieved by either CMMotionManager.CMDeviceMotion.CMAttitude.roll or pitch depending on how the iOS device is held to the bedding being measuered.
EDIT:
3. Dip.driection => (Geology) actual NSWE orientation of the tilt: Strike + 90 because they are perpendicular clockwise (I think).
I may have not written my answer correctly but my geologist colleagues confirm my readings which is basically 1, 2 and 3 (eg: 43/11SE)
If someone can improve this answer, I appreciate it.
can someone please give me an example of how you detect if the iphone is moving left or moving right. like a long version of a shake i want my app to be able to know if the users arm is going right or left. imagine your hand like a window wiper with the phone at the end
any ideas?
Thanks, Sam :P
That would be the acceleration.x value. Imagine 3 lines going through your iPhone:
1) a line perpendicular to your iPhone screen and going through it, that would be Z.
2) a horizontal and parallel line to your screen, that would be X (what you're looking for).
3) a vertical and parallel line to your screen, that would be Y.
So, moving the iPhone left or right will generate changes in the X graph. Moving the iPhone up or down will generate changes in the Y graph. Moving your iPhone forward or backward will generate changes in the Z graph.
Hope this helps you grasp the accelerometer's concept,
~ Natanavra.