Giter Club home page Giter Club logo

marching_squares's Introduction

Marching Squares

[Goal] Implement Marching Squares using OpenCV in C++

  • Randomly generated grid image

1. Prerequisites

1.1 Dependencies

OpenCV 3.2.0, C++ 11 version

1.2. OpenCV Installation

Follow OpenCV

  • Install appropriate OpenCV version: Here.

2. Changing Parameters

Parameters in "parameters.h"

// Init Image Size
#define WIDTH  640
#define HEIGHT 480

// For making interval of grid in image
#define DIFF_X 10
#define DIFF_Y 10

3. Build and Run

Clone the repository and build and run simultaneously:

   $ cd ${workspace}
   $ git clone https://github.com/SungJaeShin/Marching_squares.git
   $ cd marching_squares
   $ sh start.sh

4. Setting Rules between Vertices and Edges !!

  p0           a           p1
     ○ ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ ○
     |                   |
     |                   |
  d  |                   |   b
     |                   |
     |                   |
     |                   |
     ○ ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ ○
 p3            c           p2

    Vertex : p0, p1, p2, p3
    Edge   : a, b, c, d
    Rules  : {p0, p1, p2, p3} = {0, 0, 1, 0} <-----> {a, b, c, d} = {0, 1, 1, 0}

    // Not Make Any Line
    {0, 0, 0, 0} <-----> {0, 0, 0, 0} = 0
    {1, 1, 1, 1} <-----> {0, 0, 0, 0} = 0

    // Make Horizontal & Vertical Line
    {1, 1, 0, 0} <-----> {0, 1, 0, 1} = 5
    {0, 0, 1, 1} <-----> {0, 1, 0, 1} = 5
    {0, 1, 1, 0} <-----> {1, 0, 1, 0} = 10
    {1, 0, 0, 1} <-----> {1, 0, 1, 0} = 10

    // Make One Diagonal Line 
    {1, 0, 0, 0} <-----> {1, 0, 0, 1} = 9
    {0, 1, 1, 1} <-----> {1, 0, 0, 1} = 9
    {0, 1, 0, 0} <-----> {1, 1, 0, 0} = 12
    {1, 0, 1, 1} <-----> {1, 1, 0, 0} = 12
    {0, 0, 1, 0} <-----> {0, 1, 1, 0} = 6
    {1, 1, 0, 1} <-----> {0, 1, 1, 0} = 6
    {0, 0, 0, 1} <-----> {0, 0, 1, 1} = 3
    {1, 1, 1, 0} <-----> {0, 0, 1, 1} = 3

    // Make Two Diagonal Line
    p0          a           p1              p0          a           p1
        ● ㅡ ● ㅡㅡㅡㅡㅡㅡ ○                      ○ ㅡㅡㅡㅡㅡ ● ㅡㅡㅡ ●
        |  /             |                      |           \     |
        | /              |                      ●            \    |
    d   |/               ●   b              d   | \           \   |   b
        ●               /|                      |  \           \  |
        |              / |                      |   \             ●
        |             /  |                      |    \            |
        ○ ㅡㅡㅡㅡㅡㅡ ● ㅡ ●                      ● ㅡㅡ ● ㅡㅡㅡㅡㅡㅡ ○
    p3          c           p2              p3          c           p2

    {0, 1, 0, 1} <-----> {1, 1, 1, 1} = 15
    {1, 0, 1, 0} <-----> {1, 1, 1, 1} = 16
Case 1 : Not Make Any Line
Case 2 : Make Horizontal & Vertical Line
Case 3 : Make One Diagonal Line
Case 4 : Make Two Diagonal Line

5. Results

Result w/ vertices (grid interval: 10) Result w/o vertices (grid interval: 10)
Result w/ vertices (grid interval: 20) Result w/o vertices (grid interval: 20)
Result w/ vertices (grid interval: 30) Result w/o vertices (grid interval: 30)
Result w/ vertices (grid interval: 40) Result w/o vertices (grid interval: 40)

6. References

[1] https://bbtarzan12.github.io/Marching-Squares-Part-1/
[2] https://github.com/tmryan/MarchingSquares/tree/master

marching_squares's People

Contributors

sungjaeshin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.