OpenCV 3.2.0, C++ 11 version
Follow OpenCV
- Install appropriate OpenCV version: Here.
// Init Image Size
#define WIDTH 640
#define HEIGHT 480
// For making interval of grid in image
#define DIFF_X 10
#define DIFF_Y 10
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
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 |
[1] https://bbtarzan12.github.io/Marching-Squares-Part-1/
[2] https://github.com/tmryan/MarchingSquares/tree/master