Watson: Detect Faces

In this tutorial, we're going to use the Watson Developer Cloud API to detect faces in images. This project uses python.

Sign up for IBM Cloud

This tutorial uses Watson Visual Recognition. You can sign up for the IBM Cloud Lite account for free! Just click the button below to register.

IBM BLUEMIX LITE
  • Check the Catalog

    Click the Catalog link on the IBM Cloud menu bar. Scroll down and click on Visual Recognition.

  • Set up IBM VR

    Type your app name in the Service Name textbox. Select the region closest to you, your organization and space. Choose the Free pricing plan and click Create.

  • Get your API

    Click on Service Credentials. Select the New Credential button, give it a name, and click Add. Now click View Credentials and note your "api-key":.

Let's Hack it Up!

Make sure you've installed nuOS. When you're ready, scroll down!

  • Launch Atom.

    Fire up Atom.

    Create a new file by clicking File, and then New File.

  • Import the Libraries

    To use Watson Developer Cloud and the Visual Recognition API, we need to import the library:

    from watson_developer_cloud import VisualRecognitionV3
    from watson_developer_cloud import VisualRecognitionV3
     
  • Connect to Watson

    Now lets add our API Credentials:

    # API Setup
    vr = VisualRecognitionV3('2017-10-14', api_key='YOUR CREDENTIALS HERE')
    # API Setupvr = VisualRecognitionV3('2017-10-14', api_key='YOUR CREDENTIALS HERE')
  • Make the Call

    Finally here's the call:

    # Detect Faces by URL
    results = vr.detect_faces(images_url="YOUR URL HERE")
    print(results)

    Now save your file as detect.py, by clicking File and Save As. To run your program, open up Terminal by holding Ctrl + Alt + T. Then type:

  • Full Source

    Here's the full source:

    from watson_developer_cloud import VisualRecognitionV3
    
    # API Setup
    vr = VisualRecognitionV3('2017-10-14', api_key='YOUR CREDENTIALS HERE')
    
    # Detect Faces by URL
    results = vr.detect_faces(images_url="YOUR URL HERE")
    print(results)

     

    from watson_developer_cloud import VisualRecognitionV3# API Setupvr = VisualRecognitionV3('2017-10-14', api_key='YOUR CREDENTIALS HERE')# Classify an Image by URLresults = vr.classify(images_url="YOUR URL HERE")print(results)
DETECT TEXT WITH WATSONcoming soon

That's it! Pretty easy huh? Why don't we learn how to detect text with Watson.