title: OpenCV - Measuring distance between two edges
body: <p>I want to measure the distance (in pixels) between two edges.
  Following are the images I used and the link to code I used.</p>
  
  <p><strong>Images</strong> : </p>
  
  <p><img src="https://i.stack.imgur.com/mrGM1.jpg" alt="enter image description here">  </p>
  
  <p><img src="https://i.stack.imgur.com/gCpgz.jpg" alt="enter image description here">  </p>
  
  <p><img src="https://i.stack.imgur.com/Qnwko.jpg" alt="enter image description here">  </p>
  
  <p><img src="https://i.stack.imgur.com/0TA4n.jpg" alt="enter image description here"></p>
  
  <p>In program 1 : <a href="http://pastebin.com/VNdhyYuU" rel="nofollow noreferrer">Program1</a></p>
  
  <p>I scanned the particular row of the image <code>Mat</code> from 0 to cols. i.e. along one scan line. In this case I obtained the location of white pixels i.e. edge pixels correctly .</p>
  
  <p>In program 2 : <a href="http://pastebin.com/uJNwr4ka" rel="nofollow noreferrer">Program2</a></p>
  
  <p>I scanned the particular row of the image <code>Mat</code> from middle , i.e. I measure from middle to right direction of row till cols and again from middle to 0th column of the row. In this case I get erroneous value while getting the location of white pixel i.e. edge pixel.</p>
  
  <p>Can you please suggest me what’s wrong in the code or if there is a better solution.</p>