-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandala.cpp
84 lines (83 loc) · 2.49 KB
/
mandala.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <opencv2/highgui.hpp>
#include <bits/stdc++.h>
#include <opencv2/imgproc.hpp>
#include <fstream>
#include "slatelib.h"
#include "mandalalib.h"
using namespace cv;
using namespace std;
Mat original(ROW, COLUMN, CV_8UC3);
Mat livePoint(ROW, COLUMN, CV_8UC3);
Mat canavas(ROW, COLUMN, CV_8UC3);
VideoCapture cap("v4l2:///dev/video0");
int main()
{
namedWindow("canavas", WINDOW_NORMAL);
namedWindow("original", WINDOW_NORMAL);
vector <lineEquation> le;
le.push_back(lineEquation(1, -1, 0));
le.push_back(lineEquation(0, 1, 0));
le.push_back(lineEquation(1, 0, 0));
int depth = 2;
depth-=2;
if(cap.isOpened()==false)
{
cout<<"Cannot open the video file"<<endl;
cin.get();
}
// initializeMatObject(canavas, COLOR_BACKGROUND);
initializeMatObject(0, ROW, 0, COLUMN, canavas, COLOR_BLACK);
initializeMatObject(BOARD_ROW,
BOARD_ROW + BOARD_HEIGHT,
BOARD_COLUMN,
BOARD_COLUMN + BOARD_WIDTH,
canavas,
COLOR_BACKGROUND);
imshow("canavas", canavas);
vector <lineEquation> all_le = drawBoard(canavas,
depth, COLOR_BOARD);
for(int i=0; i!=all_le.size(); i++)
{
all_le[i].displayVal();
}
while(1)
{
vector < pair < int, int > > drawnPoints, allDrawnPoints;
bool bSuccess=cap.read(original);
if(bSuccess==false)
break;
invertImage(original);
initializeMatObject(0, ROW, 0, COLUMN, livePoint, COLOR_BLACK);
binarise(original, livePoint, 2, 1, 0, COLOR_CENTRE);
imshow("original", original);
imshow("livePoint", livePoint);
pair <int,int> centre=getCentre(livePoint, 100, COLOR_CENTRE);
cout<<"centre="<<centre.first<<endl;
drawnPoints.push_back(centre);
if(centre.second >= BOARD_COLUMN && centre.second<BOARD_COLUMN+BOARD_WIDTH)
{
canavas.at<Vec3b>(centre.first, centre.second) = COLOR_DRAW_MANDALA;
double slope = getSlope(translateOpenCVToMandala(centre));
if(slope < 1 && slope >0 && centre.first>0 && centre.second>0)
{
for(int i=0; i!=all_le.size(); i++)
{
drawnPoints = getReflectedLine(drawnPoints, le[i]);
cout<<"a"<<drawnPoints[0].first<<" "<<drawnPoints[0].second<<endl;
drawPoints(drawnPoints, canavas, COLOR_DRAW_MANDALA);
allDrawnPoints.push_back(drawnPoints[0]);
}
}
for(int i=0;i<le.size(); i++)
{
vector < pair < int, int> > linePoints =
getReflectedLine(allDrawnPoints, le[i]);
drawPoints(linePoints, canavas, COLOR_DRAW_MANDALA);
allDrawnPoints.insert(allDrawnPoints.end(),
linePoints.begin(), linePoints.end());
}
}
int keyPress=waitKey(10);
imshow("canavas", canavas);
}
}