Skip to content

Instantly share code, notes, and snippets.

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

  click Problem-based "https://gist.github.com/wzulfikar/ba2f58d7aeeb3cf53743316f96f91594"
  click Observations "https://gist.github.com/wzulfikar/2cff9bcd64ba5f15296e0b57ff402f79"
  click Logs "https://gist.github.com/wzulfikar/5ea5779d7f2ea0e27809e94e7904f93d"
  click Challenges "https://gist.github.com/wzulfikar/7d5e9426d1c7efc3ceeabb29adb2f4fd"
  click Electronics "https://gist.github.com/wzulfikar/16c3b5f10b8f28d8b0e325d03c948d1c"

Problem-based · Observations · Logs · Challenges · Electronics

@wzulfikar
Copy link
Author

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
Screen.Recording.2022-11-13.at.11.42.59.mov

▲▼▲

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/lib.rs), 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/image_demo.rs 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 main.rs 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.

@wzulfikar
Copy link
Author

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