Incomplete coordinate values for Google Vision OCR
<p>I have a script that is iterating through images of different forms. When parsing the Google Vision Text detection response, I use the XY coordinates in the 'boundingPoly' for each text item to specifically look for data in different parts of the form. </p>

<p>The problem I'm having is that some of the responses come back with only an X coordinate. Example:</p>

<pre><code>{u'description': u'sometext', u'boundingPoly': {u'vertices': [{u'x': 5595}, {u'x': 5717}, {u'y': 122, u'x': 5717}, {u'y': 122, u'x': 5595}
</code></pre>

<p>I've set a try/except (using python 2.7) to catch this issue, but it's always the same issue: <code>KeyError: 'y'</code>. I'm iterating through thousands of forms; so far it has happened to 10 rows out of 1000. </p>

<p>Has anyone had this issue before? Is there a fix other than attempting to re-submit the request if it reaches this error? </p>

<p><a href="https://cloud.google.com/vision/reference/rest/v1/images/annotate" rel="nofollow">From the docs</a>:</p>

<blockquote>
  <p>boundingPoly</p>
  
  <p>object(BoundingPoly)</p>
  
  <p>The bounding polygon around the face. The coordinates of the bounding box are in the original image's scale, as returned in ImageParams. The bounding box is computed to "frame" the face in accordance with human expectations. It is based on the landmarker results. <strong>Note that one or more x and/or y coordinates may not be generated in the BoundingPoly (the polygon will be unbounded) if only a partial face appears in the image to be annotated.</strong></p>
</blockquote>

<p>I believe this is implying that the <code>'y'</code> value in this case is <code>0</code>, or more generally, an edge value. In other words, it doesn't know where the bounded poly truly ends, as the text goes all the way to the edge of the image, and thus the image doesn't give enough info to know for sure that the text actually ends there. As far as the image provides, it ends at <code>'y'</code> of <code>0</code>.</p>

python ocr google-cloud-vision