Using Python and Project Oxford Vision API to OCR a Online image from any URL

The Computer Vision API are a collection of state-of-the-art image processing algorithms designed to return information based on the visual content, and to generate your ideal thumbnail. With this API, you can choose which visual features you want to extract that best suit your need

Project Oxford Vision APi has the following features:-

Analyse an image

This module will produce visual features based on the input image's visual content -- image categories, pornographic detection, dominant colour, and more.

  • Use the adult and racy features to enable automated restriction of sexual content and protect your users.
  • Utilize categorization to help append tags to images, as well as group images into clusters.


Generate a thumbnail

Given an input image, you will be able to generate a high quality and storage efficient thumbnail.

  • Leverage thumbnail generation to help present images in the best form suited to your needs.
  • Use smart cropping for thumbnails that are different than the aspect ratio of your original image in order to preserve the region of interest.



Optical Character Recognition (OCR) detects text in an image and extracts the recognized characters into a machine-usable character stream.

  • Run on embedded images to generate text and enable searching.
  • Allow users to take photos of text instead of transcribing to save time and effort.


Looking for an end to end solution from Microsoft for monitoring image content?


Moderate your content

Scenario-based Content Moderator service brings together Project Oxford API’s and more to proactively alert you of content policy violations

  • Create and maintain custom image and text blacklists with automated alerts.
  • Fuzzy matching can detect permutations of content you have blacklisted.
Detect child exploitation

Use our PhotoDNA Cloud Service to automatically detect and report the distribution of child exploitation images.

  • Distinguish and flag illegal images when they are uploaded to your platform.
  • Service can identify images even when they have been altered.


In this blog I am going to cover using Python and OCR functionality of the Microsoft Project Oxford API


The Python Script simply passes the url of Image to the Project Oxford API and OCR the image


Python Script

import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
   # Basic Authorization Sample
   # 'Authorization': 'Basic %s' % base64.encodestring('{username}:{password}'),
   'Content-type': 'application/json',

params = urllib.parse.urlencode({
   # Specify your subscription key
   'subscription-key': 'INSERT PROJECTOXFORD VISION KEY',
   # Specify values for optional parameters, as needed
   'language': 'en',
   'detectOrientation ': 'true',

   conn = http.client.HTTPSConnection('')
   conn.request("POST", "/vision/v1/ocr?%s" % params, "{'Url':'Simply add url of image}", headers)
   response = conn.getresponse()
   data =
except Exception as e:
   print("[Errno {0}] {1}".format(e.errno, e.strerror))


The Target Image


The output


Press any key to continue . . .


So overall the Project Oxford API is pretty impressive and from a simply  25 lines of code the image has been OCR..

Comments (0)

Skip to main content