How to make a face out of food
Aaron Randall’s Megabite app uses a food photo, analyzes every single component of your dish, then swaps everything to get a funny face on a plate. Under the cut - video and description of the algorithm.
The user takes food using the application, the photo size is changed to 1000x1000 pixels, and then cropped along the contour of the plate.
In the next step, the application searches for individual objects, determining their contours. The application applies the Canny image boundary detection operator (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 "daughter" contours - for example, the yolk in the scrambled eggs.
The application flips each resulting contour to fit into the minimum bounding box - the minimum area that will contain the image at the maximum scale. The process is repeated for all six parts in the example.
The application has templates that are used to arrange individual parts. Below are three examples, with the number of polygons from three to six.
Then the application selects the template according to the number of details. In this example, there are six parts, so the muzzle will turn out with ears and nose. Then the polygons and parts of the image are sorted by size and selected in pairs.
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.
Such a face eventually came out of fried eggs with bacon and toast. The author writes that the application so far only works with photos similar to this one and so far has many limitations.
Image Preparation
The user takes food using the application, the photo size is changed to 1000x1000 pixels, and then cropped along the contour of the plate.
Edge detection
In the next step, the application searches for individual objects, determining their contours. The application applies the Canny image boundary detection operator (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 "daughter" contours - for example, the yolk in the scrambled eggs.
Select contours from an image
The application flips each resulting contour to fit into the minimum bounding box - the minimum area that will contain the image at the maximum scale. The process is repeated for all six parts in the example.
Placing parts on a template
The application has templates that are used to arrange individual parts. Below are three examples, with the number of polygons from three to six.
Then the application selects the template according to the number of details. In this example, there are six parts, so the muzzle will turn out with ears and nose. Then the polygons and parts of the image are sorted by size and selected in pairs.
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.
Result
Such a face eventually came out of fried eggs with bacon and toast. The author writes that the application so far only works with photos similar to this one and so far has many limitations.