0

I was wondering if it was possible to use the iOS gyroscope to detect if an object the camera is taking (a physical photo of someone) is straight. This means by perhaps using the iOS camera, I could know if the physical photo is straight. Does anyone know if this can be done? If so, can someone please provide an example?

Thank you

Teddy13
  • 3,824
  • 11
  • 42
  • 69

1 Answers1

1

Use the gravity property of CMDeviceMotion, which incorporates both accelerometer and gyroscope data.

Another approach would be to detect straight lines in the image, and see whether these are horizontal or vertical. In most scenes, the camera is oriented correctly when the most prominent straight lines are horizontal or vertical. You can do this using the Hough transform on an edge-filtered image.

David M.
  • 3,667
  • 25
  • 27
  • Thank you David! Just to verify before I wander on my own to do research, your suggestion imply that we are measuring the straightness of the device opposed to the object before the device? Correct? Thanks – Teddy13 Mar 18 '13 at 06:44
  • Maybe you should explain the problem you're trying to solve more explicitly. I was imagining a scenario where the user is taking photographs and wants the horizon to be level. – David M. Mar 18 '13 at 06:58
  • Okay. So I want to take a photo with my iOS device of a business card (in this example). I hold the business card in one hand and take the photo with the device in my other hand. However, the image taken is crooked because of the angle I was holding the business card at. Is there a way to detect the business card is not straight relative to the device before the image is taken (or after)? Thanks so much! – Teddy13 Mar 18 '13 at 07:17
  • 1
    Then you need to analyze the image: since you can only measure the phone's orientation, and not that of the card, there's no way to find the relative orientation from sensors. There's a broad field of work on this kind of problem. This might be a good place to start: http://stackoverflow.com/questions/6356891/find-distorted-rectangle-in-image-opencv I'm offline for now. – David M. Mar 18 '13 at 09:03