Computer Vision API Jupyter notebook

This guide shows you how to use the Computer Vision API in Python and how to visualize your results using popular libraries. You will use Jupyter to run the tutorial. To learn how to get started with interactive Jupyter notebooks, refer to the Jupyter Documentation.

Prerequisites

Open the notebook in Jupyter

  1. Go to the Cognitive Vision Python GitHub repo.
  2. Click on the green button to clone or download the repo.
  3. Open a command prompt and navigate to the folder Cognitive-Vision-Python\Jupyter Notebook.
  4. Ensure you have all the required libraries by running the command pip install requests opencv-python numpy matplotlib from the command prompt.
  5. Start Jupyter by running the command jupyter notebook from the command prompt.
  6. In the Jupyter window, click on Computer Vision API Example.ipynb to open the tutorial notebook.

Run the notebook

To use this notebook, you will need a subscription key for the Computer Vision API. Visit Azure portal to sign up Either the primary or the secondary key will work. Be sure to enclose the key in quotes to make it a string.

You will also need to make sure the _region field matches the region that corresponds to your subscription.

# Variables
_region = 'chinanorth' #Here you enter the region of your subscription
_url = 'https://{}.api.cognitive.azure.cn/vision/v2.0/analyze'.format(_region)
_key = None #Here you have to paste your primary key
_maxNumRetries = 10

When you run the tutorial, you will be able to add images to analyze, both from a URL and from local storage. The script will display the images and analysis information in the notebook.