Gary, our fictive business expert, works in an upgrowing company. Each morning he has to check uploaded images from new customers. Some jokers sends an image from their cat or dog. He needs on average 30 minutes each morning for circa 50 images, sometimes more sometimes less. Mary his colleague, also a fictive business expert at this company, started last weekend a marketing campaign in a social network. When Gary starts working on this Monday morning he is scared, several hundred of images. The marketing campaign was a complete success. Now Gary asks himself, how he can quickly and effectively view the images and take the necessary action. Here now one possibility:
To detect if an image contains one human face we can use machine learning. In this example we use Accord.NET, a machine learning framework combined with audio and image processing libraries. It is a complete framework for building production-grade computer vision, computer audition, signal processing and statistics applications. It includes a vision library which offers the possibility to detect human faces. AccordDotNET includes a phantastic help and great examples, so that it is very easy to use.
At first we add the AccordDotNET packages to our UiPath project, in this case Vision and Imaging.
Then we start with an Invoke Code activity to detect a human face in an image.
You can find this example with detailed explanations in the help file.
Dim Image As System.Drawing.Image Dim Bitmap As System.Drawing.Bitmap Image = System.Drawing.Image.FromFile(i_file) Bitmap = New Bitmap(Image) Dim Cascade As Accord.Vision.Detection.HaarCascade Cascade = New Accord.Vision.Detection.Cascades.FaceHaarCascade() Dim Detector As Accord.Vision.Detection.HaarObjectDetector Detector = New Accord.Vision.Detection.HaarObjectDetector(Cascade, 50) Detector.SearchMode = CType(2, Accord.Vision.Detection.ObjectDetectorSearchMode) Detector.ScalingMode = CType(1, Accord.Vision.Detection.ObjectDetectorScalingMode) Detector.ScalingFactor = 1.5 Detector.UseParallelProcessing = True Dim Result As System.Array Result = Detector.ProcessFrame(Bitmap) Console.WriteLine(i_file) If Result.Length = 0 Then Console.WriteLine("No face detected") ElseIf Result.Length = 1 Then Console.WriteLine("One face detected") ElseIf Result.Length > 1 Then Console.WriteLine("More faces detected") End If
We embed this routine inside a loop. On this way we have the possibility to process an entire directory with images.
To get all files in a directory we create a sequence which contains a few settings like path and pattern like *.jpg or *.png and a tiny Invoke Code routine.
Dim Extension As String Dim File As String Dim Files() As String For Each Extension In i_pattern Files = System.IO.Directory.GetFiles(i_path, Extension) For Each File In Files o_files.Add(File) Next Next
The result of the face detection is okay.
With this tiny routine Gary saves now a lot of time. He only has to look at the problem cases with no or multiple faces. Also this example shows us, how easy it is to implement machine learning algorithms
into UiPath. And the many other possibilities of machine learning that we can now easily integrate into our automated business processes. That promises a lot of potential. Thank you UiPath for giving us this path.
Main.xaml (10.1 KB)