📜 ⬆️ ⬇️

How to make a face out of food

Aaron Randall's Megabite application uses a photo of food, analyzes each individual component of your dish, then changes everything in places to get a funny face on a plate. Under the cut - video and description of the algorithm.

image



Image preparation


The user shoots food using the application, the size of the photo is changed to 1000x1000 pixels, and then cropped along the contour of the dish.
')
image

Contour detection


In the next step, the application searches for individual objects, defining their contours. The application applies the image detection operator Canny (2), and receives three images for subsequent work (3, 4, 5). Then the OpenCV findContours function is used to detect the contours of each part. The outlines in the image below are marked in red. Then the algorithm filters out the "child" contours - for example, the yolk in the fried eggs.

image

Outline selection from image


Each application contour turns over to fit into the minimum bounding rectangle - the minimum area that will contain the image in the maximum scale. The process is repeated for all six parts in the example.

image

image

Placing parts on a template


The application has templates that are used to arrange the individual parts. Below - three examples, with the number of polygons from three to six.

image

The application then selects the template by the number of parts. In this example, there are six details, so the face will come out with ears and a nose. Then polygons and parts of the image are sorted by size and are selected by pairs.

image

At the next stage, the details are placed on the template so that the food occupies the maximum possible area of ​​each of the polygons.

image

Result


This face eventually came from fried eggs with bacon and toast. The author writes that the application so far works only with photos similar to this one and so far has many limitations.

image

Source: https://habr.com/ru/post/390075/


All Articles