-
Notifications
You must be signed in to change notification settings - Fork 1
/
Show.cpp
181 lines (169 loc) · 5.98 KB
/
Show.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <cstdlib>
#include "opencv2/core.hpp"
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "Forces.cpp"
using namespace std;
using namespace cv;
Mat ShowPixelForce(Mat ima, int sampling, float vscale, float halfperception, float pixeldiv ,float &maxforce) {
int width =ima.cols;
int height=ima.rows;
Mat matforce(ima.rows, ima.cols, CV_8UC1, Scalar(255));
Point2f getforce,pos;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pos.x=j;
pos.y=i;
getforce=PixelForce(pos,ima,halfperception,pixeldiv);
if (mag(getforce) > maxforce) {maxforce = mag(getforce);}
if (!(i%sampling) && !(j%sampling)) {
line(matforce,pos,pos+(getforce*vscale),(0),1,CV_AA);
}
}
}
return matforce;
}
Mat ShowPixelForceAngle(Mat ima, float halfperception, float pixeldiv ,float &maxforce) {
int width =ima.cols;
int height=ima.rows;
Mat dx(ima.rows, ima.cols, CV_32F, 1.);
Mat dy(ima.rows, ima.cols, CV_32F, 1.);
Mat force_angle(ima.rows, ima.cols, CV_32F, 1.);
Mat force_mag(ima.rows, ima.cols, CV_32F, 1.);
Point2f getforce,pos;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pos.x=j;
pos.y=i;
getforce=PixelForce(pos,ima,halfperception,pixeldiv);
dx.at<float>(i, j)=getforce.x;
dy.at<float>(i, j)=getforce.y;
//cout << "pixforce : " << getforce << endl;
}
}
cartToPolar(dx, dy, force_mag, force_angle, 1);
force_angle=force_angle*180./360.;
//convert to color
Mat h(ima.rows, ima.cols, CV_8UC1, Scalar(0));
Mat s(ima.rows, ima.cols, CV_8UC1, Scalar(255));
Mat v(ima.rows, ima.cols, CV_8UC1, Scalar(255));
Mat hsv(ima.rows, ima.cols, CV_8UC3);
Mat bgr(ima.rows, ima.cols, CV_8UC3);
force_angle.convertTo(h,CV_8UC1);
vector<Mat> channels;
channels.push_back(h);
channels.push_back(s);
channels.push_back(v);
merge(channels, hsv);
cvtColor(hsv, bgr, CV_HSV2BGR);
return bgr;
}
Mat ShowCurlForce(Mat ima, int sampling, float vscale, float &maxforce) {
int width =ima.cols;
int height=ima.rows;
Mat matforce(ima.rows, ima.cols, CV_8UC1, Scalar(255));
Point2f getforce,pos;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pos.x=(float)j;
pos.y=(float)i;
getforce=CurlForce(ima,pos);
if (mag(getforce) > maxforce) {maxforce = mag(getforce);}
if (!(i%sampling) && !(j%sampling)) {
line(matforce,pos,pos+(getforce*vscale),(0),1,CV_AA);
}
}
}
return matforce;
}
Mat ShowCurlNoiseForce(Mat ima, int sampling, float vscale, float z, float k, FastNoise fn,float &maxforce) {
int width =ima.cols;
int height=ima.rows;
Mat matforce(ima.rows, ima.cols, CV_8UC1, Scalar(255));
Point2f getforce,pos;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pos.x=j;
pos.y=i;
getforce=CurlNoiseForce(pos,z,k,fn);
if (mag(getforce) > maxforce) {maxforce = mag(getforce);}
if (!(i%sampling) && !(j%sampling)) {
line(matforce,pos,pos+(getforce*vscale),(0),1,CV_AA);
}
}
}
return matforce;
}
Mat ShowFlowForce(Mat flow, int sampling, float vscale, float &maxforce) {
int width =flow.cols;
int height=flow.rows;
Mat matforce(height, width, CV_8UC1, Scalar(255));
Point2f getforce,pos;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pos.x=j;
pos.y=i;
getforce=FlowForce(pos,flow);
if (mag(getforce) > maxforce) {maxforce = mag(getforce);}
if (!(i%sampling) && !(j%sampling)) {
line(matforce,pos,pos+(getforce*vscale),(0),1,CV_AA);
}
}
}
return matforce;
}
Mat ShowFastNoiseForce(Mat ima, int sampling, float vscale, float z, float k, float circularboost, FastNoise fn , bool curl, float &maxforce) {
int width =ima.cols;
int height=ima.rows;
Mat matforce(ima.rows, ima.cols, CV_8UC1, Scalar(255));
Point2f getforce,pos;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pos.x=j;
pos.y=i;
if (!curl) {getforce=FastNoiseForce(pos,z,k,circularboost,fn);}
else {getforce=CurlNoiseForce(pos,z,k,fn);}
if (mag(getforce) > maxforce) {maxforce = mag(getforce);}
if (!(i%sampling) && !(j%sampling)) {
line(matforce,pos,pos+(getforce*vscale),(0),1,CV_AA);
}
}
}
return matforce;
}
Mat ShowSuperEllipseForce(Mat ima, int sampling, float vscale, float bound, float n, float &maxforce) {
int width =ima.cols;
int height=ima.rows;
Mat matforce(ima.rows, ima.cols, CV_8UC1, Scalar(255));
Point2f getforce,pos;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pos.x=j;
pos.y=i;
getforce=SuperEllipseForce(pos,bound,n,ima);
if (mag(getforce) > maxforce) {maxforce = mag(getforce);}
if (!(i%sampling) && !(j%sampling)) {
line(matforce,pos,pos+(getforce*vscale),(0),1,CV_AA);
}
}
}
return matforce;
}
Mat ShowGradientForce(Mat dx,Mat dy, int sampling, float vscale, float &maxforce) {
int width =dx.cols;
int height=dx.rows;
Mat matforce(dx.rows, dx.cols, CV_8UC1, Scalar(255));
Point2f getforce,pos;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pos.x=j;
pos.y=i;
getforce=GradientForce(dx,dy,pos);
if (mag(getforce) > maxforce) {maxforce = mag(getforce);}
if (!(i%sampling) && !(j%sampling)) {
line(matforce,pos,pos+(getforce*vscale),(0),1,CV_AA);
}
}
}
return matforce;
}