Skip to content

Instantly share code, notes, and snippets.

Last active November 25, 2022 20:36
What would you like to do?
flowchart TD
  Notes -.-> Problem-based
  Notes -.-> Observations
  Notes --You are here--> Logs[<strong>Logs</strong>]
  Notes -.-> Challenges
  Notes -.-> Electronics

  click Problem-based ""
  click Observations ""
  click Logs ""
  click Challenges ""
  click Electronics ""

Problem-based · Observations · Logs · Challenges · Electronics

Copy link

Log #2 · facegrep – my first Rust program 🚀

Last week (Nov 4, 2022) I wrote my first Rust program, facegrep. It's a command line program that detects a face from an image:

  1. Let's use the test image at assets/test/scientists.jpg
  2. Pass the test image to the command line: facegrep assets/test/scientists.jpg
  3. The command found 29 faces and created a new image at assets/test/scientists.jpg-facegrep.png
  4. Let's see the image and we'll see the red squares on each face
  5. Now, let's use the command to output json instead of image: facegrep assets/test/scientists.jpg --json | jq
  6. The command will show the array of face data (bbox and score) in json format


Here's how I got the idea.

I was checking twitter and saw a tweet from @levelsio:

and I thought, "maybe I can do it in Rust? Maybe someone has done the algorithm and I only need to port it to Rust?". After a quick search, I found about Rustface which fits the bill: it detects face, doesn't require GPU, no external dependencies (eg. dlib, opencv). In fact, it's a port of C++ library Seetaface which is a face recognition engine.

I started digging Rustface codebase and felt like I'am profiting from my learning: I know where to start my digging (I started from src/, how the type system works, and most importantly I wasn't afraid of looking at the codes. The codebase was modular so I know it's not going to be heavy work to just wrap the library in a command line.

I used examples/ as starting point. It detects faces from the test image and draw red boxes on each face, so I only need to:

  1. Change the test image to use the image from command line argument
  2. Add option to output json

You'll see the final code in file of the facegrep repo. As you may have noticed, I didn't actually do a lot of work. It was mostly reorganizing the existing code to fit my need. Nevertheless, it was a good exercise to practice what I learnt.

  • Do I want to learn even more Rust after this exercise?
    Yes, definitely. I was able to pick random repository (ie. Rustface) and figure out what it does. Rust codebase is no longer something scary to look at.
  • Should I continue learning from the same resource, with the same style?
    Yes, I should. From this exercise, I've seen that the knowledge I gained from the resources (see Log #1) has materialized easily in real use case.

That's it! I think I'm on the right path. Looking forward to learning more Rust 🦀


Note to self: took me 45 min to write this log.

Copy link

wzulfikar commented Nov 25, 2022

Log #3 · Books I want to read 📚

About design:

About software:


Might be good but still unsure:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment