Laundry symbol reader

Laundry symbol reader

By: Alejandro Colomar Andrés & Tim Splinter

Introduction

Most of us don’t know what those symbols in our clothes’ labels mean. Some of us can know some of them, but there are too many of them. And we need to select a program when we wash our clothes, because washing machines don’t understand the symbols either. It would be great if machines did understand the symbols so that they could automatically choose which program is most appropriate.

Throughout this article we will use this label as an example of label to be analized by the program.

Problem

We would like to have a program which takes an image of a label as input and gives an output which can be more useful to us; it can be human readable text, or codes that a machine can understand, or both.

Having that program, it would be possible to develop many different systems: a mobile “App” that tells the user what program to put in his washing machine, a system for automating a laundry or a washing machine, ….

Solution

Following the single responsibility principle, it makes sense to first develop the simple program that traduces the symbols into data that can later be interpreted by humans or machines.

The most appropriate language for developing the program is C for many reasons:

  • C is one of the most performing programming languages.
  • OpenCV, the FOSS computer vision library we will use, is written in C++, which is very easily interfaced to C.
  • C is a very stable language, meaning that programs written in C will continue to work for many decades.
  • Any system is likely to have a C compiler, which makes the program very portable; something very important if this program is to be run in a washing machine in the future.
  • C is the best documented programming language thanks to the man pages, which can be found on any Unix-like system
  • The main developer has a lot of experience using C, having written a library in C & C++ with tens of thousands of lines of code, which has been used by this project: libalx

Interface

The program needs to have a very simple interface for the user; the problem we are trying to solve is that the actual information the user can get from the label is not user friendly, so we need to improve this. The interface we developed is the following:

The program needs to be called specifying the name of the image to be analyzed. It then prints one line for each symbol detected, where each line corresponds to the meaning of the symbol.

Example of usage of the program:

$ laundry-symbol-reader <image>
wash: 30, delicate
bleach not
dry not
iron: low temp
professional clean: PCE only, delicate

Computer vision

Most of the code is made up of calls to computer vision functions. We had to use many different opencv functions for separating colors, removing noise, finding specific features in the image, thresholding grayscale images, …. But we also had to write custom functions based on opencv functions. Specifically, one of the most difficult parts of the program was to compare the symbols found in the image against a set of templates. The available comparison functions we tried from opencv weren’t good enough for the very special needs we had, so we had to develop a new comparison function made up of basic bitwise operations. We achieved a very high reliability comparison function for the images we had to compare.

Development

The source code of the program has been developed using very a strict coding style based on the Linux kernel coding style. The code was divided into files and functions where each file and each function has one and only one very specific concern.

We used GNU build tools (gcc, make, …) for building the program. Those tools can be expected to be present on any linux system. The source and version control was managed using git, also widely available on linux systems.

Because of that, the program is very portable, and also very easy to maintain, debug, and improve.

Deployability

We developed this program with its usage in mind, so we developed it to be easily deployed in any system. It could be used to implement automated laundries or washing machines, so we can expect systems with not many resources. Also, a program like this one, using computer vision, has many library dependencies which we cannot expect to be met in most systems. For that reason, we used containers to deploy the program as a standalone application.

We used docker for that, which is a program for linux that allows to run any container similar to how virtual machines work. However, docker uses the native kernel of the linux host, which makes it much more performant than a virtual machine.

Docker is very useful, but it may be difficult to use for the unexperienced ones. For convenience, we wrote a shell script that wraps the calls to docker so that the interface for the user is still as simple as possible; the resulting interface works exactly as the one without docker.

Example of usage of the docker container (using the script):

$ laundry-symbol-reader-dk <image>
wash: 30, delicate
bleach not
dry not
iron: low temp
professional clean: PCE only, delicate

The program is very easy to compile, install and use, and we wrote a very detailed guide on that on the README file that can be found on the main page of the repository

  • A video showing how the program internally works on YouTube.
  • The source code of the program on GitHub.
  • Docker images of the program on DockerHub.