Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
Machine Learning is not new to us now. It helps the system\code by providing an ability to make decisions based on prior experience and learnings.

In this blog, I will be sharing the steps to use the Microsoft Azure Computer Vision API within SAP UI5.

To go ahead with it we need few pre-requisites:

  1. SAP Web IDE account

  2. Microsoft Azure account (

  3. Understanding of SAP UI5/Javascript/Jquery

We will start with creating our UI5 application.

SAP UI5 application project structure looks like above.

Below is the code of each file

  • index.html

<!DOCTYPE html >
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="UTF-8">
<title>Microsoft ML with SAPUI5</title>
data-sap-ui-resourceroots='{"sapml.microsoftml": "./"}'>

sap.ui.getCore().attachInit(function () {
viewName: "sapml.microsoftml.view.App"
<body class="sapUiBody" id="content">

  • App.view.xml

<mvc:View displayBlock="true" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout"
<Page title="Microsoft Machine Learning\ Computer Vision"
<subHeader height="150px">
<l:HorizontalLayout class="sapUiSmallMargin">
<Image class="sapUiSmallMarginEnd" src=""
densityAware="true" width="100px" height="100px" alignItems="Start"></Image>
<FlexBox height="50px" width="90%" alignItems="End" justifyContent="End">
<Panel expandable="true" expanded="false" headerText="Computer Vision" width="auto" class="sapUiResponsiveMargin">
<l:VerticalLayout width="100%">
<Label text='Image' level="H3" class="sapUiSmallMarginEnd" design="Bold"/>
<Input id="imgInput" type="Text" placeholder="Enter Image URL ..."/>
<Button text="Magic" icon="sap-icon://activate" width="150px" press="onClick"/>
<Text id="output" class="sapUiSmallMarginEnd"/>
<Text id="celebrity" class="sapUiSmallMarginEnd"/>
<Text id="landmark" class="sapUiSmallMarginEnd"/>
<Text id="responseTextArea" class="sapUiSmallMarginEnd"/>
<Image id="dispImage" class="sapUiSmallMarginEnd" width="100%" height="100%" densityAware="true" alignItems="Start"></Image>

  • App.controller.js

], function(Controller, MessageToast) {
"use strict";
return Controller.extend("sapml.microsoftml.controller.App", {
onInit: function() {
// set mock model"Welcome Guest");

onClick: function() {
// set mock model
var url = this.getView().byId("imgInput").getValue();"Searching " + url);

var view = this.getView();

// Replace the subscriptionKey string value with your valid subscription key.
var subscriptionKey = <replace this with your subscription key>;

// Replace or verify the region.
// You must use the same region in your REST API call as you used to obtain your subscription keys.
// For example, if you obtained your subscription keys from the westus region, replace
// "westcentralus" in the URI below with "westus".
// NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using
// a free trial subscription key, you should not need to change this region.
var uriBase = "";

// Request parameters.
var params = {
"visualFeatures": "Categories,Description,Color",
"details": "",
"language": "en"

// Display the image.
var sourceImageUrl = url;

// Perform the REST API call.
url: uriBase + "?" + $.param(params),

// Request headers.
beforeSend: function(xhrObj) {
xhrObj.setRequestHeader("Content-Type", "application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);

type: "POST",

// Request body.
data: '{"url": ' + '"' + sourceImageUrl + '"}'

.done(function(data) {
// Show formatted JSON on webpage.
var jsonModel = JSON.stringify(data, null, 2);
var description = JSON.parse(jsonModel);
if (JSON.stringify(description).indexOf("celebrities") > -1) {
view.byId("celebrity").setText("Celebrity: " + description.categories[0].detail.celebrities[0].name);
if (JSON.stringify(description).indexOf("landmarks") > -1) {
view.byId("landmark").setText("LandMark: " + description.categories[0].detail.landmarks[0].name);

.fail(function(jqXHR, textStatus, errorThrown) {
// Display error message.
var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): ";
errorString += (jqXHR.responseText === "") ? "" : jQuery.parseJSON(jqXHR.responseText).message;



Make sure you change the highlighted text in App.controller.js file with the API subscription key provided to you after creating an account with Microsoft Azure:


That's it...! Now our SAP UI5 Image processing application is ready. Let us see how it works.

The initial page of the application looks like below:

You need to provide the URL of the image available over the internet in the Input Box and click on the button available below.

Lets us check for the Tajmahal image and see what the application returns in the output

The highlighted text is the output for the URL of image entered in the Input box. As we can see our application is correctly predicting the contents of the image. Looks cool right?


Let's check with something else.

And here it is... Our application correctly identifies the celebrity figure also.

Here is few more screenshot of output with different images.





So we can conclude that it's easy and pretty cool to start with image processing in SAP UI5. To learn more about this and other different ML services you need to make your hands dirty with coding. You can refer the below link to the API Sheet for this service.

Happy Learning....!
Labels in this area