Hawk: Image Recognition Application using Rust and AWS Services

Rust is one of the newest kid on the block in the modern programming languages. We tried to take advantage of its great features by using it in an Image Recognition blueprint project. This project can be traded with any existing security system deployed at any organization. Hawk uses AWS services integrated with Rust.

Starting with Rust

Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.

Rust’s rich type system and ownership model guarantee memory-safety and thread-safety — and enable you to eliminate many classes of bugs at compile-time.

Rust has great documentation, a friendly compiler with useful error messages, and top-notch tooling — an integrated package manager and build tool, smart multi-editor support with auto-completion and type inspections, an auto-formatted, and more.

Basic model

https://s3.ap-south-1.amazonaws.com/uploadbucket1234/Untitled%20Diagram%283%29.jpg?response-content-disposition=inline&X-Amz-Security-Token=AgoGb3JpZ2luEMP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDmFwLXNvdXRoZWFzdC0yIoACW7ahx0y88UVtxTXkXl%2BDjpOnLxdNtpg4wbEOTHbJadoVDjxyJ2yFRWnVDUiQOsKZJlqqB%2F5ECbzXF9EsixVesg2qJd7GN7IyF4esyuRGwCkZfnLk1zldKteDwbHkEWSBHhSPGnVtXcMQHYrehk6Kk3ceSCWLIU0bJ7ntRc8VIAK3EQfI2dv9uk1wplwxe5L5jTEH64NUrp2DO0IwtQd%2BpzB%2F2x%2FYyyMzlDCPqAx6JNOMxgsOrC%2BY9AsizK%2FN9menob%2BxYcPugBGi36UB6CLPqarxh%2FWTYEszUwLPHMdh89IIyO9WyEynp9BrFWlNlYjONP4nZ%2FP3r8MGDrSC%2FwmL0SrbAwhZEAAaDDAxNzY1NDEwODg5MiIMlY4QMqQ9Yi1nUT9sKrgDnClFOWasRW0J5jSVehxMglhlT8DcVL5s3HsS5gP8txAJliYS307rqxoaN%2B4ZF5pC9NhCkddR%2FBp%2Bv%2F6uXohg9hDQEXrCnGEset%2FF9LECfTM3yo7Ezf19ThJ5yT%2Be1d2HWsfLRC%2FOXwibY3oz884db1RMCI3Qwz7JEGhEBe%2FP3pBvmb32pgIvtpzdxlwBDCRns0l9j36F6zaukg0V1HDM6P6UUQYS9oX573SWWv04Ad4yvU1yOhWwM3u1X0hjoMcFkrFhj%2FBoum09%2FpqlJ4waPdCt305uFjlv11MoSKFX%2Fponm0rW432V8P8sLKIFLZ2uai6mcj9bz3FW7wxCnE5%2B5MsMukgDbH2TEqLXy5r7Hfhym11rZkoQCFuiuM2yyYuCR8a4oA%2FAXlI323Fa9l1ll6sXTPq9rZ61aUgPF8TGdOZdG8Ho1v3B6ImIIEvXg22Z6qbf5XyLzEwcOqGjuX7FzWmH2j7a4VlyoAGfYOpWzksirTHdUXqcbe9qiEncyS1UVxz0nGJVW5GOhrjWTihrbuWP33JILasw%2BgAK1OlFAg%2BVC05KF3GgJm6RCgvPJluBgMSQTMm9BdQwioqa5gU%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20190429T075338Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Credential=ASIAQIHCEKLOITKKV5PQ%2F20190429%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Signature=b1ad687ccfa46dcd768e2a8eca8edccb14a1c3c69aa7500c1d43a7b27331d422

Hawk uses 2 way authentication process

  1. RFID authentication
  2. Image authentication

The basic flow of the project includes authenticating the RFID of an employee and then the image.

If the RFID is known to the system, the image recognizer will be triggered. If the image matches with the RFID card owner, the system will respond in the affirmation.

You might be thinking, how do all these things stack up to give us the desired results? Don’t worry, we will be discussing that in our next segment.

Technical overview

AWS S3 Bucket

Firstly, we set up two S3 Buckets (AWS service to store data). The first one stores the reference images of employees (Reference_Images) and the other one all the clicked images(Clicked_Images).
This project uses S3 Bucket for storing the images of all the employees of the organization. As soon as the system passes the first authentication process i.e if the card is a valid RFID card, the clicked image is sent to the Clicked_Images bucket.
Now, comes the AWS Lambda (Another AWS Service).

AWS Lambda Function

Image result for aws lambda

AWS Lambda stores a function in Java. It accepts the clicked images from the Rust Application and the Employee code from the RFID Card. It then fetches the employee’s image from the Reference_Image bucket. Both the images are sent to the Image Rekognition for Recognition process.

AWS Rekognition

Image result for amazon rekognition image

AWS Rekognition is an AWS service that helps compare two images and get a similarity score. Hawk uses CompareFace API that returns a similarity score back to Rust as a response.

Asynchronous Hawk

For achieving our goal of faster response, the project is built using futures. By using futures, we make sure that the two tasks – hitting the API Gateway and uploading the clicked image to S3 Bucket, are done asynchronously. This enables the user to get the response from the API Gateway in 1-2 seconds.

Dockerizing Rust Application

Image result for docker

Docker is an open source program that performs OS-level virtualization. It was first released in 2013 and is developed by Docker Inc. It is the most common and widely used Containerization platform. The Hawk project has been containerized for making it available to build once and run anywhere.

Verification

Rust gets the similarity score as a response and the final step is based on the threshold set by the AWS Lambda code i.e 80% in our case. If the returned image similarity is more than 80%, the system accepts you as a verified person.

Architecture Design

https://i0.wp.com/s3.ap-south-1.amazonaws.com/uploadbucket1234/arch.png?w=810&ssl=1?response-content-disposition=inline&X-Amz-Security-Token=AgoGb3JpZ2luEMP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDmFwLXNvdXRoZWFzdC0yIoACW7ahx0y88UVtxTXkXl%2BDjpOnLxdNtpg4wbEOTHbJadoVDjxyJ2yFRWnVDUiQOsKZJlqqB%2F5ECbzXF9EsixVesg2qJd7GN7IyF4esyuRGwCkZfnLk1zldKteDwbHkEWSBHhSPGnVtXcMQHYrehk6Kk3ceSCWLIU0bJ7ntRc8VIAK3EQfI2dv9uk1wplwxe5L5jTEH64NUrp2DO0IwtQd%2BpzB%2F2x%2FYyyMzlDCPqAx6JNOMxgsOrC%2BY9AsizK%2FN9menob%2BxYcPugBGi36UB6CLPqarxh%2FWTYEszUwLPHMdh89IIyO9WyEynp9BrFWlNlYjONP4nZ%2FP3r8MGDrSC%2FwmL0SrbAwhZEAAaDDAxNzY1NDEwODg5MiIMlY4QMqQ9Yi1nUT9sKrgDnClFOWasRW0J5jSVehxMglhlT8DcVL5s3HsS5gP8txAJliYS307rqxoaN%2B4ZF5pC9NhCkddR%2FBp%2Bv%2F6uXohg9hDQEXrCnGEset%2FF9LECfTM3yo7Ezf19ThJ5yT%2Be1d2HWsfLRC%2FOXwibY3oz884db1RMCI3Qwz7JEGhEBe%2FP3pBvmb32pgIvtpzdxlwBDCRns0l9j36F6zaukg0V1HDM6P6UUQYS9oX573SWWv04Ad4yvU1yOhWwM3u1X0hjoMcFkrFhj%2FBoum09%2FpqlJ4waPdCt305uFjlv11MoSKFX%2Fponm0rW432V8P8sLKIFLZ2uai6mcj9bz3FW7wxCnE5%2B5MsMukgDbH2TEqLXy5r7Hfhym11rZkoQCFuiuM2yyYuCR8a4oA%2FAXlI323Fa9l1ll6sXTPq9rZ61aUgPF8TGdOZdG8Ho1v3B6ImIIEvXg22Z6qbf5XyLzEwcOqGjuX7FzWmH2j7a4VlyoAGfYOpWzksirTHdUXqcbe9qiEncyS1UVxz0nGJVW5GOhrjWTihrbuWP33JILasw%2BgAK1OlFAg%2BVC05KF3GgJm6RCgvPJluBgMSQTMm9BdQwioqa5gU%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20190429T075606Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Credential=ASIAQIHCEKLOITKKV5PQ%2F20190429%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Signature=0057880f945e9be76f7498af739aa7a17a3a187198fe6a8018afe13aee761a6e

Thank you for coming this far in the blog. If you have any suggestions for the blog/project, you can surely give your comments.

For more reference and contributing to our open source project Hawk, you can visit here. Here is demo video working of Dockerized Hawk Application on a Linux machine.


Knoldus-blog-footer-image

Leave a Reply

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!