Skip to content

rafoolin/image2dice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image2dice

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
syle1 syle2 syle3 syle4 syle5 syle6

Getting Started

These instruction helps You to run the project.

Prerequisites

OpenCV > 3.0.0

Python3

cairosvg

Installation

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.

  1. To install Python3 You can use the official WEBSITE.

  2. 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.

  3. To install cairosvg follow this LINK.

To test if modules are installed correctly or not, do the following:

  1. Open Terminal / Command Line

  2. 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.
    >>>
  3. 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.

Running the tests

After installing prerequisites follow the bellow steps to test the project:

  1. Download the project and unzip it.

  2. Open the Terminal / Command Line.

  3. 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
  4. Run the below command on Terminal/Command Line to get more information: (Remove 3 if it doesn't work)

    python3 image2dice.py -h

Samples

There are two samples.

First Sample:

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:

Input:

img

Output:

img

Second Sample:

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:

Input:

Output:

In this output, dice faces are noticeable.(download it to see)

To-Do

  • Use better algorithm.
  • Remove cairosvg and use Math packages to define die faces.
  • Add GUI version.

License

Code is under MIT License.

First photo by Eye for Ebony on Unsplash

Second photo by Rodrigo Pereira on Unsplash

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages