It’s time for the third in our series of articles about Grid for Apps, the event-driven framework that is part of the OpenIO SDS object storage solution. For those who missed the previous articles, here’s a link to the first article A Technical Introduction to Grid for Apps, and to the second one Simple Metadata indexing through Grid for Apps.
In this article, we will tackle a common use case often raised by some of our customers. How can we recognise patterns in pictures at scale? By “scale,” we mean when you are storing billions of files. We have prepared three possible scenarios, using the most common open-source. One has been showcased during our webinar on May 24 with Tensorflow. The following week, we will do the same using the deep learning framework Caffee.
But let's start with OpenCV. We will use it to detect faces in pictures and localize them. Using our event-driven processing framework, we will use this framework to analyse each object that is uploaded; a pre-trained neural network will detect people in images. As usual, we will enrich the object with new metadata: the number of faces detected, their location, and the sizes of the images. If you think about it, there are many use cases for this sort of procedure: face blurring, face detection for CCTV, or like the cover picture you can see behind.
As a side note, using Elasticsearch, presented in the second article, we will demonstrate how you can build more complex workflows with OpenIO Grid for Apps technology: store, enrich, index, and search!
Let’s do it!
As in our previous articles, we will use our docker container image to easily spawn an OpenIO SDS environment. Retrieve the OpenIO SDS Docker image:
Start your new OpenIO SDS environment:
You should now be at the prompt with an OpenIO SDS instance up and running.
Next, we will configure the trigger, so each time you add a new object, the metadata from the object will be pushed to Elasticsearch. Add the following content to the file /etc/oio/sds/OPENIO/oio-event-agent-0/oio-event-handlers.conf:
If you want to learn more about this configuration file, please refer to our previous blog post.
Then, restart the openio event agent to enable the modification:
Your event-driven system is now up and running. The next step is to write the script that will analyse objects using OpenCV. To do so, we will need first to install the OpenCV python module:
Download the pre-trained neural network:
Then write the script; let’s call it detect-faces.py:
Finally, launch it in background:
Please note that the script is written in Python, but you can write it any other language.
How does it work?
It’s time to add a new picture to see if the process works. First, download a picture to upload it to OpenIO. Let's use the family picture we took during our last hackathon:
Using the OpenIO CLI, let’s upload this new object family.jpg to the container mycontainer in the account myaccount:
Well done! You’ve just uploaded the picture and OpenCV was launched as a background task to process it. Now, and to conclude, let’s check the metadata added to the object:
We obtain the following result:
As you can see, OpenCV detected 10 faces meta.face_number = 10 with their following position and size (x,y,w,h) in meta.position.