Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDelphiTech Partner

How To Use The DeepAI Service In Your Cross Platform Apps

How To Use The DeepAI Service In Your Cross Platform Apps
how to use the deepai service in the delphi app

Today AI technologies boast high popularity and demand in many spheres of our life. For example, AI is used for face identification on smartphones. On social networks, we have the possibility to add different effects on photos (AR, collages, etc.). AI tools allow users to identify different objects. They are used in video surveillance systems for identifying cars, people, animals, and all sorts of other useful capabilities.

In this article, we will analyze a popular multifunctional AI service, DeepAI, and show you how easy it is to use it in your cross platform apps. With the DeepAI service, users can enjoy all the capabilities and benefits of AI via a simple and straight-forward API. One DeepAI feature allows colorizing your old black-and-white photos. It can also identify some undesirable items in the photo (like weapons, etc) and provides many other possibilities.

We will show how you can easily use the DeepAI service in your Delphi FMX cross platform apps. To work with images, we suggest using the Image Colorization API.

 

How To Use The DeepAI Service In Your Cross Platform Apps Main Page Image Colorization API

What does the DeepAI Image Colorization API do?

This service for colorizing black-and-white photos is ensured by the API for work with images.

How To Use The DeepAI Service In Your Cross Platform Apps Description of Image Colorization API

For working via the API, it is necessary to send a POST request to the DeepAI server and to provide the path to the file of a black-and-white image and an API key. It is also required to use a link for connecting to the DeepAI Image Colorization API service.

How To Use The DeepAI Service In Your Cross Platform Apps Description how to use Image Colorization API in your apps

Get valuable insights on how clean and sharp photos are when implementing an image upscale using DeepAI’s Super Resolution API.

How do I get a DeepAI API key?

For getting an API key, you have to sign up. This process is rather simple. It is necessary to click SIGNUP.

How To Use The DeepAI Service In Your Cross Platform Apps How to signup

Then you have to enter the user name, email, and password.

How To Use The DeepAI Service In Your Cross Platform Apps Signup dialog

After that, you will receive a link for account verification on your email. You will just have to follow the link.

How To Use The DeepAI Service In Your Cross Platform Apps DeepAI API key

You need to copy the received API key and save it for further use in the FMX Delphi app.

You will also have to add bank card details (card number, the date of expiration, CVV) for correct interaction with the service (the tab Billing). DeepAI offers a free trial limit of 5 dollars.

How To Use The DeepAI Service In Your Cross Platform Apps Billing information

How to use DeepAI in a Delphi FMX cross platform App

As an example, we will send a black-and-white photo from our Delphi FMX app with the use of the POST request to the server and will get a response in the JSON format that keeps the URL link leading to the processed colorful image.

In Delphi, for working with the DeepAI server, we can use some standard components TNetHttpRequest and TNetHttpClient. We have to assign the value of the current TNetHttpClient component (NetHttpClient1) to the Client field in the TNetHttpRequest component. We also need to assign the value “POST” to the MethodString field.

How To Use The DeepAI Service In Your Cross Platform Apps NetHttpRequest and NetHttpClient components settings

How do I display the DeepAI image colorization results in a Delphi cross platform app?

We will use the standard component TImage for showing the original black-and-white image in the FMX app.

How To Use The DeepAI Service In Your Cross Platform Apps TImage component for black and white image

For showing the processed colorful image to a user with the help of the REST of the DeepAI service, we also have to use the standard component TImage.

How To Use The DeepAI Service In Your Cross Platform Apps TImage component for black and color image

For showing the JSON reply from the server in the Delphi FMX app, we will use the standard component TMemo (the tab Standard).

How To Use The DeepAI Service In Your Cross Platform Apps TMemo component for keeping JSON response

For sending the parameters via the POST request to the server, such as the API key, the path to our black-and-white image on the computer, we should use the following variables.

Sending the DeepAI API request to the server

The variable (object) of the  TName ValuePair header class will be used for sending our API key REST to the DeepAI server.

How To Use The DeepAI Service In Your Cross Platform Apps TNameValue variable containing API key

The LMultiPartFormData object of the TMultipartFormData class is used for sending our black-and-white image following its path on the computer. A line variable path saves the path to our image file.

The path to the image differs on MSWindows and Android. That’s why conditional compilation is applied for these platforms.

During the compilation for MSWindows, our image file is stored on the C disk (c:Einstein.jpeg). 

On Android, the image file will be stored in the internal memory of the smartphone in the Pictures folder.

How To Use The DeepAI Service In Your Cross Platform Apps Black and white image path on Windows and Android

For loading the original black-and-white image to the TImage component, the LoadFromFile method is used. As a parameter, it takes a variable path.

The line variable path stores the name and the path to the image file.

How To Use The DeepAI Service In Your Cross Platform Apps TImage components LoadFromFile method

For executing the POST request and sending all the necessary data (a path to the image file, an API key) to the server, we need to use the POST method of the NetHTTPRequest1 component.

How To Use The DeepAI Service In Your Cross Platform Apps TNetHttpRequest components POST method

The method receives a link for connecting to the server, the LMultiPartFormData object that stores the path to the image file, the LMS object of the TMemoryStream class and the header variable with the API key.

How To Use The DeepAI Service In Your Cross Platform Apps TNetHttpRequest components POST method input parameters description

The LMS object is used for saving the reply received from the server in a JSON format.

How To Use The DeepAI Service In Your Cross Platform Apps TMemoryStream variable

The received JSON reply from the server will be displayed in TMemo with the help of the LoadFromStream method.

How To Use The DeepAI Service In Your Cross Platform Apps TMemo components LoadFromStream method

The JSON response from the server includes the URL link to the file of the processed colorful image (theoutput_url parameter).

How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI server with url link to color image

How to parse the DeepAI API JSON results into an image?

For loading a colorful image, it is necessary to get the URL link from the JSON reply from the DeepAI server via parsing.

For reply parsing, we should use the JSON object of the TJSONObject class.

As a result of parsing the JSON reply from the server, we will get the URL link and save it in the line variable ColorizedImagePath.

How To Use The DeepAI Service In Your Cross Platform Apps Parsing JSON response

For downloading a colorful image from the server, we need to use the GET method of the TNetHttpClient component.

How To Use The DeepAI Service In Your Cross Platform Apps TNetHttpClient GET method for color image downloading to TMemoryStream object LResponse

The GET method accepts the URL link of the colorful image in the server and the object of the TMemoryStream LResponse class. In our case,  LResponse  gets the colorful image from the server for its further display in TImage.

How To Use The DeepAI Service In Your Cross Platform Apps TMemoryStream object description

For loading and displaying a colorful image, we will use the method of the TImage LoadFromStream component.

How To Use The DeepAI Service In Your Cross Platform Apps TImage components LoadFromStream method for color image showing to a user

 

Is there a Delphi example of using DeepAI to colorize images?

Here is some example Delphi program code of sending a request to DEEPAI and then loading the results into an image.

Are there any special considerations for Delphi Android apps when using DeepAI?

For the correct functioning of the Delphi FMX app on the Android platform, we need to install permissions for access to smartphone memory and internet connection.

Check out how these speech services by Google could be vital for the success of your business operations.

How To Use The DeepAI Service In Your Cross Platform Apps Access to internet permission on Android
How To Use The DeepAI Service In Your Cross Platform Apps Write to external storage permission on Android

Let’s test the work of our Embarcadero Delphi FMX app on the MSWindows and Android platforms. Let’s send a black-and-white picture and get a processed colorful image from the DeepAI server.

How To Use The DeepAI Service In Your Cross Platform Apps Original black and white image
How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI
How To Use The DeepAI Service In Your Cross Platform Apps Color image from DeepAI server
How To Use The DeepAI Service In Your Cross Platform Apps Original black and white image 2
How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI 2
How To Use The DeepAI Service In Your Cross Platform Apps Color image from DeepAI server 2
How To Use The DeepAI Service In Your Cross Platform Apps Original black and white image 3
How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI 3
How To Use The DeepAI Service In Your Cross Platform Apps Color image from DeepAI server 3

What does the Delphi Android FMX DeepAI cross platform example results look like?

Let’s test the work of the FMX app on an Android device.

How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI Android device
How To Use The DeepAI Service In Your Cross Platform Apps Original black and white image Android device
How To Use The DeepAI Service In Your Cross Platform Apps Color image from DeepAI server Android device

Watch step by step guide on the Softacom Youtube channel

https://www.youtube.com/embed/r4v8WYS3hRA

This article was written by Softacom, one of our excellent Embarcadero Tech Partners.

You can read more about Softacom’s AI implementation services by clicking this link: https://softacom.com/services/artificial_intelligence_implementation_with_delphi/

Why not download a free trial of Embarcadero Delphi today and try the DeepAI example for yourself?

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES