How do I work with shapes and patterns in images


I’m thinking about creating a web service (hopefully open sourcing it) using Elixir and Phoenix. You would upload images to it, using an interface or API, and then you can fetch those images in different sizes etc (think

Uploading etc. is quite easy.
Cropping images is quite easy (shelling out to ImageMagick or something).

One feature that would be nice to have is some kind of smart cropping, where it would choose the area to crop by finding faces or other “things” in the image.

Finding faces etc. is possible using OpenCV, but I’m not sure how easy it is to integrate so I have a few questions.

  1. Are there any libraries to do image manipulation directly in Elixir? (Is it even a good idea? :slight_smile: )
  2. Are there any libraries to do image analysis in Elixir? Like finding faces etc. (Is it even a good idea? :slight_smile: )
  3. What would be the best way to integrate with OpenCV? There is no CLI AFAIK, so I guess I’d need to write some Port/NIF to call C++ functions?

The reason for wanting to do 1 and 2 above in Elixir is to avoid annoying external dependencies of course. However, it’s not a deal breaker if I need to install some dependencies.

Any thoughts?

1 Like

I would write a small command line program to handle image processing entirely, Elixir/Erlang is not suitable for number crunching which is essentially what image processing is. You can make an opencv based program to find interesting region, then give the output to imagemagick for cropping/resizing.

1 Like


Yes, it sounds reasonable to just create a small C++ CLI that I can call from elixir. I don’t have much experience with C++, would it be possible to compile such a command line program to a static binary for easy deployment? So I don’t have to mess with too many dependencies on the server.

I also found thumbor: which does pretty much the same as I want to do, but in Python. The good thing with Python here is that there are very good OpenCV libraries in Python.

I also just found Microsoft Cognitive Services Face API which looks pretty neat. Perhaps I’ll just use that instead of OpenCV.

(I know I can just use thumbor, but I’m looking for a more advanced Elixir project for learning :slight_smile: )

1 Like

With C++ anything is possible :slight_smile: So yes you can make a static binary that bundles opencv. I did something similar with ffmpeg.

1 Like

check out - bootstrap elixir code to interface opencv(through python)… so might be useful.

If you succeed in image recognition etc. a good path would be to figure out how to plug it into - also look at how that uses imagemagick for thumb generation etc.


write your image processor in GO… That’s what I’ve seen a lot of people doing…

Hi guys,

This is exactly what I am looking for: how to create images with blog titles in Elixir?

I have some experiences in python and ruby, and low level c.
@outlog is right.

Python could be helpful to do the job, because of great libraries and especially related to graphics.
Elixir could communicate with Pyton scripts in that case. Python is on almost all servers available and easy to run.
Go and Elixir on one server? That sounds interesting too.

How they do that?
Do you know solutions using GO together with Elixir/Phoenix? I have to build image generator with embedded titles from blogs.That would be part a of bigger project in Elixir/Phoenix.