title: Ideas how can i measure distance of an detected object from Camera using opencv for IOS?
body: <p>Story:</p>
  
  <p>I have an app that is detecting faces build with opencv on iphone sdk 6.0 every thing is working i can use the front camer and the "back camera " also i can turn on/off the torch as well i can display how much fps i have at the moment (live) .</p>
  
  <p>but now i want to add a additional feature that you can see how fare away is this face </p>
  
  <p><img src="https://i.stack.imgur.com/nvgVK.png" alt="enter image description here"></p>
  
  <p>are there some formulas or some good ideas or evan a solution from a pro ? 
  (if you need some code  or something i can show you every thing that you need ) </p>
  
  <p>Thx for help and fast answers !^^ </p>
  
  <p>hear is for every one a translation for objective c </p>
  
  <pre><code>-(double) faceDistance{
      const NSInteger kFaceWidth = 10;
      const NSInteger kPicWidth = 640;
      CGPoint p1 = CGPointMake(10, 10);
      CGPoint p2 = CGPointMake(100, 70);
      int facePixelWidth;
  
  
      int slope = (p2.y - p1.y) / (p2.x - p1.x);
  
      double propOfPic = kPicWidth / facePixelWidth;
      double surfSize = propOfPic * kFaceWidth;
      double dist = surfSize / slope;
  
      return dist;
  }
  </code></pre>
  
  <p>I have update my code here is the solution for objective c </p>