Search code examples
androidocrgoogle-vision

Limit google vision api text detection to specific region


I am trying to use google vision API to detect text from camera preview. However, I want the detected text to be within a specific region/rectangle in the camera review.


Solution

  • Till date, there is no such feature in GVision. But I handled a similar situation by filtering at the backend of my application, as follows.

    1. Get the GVision text using FULL_TEXT_DETECTION
    2. Get the co-ordinates of user action, i.e., user touch, or mouse click
    3. Get the application length & width of the mobile device
    4. Make a proportion or ratio function from points 2 & 3
    5. Using the value from point 4, get extract the text of based on GVision bounds of the blocks

    Update: 4/8/2018

    {
      "requests": [
        {
          "imageContext": {
            "latLongRect": {
              "minLatLng": {
                "latitude": 0,
                "longitude": 0
              },
              "maxLatLng": {
                "latitude": 0,
                "longitude": 0
              }
            }
          }
        }
      ]
    }
    

    minLatLng is TopLeft, maxLatLng is BottomRight of the your region

    For more check: https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate#ImageContext