-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edge.cpp
149 lines (134 loc) · 3.43 KB
/
Edge.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "Edge.h"
Edge::Edge(void)
{
startEdgeRow = -1;
startEdgeColumn = -1;
endEdgeRow = -1;
endEdgeColumn = -1;
length = -1;
edgeSumCanny = 0;
edgeSumOriginal = 0;
edgeVectorCanny.clear();
edgeVectorOriginal.clear();
}
Edge::~Edge(void)
{
}
int Edge::getStartEdgeRow()
{
return startEdgeRow;
}
int Edge::getStartEdgeColumn()
{
return startEdgeColumn;
}
int Edge::getEndEdgeRow()
{
return endEdgeRow;
}
int Edge::getEndEdgeColumn()
{
return endEdgeColumn;
}
int Edge::getLength()
{
return length;
}
/*
Edge::compute(void)
{
Mat cannyEdge, cannyEdge2;
Mat greyGaussian(image.rows, image.cols, CV_8UC1);
Mat greyGaussian2(image2.rows, image2.cols, CV_8UC1);
GaussianBlur(image,greyGaussian, Size(3,3) ,0,0);
GaussianBlur(image2, greyGaussian2, Size(3,3),0,0 );
//Mat edge(grey.rows, grey.cols, CV_8UC1);
//Mat edge2(grey2.rows, grey2.cols, CV_8UC1);
Canny(greyGaussian,cannyEdge,25,100,3);
Canny(greyGaussian2,cannyEdge2,25,100,3);
// float startTime = (float)clock()/CLOCKS_PER_SEC;
for(int y = 0; y < cannyEdge.rows; y++)
{
Edge edge;
for(int x = 0; x < cannyEdge.cols; x++)
{
Scalar u = cannyEdge.at<uchar>(y,x);
Scalar v = image.at<uchar>(y,x);
// cout << u.val[0] << ", ";
if(u.val[0] > 0 && edge.getStartEdgeRow == -1)
{
edge.startEdgeRow = y;
edge.startEdgeColumn = x;
edge.edgeVectorCanny.push_back(u.val[0]);
edge.edgeVectorOriginal.push_back(v.val[0]);
}
if(u.val[0] > 0 && edge.startEdgeRow != -1)
{
edge.edgeVectorCanny.push_back(u.val[0]);
edge.edgeVectorOriginal.push_back(v.val[0]);
}
else if(edge.startEdgeRow != -1)
{
edge.endEdgeRow = y;
edge.endEdgeColumn = x;
edge.length = edge.edgeVectorCanny.size();
}
}
if(edge.length > 10)
{
for(int i = 0; i < edge.edgeVectorCanny.size(); i++)
{
edge.edgeSumCanny += edge.edgeVectorCanny[i];
}
for(int j = 0; j < edge.edgeVectorOriginal.size(); j++)
{
edge.edgeSumOriginal += edge.edgeVectorOriginal[j];
}
/* cout << "Canny Edge Sum: " << edge.edgeSumCanny << endl;
cout << "Original Image Greyscale Sum: " << edge.edgeSumOriginal << endl;
listOfEdge.push_back(edge);
}
}
for(int y = 0; y < cannyEdge2.rows; y++)
{
Edge edge = InitializeEdge();
for(int x = 0; x < cannyEdge2.cols; x++)
{
Scalar u = cannyEdge2.at<uchar>(y,x);
Scalar v = image2.at<uchar>(y,x);
// cout << u.val[0] << ", ";
if(u.val[0] > 0 && edge.startEdgeRow == -1)
{
edge.startEdgeRow = y;
edge.startEdgeColumn = x;
edge.edgeVectorCanny.push_back(u.val[0]);
edge.edgeVectorOriginal.push_back(v.val[0]);
}
if(u.val[0] > 0 && edge.startEdgeRow != -1)
{
edge.edgeVectorCanny.push_back(u.val[0]);
edge.edgeVectorOriginal.push_back(v.val[0]);
}
else if(edge.startEdgeRow != -1)
{
edge.endEdgeRow = y;
edge.endEdgeColumn = x;
edge.length = edge.edgeVectorCanny.size();
}
}
if(edge.length > 10)
{
for(int i = 0; i < edge.edgeVectorCanny.size(); i++)
{
edge.edgeSumCanny += edge.edgeVectorCanny[i];
}
for(int j = 0; j < edge.edgeVectorOriginal.size(); j++)
{
edge.edgeSumOriginal += edge.edgeVectorOriginal[j];
}
/* cout << "Canny Edge Shifted Sum: " << edge.edgeSumCanny << endl;
cout << "Original Image Shifted Greyscale Sum: " << edge.edgeSumOriginal << endl;
listOfEdges2.push_back(edge);
}
}
} */