Classify images through filtering and categorization

Real-time analysis of images in any application


Quick start

Make sure you’ve read Getting Started.

About

The image recognition API adds image analysis to your application. Gain insights in images and classify them in any category. Automatically add labels to images and organize your content. You can make images searchable using categorization and filtering. This API is capable of detecting multiple objects.

The image classifier is provided as is, and the images classifications have around 90% accuracy on non-domain specific images. Future versions of the API can offer training on provided images.

How it works

To get started and test the API from your local workstation you can use Postman or our API Reference (powered by SwaggerHub) or cURL as an HTTP client. If you use the Postman collection or API Reference, make sure you update the environment settings with your credentials in order to authenticate.

 

 

If you use cURL scroll down to see the examples.

The following diagram shows how the image recognition flow works.

 

Connect to the API

To start testing the API you need to get authorization credentials. Log in to your account and create a developer app on the My Apps page. The steps to create a developer app are briefly discussed under 'Support' 🡆 'Frequently Asked Questions'.

 

Get access token

Copy your app's credentials and replace APP_CONSUMER_KEY and APP_CONSUMER_SECRET with the copied values, then execute the below cURL command to receive access token.


curl -X POST \
 'https://api-prd.kpn.com/oauth/client_credential/accesstoken?grant_type=client_credentials' \
 -H 'content-type: application/x-www-form-urlencoded' \
 -d 'client_id=APP_CONSUMER_KEY&client_secret=APP_CONSUMER_SECRET'

Note: If you are using cURL for Windows then please use below command.


curl -X POST "https://api-prd.kpn.com/oauth/client_credential/accesstoken?grant_type=client_credentials" -H "content-type: application/x-www-form-urlencoded" -d "client_id=APP_CONSUMER_KEY&client_secret=APP_CONSUMER_SECRET"

The authorization service returns a JSON message that contains the access token field.

{
    "refresh_token_expires_in": "0",
    "api_product_list": "[Image Classifier - KPN]",
    "api_product_list_json": [
        "Image Classifier - KPN"
    ],
    "organization_name": "kpn",
    "developer.email": "demo123@kpn.com",
    "token_type": "BearerToken",
    "issued_at": "1521039195424",
    "client_id": "2Xvp2YLhEeT8w4cXQWvKuOpMoHQQ9zGx",
    "access_token": "haf2SDl07E9N7RluNQ4kJ1TkGgso",
    "application_name": "6e38ed2d-48b1-4362-97d6-04254065d79c",
    "scope": "",
    "expires_in": "3599",
    "refresh_count": "0",
    "status": "approved"
}

 

Recognize an image using access token

Copy your access_token and replace access_token with the copied value, then you can execute the cURL command and recognize an image by calling the Classify endpoint of the Image Recognition API.

You can use same token to make multiple 'Image Recognition API' calls, provided the token is active. If the token expires then you can repeat the above step 'Get access token'.

curl -X POST \
  https://api-prd.kpn.com/ai-machine-learning/kpn/image-classifier \
  -H 'authorization: BearerToken access_token' \
  -H 'content-type: application/json' \
  -d '{
  "data": [{
    "ext" : "jpg",
    "path" : "http://www.babushahi.com/upload/image/Train-Engine_HKM.jpg"
  },{
    "ext" : "jpg",
    "path" : "https://upload.wikimedia.org/wikipedia/commons/0/0e/Atlanta_Zoo_Panda.jpg"
  }]
}'

Note: If you are using cURL for Windows then please use below command.


curl -X POST "https://api-prd.kpn.com/ai-machine-learning/kpn/image-classifier" -H "authorization: BearerToken access_token" -H "content-type: application/json" -d "{\"data\":[{\"ext\" : \"jpg\",   \"path\" : \"http://www.babushahi.com/upload/image/Train-Engine_HKM.jpg\"},{\"ext\" : \"jpg\",  \"path\" : \"https://upload.wikimedia.org/wikipedia/commons/0/0e/Atlanta_Zoo_Panda.jpg\"}]}"