The goal of this project was to get familiar with an Amazon Web Service, in particular the Amazon Rekognition Client. The Client was used to detect famous people on a captured image and display some information about the recognized celebrities.
Before starting to code I had to set up an Amazon Account by following the instructions on this link. After everything was set up, I wanted to get any kind of response from the AmazonRekognitionClient. The client accepts a BasicAwsCredentials object in its constructor, which contains the access and secret key obtained in the AWS registration process. Now, after capturing an image, the resulting Bitmap has to be converted into a ByteBuffer before it can be sent to the RekognitionClient. The recognition procedure can be initialized using this code snippet:
The RekognitionClient returns a RecognizeCelebritiesResult which contains recognized and unrecognizedFaces. If the faces are recognized, the Client provides the names of the celebrities and IMDB URL to the page of the celebrity and some meta-information about the captured faces.
Now that we have obtained the names of our celebrities from the image, it is time to extract some data. The initial idea was to parse the HTML document from the gotten IMDB URL in the RecognizeCelebritiesResult.recognizedFaces, but it turned out that not all celebrities had an IMDB page. Thankfully, there is a web page that contains some information about every famous person ever – Wikipedia.
After generating a Wikipedia URL for the recognized celebrity, it is time to extract some valuable data from the corresponding HTML document. I choose to extract the image URL of the person and the birth date. That is where the library Jsoup comes in handy.
My local Celebrity model:
Let us take a look at the parsing of the imageUrl, by taking a look at the corresponding part of the image in the HTML document:
With Jsoup I could extract any wanted tag or attribute from the HTML document, using CSS Queries. By looking at the above HTML, all that needed to be done is to write the corresponding Jsoup query:
The parsing of the HTML can take some considerable time, as much as 1s, so I decided to create a separate thread for the creation of each recognized celebrity using the async – await in kotlin coroutines:
After the model was successfully created, I displayed the fetched data in a RecyclerView and added a WebView fragment for each tapped Celebrity, which redirected the user to the Wiki page for more details.
In conclusion, after some issues with the AWS setup, the Amazon Rekognition Service was really easy to use. All the valuable data is stored in well named attributes. The only challenging part was to figure out how to extract certain fields from the Wiki HTTP document, but after studying the library JSON, that was also a breeze.
You can check out the screenshots and download the app from this link.
Also, feel free to check out the project on this GitHub page: