-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCalSim.h
118 lines (103 loc) · 2.54 KB
/
CalSim.h
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
#include "common.h"
//#include "Block.h"
//#include <opencv2/opencv.hpp>
#define PI 3.14159265
class CalSim
{
public:
CalSim() {}
int cal_angle(float x,float y)
{
if(x<1&&x>0||x<0&&x>-1)
{
x=0;
}
if(y<1&&y>0||y<0&&y>-1)
{
y=0;
}
if(x==0&&y==0)
{
return 8;
}
if(x==0)
{
if(y>0)
{
return 2;
} else{
return 6;
}
}
if(y==0)
{
if(x>0)
{
return 0;
} else
{
return 4;
}
}
float angle=atan(abs(y)/abs(x))*180/PI;
if (angle!=angle)
{
return 8;
} else
{
if(x<0 && y>0)
{
angle=180-angle;
}
if(x<0 && y<0)
{
angle=180+angle;
}
if(x>0 && y<0)
{
angle=360-angle;
}
}
return int(angle/45);
}
float cal_sim(float a[], float b[]) {
using namespace cv;
int scale = 1;
int delta = 0;
int ddepth = CV_32F;//CV_16S;
Mat A, B, A_x, B_x,A_y,B_y;
A = Mat(90, 60, CV_32F, a);
B = Mat(90, 60, CV_32F, b);
Sobel( A, A_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
Sobel( B, B_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
Sobel( A, A_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );
Sobel( B, B_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );
Block a_image [10][10],b_image[10][10];
for(int i=0;i<90;i++)
{
for(int j=0;j<60;j++)
{
float a_x=A_x.at<float>(i,j);
float a_y=A_y.at<float>(i,j);
float b_x=B_x.at<float>(i,j);
float b_y=B_y.at<float>(i,j);
int a_angle=cal_angle(a_x,a_y);
int b_angle=cal_angle(b_x,b_y);
a_image[i/9][j/6].count[a_angle]++;
b_image[i/9][j/6].count[b_angle]++;
}
}
float similarity=0;
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(a_image[i][j].find_block_direction()==b_image[i][j].find_block_direction())
{
similarity++;
}
}
}
return similarity/100;
}
};