This is my first post here - my name is Dan and I recently got into Rust; my background is (mostly) C++ for audio programming but I also have an interest in functional programming (have worked a little bit in Haskell and Clojure before). I love Rust's memory safety (coming from C++, it's a big thing!), smooth tooling experience and those language features (expression-oriented, algebraic data types, immutability by default etc.) that makes it "feel" a bit more like a functional language while still giving you all the power and performance of C++ (and the ability to work on audio plugins, which is pretty much exclusive domain of C++!).
I recently finished reading The Book and completed the Rustling exercises. I'm now looking to build a little command-line application that reads an image file and process it in some way (e.g. by converting it into ASCII art). It's nothing ground breaking I know, but I thought it'd be a fun little project to warm up.
So, coming to my question - as I'm not very familiar with the ecosystem yet, can anyone recommend a good image processing crate to use? And, similarly, what about a good crate for handling command line arguments? (I've seen something on crate.io but I don't know which ones are the best/most used/recommended)
You may find the opencv crate (which requires OpenCV libs to be installed and available) useful for the more advanced image processing it offers. I think it's also a bit more optimized than image - I found a while back that image resizing is ~2 times quicker with opencv than with image.
I'd like to read an image file and produce some ASCII art.
I think all I need in terms of image processing is being able to parse the image file into matrix of pixels.
Once I've got the matrix is all a matter of downsampling (discarding some pixels), calculating averages and then mapping numbers to chars, so there's no real image processing there
Hi and welcome. Sorry, I’m asking instead of answering. How long did it take you to complete The Book and Rustlings? I’m curious about the learning time for each person, especially for those with a C++ background.
Not sure I can provide a very precise answer, since I actually started a few months ago, then stopped for a couple of months, then started again
But I think overall (not considering the break) it took me about a month, maybe a month and a half. I tried to do the Rustlings exercises alongside the book, chapter by chapter.
Coming from C++ definitely gave me the background necessary for appreciating why things are done in a certain way in Rust, what are the goals, tradeoffs etc.
Also, having some familiarity with Haskell and functional programming helped a lot, since I was already familiar with algebraic data types, pattern matching, higher order functions etc.
The most difficult concepts to grasp for me was the ownership rules / borrow checker and lifetimes. This definitely takes a bit more to build a good intuition for (and I'm still working on it!).
But overall I can say it's been smooth learning experience so far!
EDIT: I forgot - I also still get confused about strings vs string slices, when to pass one or another as argument etc.
'clap' working great for me, very useful and smooth to use!
I took a look at your code.
Interesting how you double the image width before converting to ASCII in order to compensate for the fact that pixels are perfect squares while chars are more like rectangular (taller than wider).
I think we can get a similar result by just keeping the image proportions untouched and instead having each pixel map to 2 copies of the same char (horizontally).
But both methods work fine and give slightly different results. I think I'll keep both options and allow the user to chose via an option
I also tried to keep it more "functional style" using iterators as much as I could.