This is a really simple project but I tried to treat it as a real project for educational purposes :)
This project builds an image from dice pieces and die's style and side length can be defined. Idea for this project is from YouTube or Jadi , but I changed some of it's features.
Instead of defining number of dice in rows and columns to build the main image, I decided to define the length of the die(in Pixel) to replace Pixels of the image, so number of dice in rows and columns of the image depends on die side's length.
There are 6 styles for die to be chosen:
Style 1 | Style2 | Style3 | Style4 | Style5 | Style6 |
---|---|---|---|---|---|
These instruction helps You to run the project.
OpenCV > 3.0.0
Python3
cairosvg
You can install OpenCV and cairo (for Windows user in order to install cairosvg) with less effort with the help of Anaconda rather than building them from the source code.
-
To install Python3 You can use the official WEBSITE.
-
Skip this step if You used Anaconda.
To install OpenCV You can check the website or on Linux You can use this command:
sudo apt install python3-opencv
Or to build it from the source code, if You're on Linux this SCRIPT may help You a lot.
-
To install cairosvg follow this LINK.
To test if modules are installed correctly or not, do the following:
-
Open Terminal / Command Line
-
Type python or python3 (if default is Python 2.7) and press Enter, if it is installed correctly You should see something like this(Python interactive mode):
Python 3.7.2+ (default, Feb 27 2019, 15:41:59) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
-
Import OpenCV and cairosvg modules(Type bellow commands after >>>)
import cv2 import cairosvg
If it showed nothing that means both are installed successfully but if not, You should try to install the one which failed.
After installing prerequisites follow the bellow steps to test the project:
-
Download the project and unzip it.
-
Open the Terminal / Command Line.
-
Change to the project directory where img2dice.py is located (I assumed project directory is on Download directory)
cd /Download/image2dice-master/image2dice-master/image2dice
-
Run the below command on Terminal/Command Line to get more information: (Remove 3 if it doesn't work)
python3 image2dice.py -h
There are two samples.
Die:
Length: 1
Style: 2
Paste the following command in Terminal/Command Line:
python3 img2dice.py ./sample/input/sample1.jpg -side 1 -style 2 --save
Result is like this:
Die:
Length: 20
Style: 1
Paste the following command in Terminal/Command Line:
python3 img2dice.py ./sample/input/sample2.jpg -side 20 -style 1 --save
Result is like this:
In this output, dice faces are noticeable.(download it to see)
- Use better algorithm.
- Remove
cairosvg
and use Math packages to define die faces. - Add GUI version.
Code is under MIT License.
First photo by Eye for Ebony on Unsplash
Second photo by Rodrigo Pereira on Unsplash