-
Notifications
You must be signed in to change notification settings - Fork 0
/
icanvision.cpp
236 lines (168 loc) · 7.04 KB
/
icanvision.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "icanvision.h"
void IcanVision::ImageProducer(){
VideoCapture cap;
cap.open(0);
Mat image;
int fd;
int i = 0;
for(;;)
{
//第一行没有必要加上
//while(image_buffer_rear_ - image_buffer_front_ > IMGAE_BUFFER); //若满足这个条件,则让这个函数一只停在这里
cap >> image;
//imshow("",src);
if(image.empty())
break;
image_buffer_rear_++;
Mat img;
//int i = 0;
Dector dector;
Target target;
// MeasureDistance measuredistance;
// int fd;
Mat out;
Point3f point;
waitKey(1);
img = image.clone();
//bilateralFilter(image,img,25,90,90);
if(img.empty())
break;
Mat src = img.clone();
Size dsize = Size(1280, 960);
resize(src,src,dsize);
char sign;
Point3f target_location;
bool is_find;
target = dector.getBestTarget(img,is_find,target_location);
if(i != 0){
target_location.x = (point.x + target_location.x)/2;
target_location.y = (point.y + target_location.y)/2;
target_location.z = (point.z + target_location.z)/2;
}
i++;
point = target_location;
// ************fliter***********
// 开始发送数据
fd = datacontroler.OpenPort("/dev/ttyUSB0");
datacontroler.configureSerial(fd);
serial_state = SerialState::SEND;
cout << is_find << endl << endl;
if(is_find == false){
sign = 0xcc;
}else{
sign = 0x0a;
}
float angle;
angle = atan(target_location.x/target_location.z)*(180/CV_PI);
vision_data.X.f = target_location.x;
vision_data.Y.f = target_location.y;
vision_data.Z.f = target_location.z;
//angle = 0;
vision_data.angle.f = angle;
vision_data.sign = sign;
//cout<<"ddddd"<<vision_data.X.f <<endl<<endl;
//cout<<"sssss"<<vision_data.Z.f<<endl<<endl;
datacontroler.sentData(fd,vision_data);
{
char test[100];
sprintf(test, "tz:%0.4f", vision_data.Z.f);
cv::putText(src, test, cv::Point(10, 40), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
sprintf(test, "tx:%0.4f", vision_data.X.f);
cv::putText(src, test, cv::Point(src.cols/3, 80), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
sprintf(test, "ty:%0.4f", vision_data.Y.f);
cv::putText(src, test, cv::Point(2*src.cols/3, 120), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
sprintf(test, "targrt.x:%0.4f", target.left_up.x);
cv::putText(src, test, cv::Point(2*src.cols/3, 200), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
sprintf(test, "target.y:%0.4f", target.left_up.y);
cv::putText(src, test, cv::Point(2*src.cols/3, 280), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
sprintf(test, "vision_data:%0.4f", vision_data.angle.f);
cv::putText(src, test, cv::Point(2*src.cols/3, 360), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
//sprintf(test, "fps:%c", sign);
//cv::putText(src, test, cv::Point(2*src.cols/3, 420), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
}
imshow("Print data",src);
}
}
//void IcanVision::ImageConsumer(){
// Mat img;
// //int i = 0;
// Dector dector;
// Target target;
// double t = 0;
// double fps;
// // MeasureDistance measuredistance;
// // int fd;
// while(1){
// // 这一行必须加上
// while(image_buffer_rear_ <= image_buffer_front_); //若满足这个条件,则让这个函数一只停在这里
// image_buffer_front_ = image_buffer_rear_ - 1;
// img = image_buffer_[image_buffer_front_%IMGAE_BUFFER];
// Mat out;
// bilateralFilter(img,out,25,100,100);
// waitKey(1);
// if(img.empty())
// break;
// Point3f target_location;
// bool is_find;
// target = dector.getBestTarget(img,is_find,target_location);
// //cout << target.left_up.x << "\t" << target.left_up.y << endl;
// //**************测距****************
// //**************测距****************
// //**************滤波处理*************
//// vector<Point3f> location_seq;
//// location_seq.push_back(target_location);
//// target_location = smoothFiter(location_seq);
//// if(i >= 20){
//// i = 0;
//// location_seq.clear();
//// }
// //**************滤波处理*************
// // 开始发送数据
// //cout << "hello wodld" << endl;
// //fd = datacontroler.OpenPort("/dev/ttyUSB0");
// //datacontroler.configureSerial(fd);
// serial_state = SerialState::SEND;
// float angle;
// angle = atan(target_location.x/target_location.z)*(180/CV_PI);
// vision_data.X.f = target_location.x;
// vision_data.Y.f = target_location.y;
// vision_data.Z.f = target_location.z;
// vision_data.angle.f = angle;
// //datacontroler.sentData(fd,vision_data);
// Mat src = img.clone();
// Size dsize = Size(1280, 960);
// resize(src,src,dsize);
// t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
// fps = 1.0 / t;
// {
// char test[100];
// sprintf(test, "tz:%0.4f", target_location.z);
// cv::putText(src, test, cv::Point(10, 40), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
// sprintf(test, "tx:%0.4f", target_location.x);
// cv::putText(src, test, cv::Point(src.cols/3, 80), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
// sprintf(test, "ty:%0.4f", target_location.y);
// cv::putText(src, test, cv::Point(2*src.cols/3, 120), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
// sprintf(test, "targrt.x:%0.4f", target.left_up.x);
// cv::putText(src, test, cv::Point(2*src.cols/3, 200), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
// sprintf(test, "target.y:%0.4f", target.left_up.y);
// cv::putText(src, test, cv::Point(2*src.cols/3, 280), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
// sprintf(test, "vision_data:%0.4f", vision_data.angle.f);
// cv::putText(src, test, cv::Point(2*src.cols/3, 360), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
// sprintf(test, "fps:%0.4f", fps);
// cv::putText(src, test, cv::Point(2*src.cols/3, 420), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 0, 255), 5, 8);
// }
// imshow("Print data",src);
// }
//}
//void IcanVision::SerialSendReceive(){
// int fd;
// fd = datacontroler.OpenPort("/dev/ttyUSB0");
// datacontroler.configureSerial(fd);
// while(true){
// //发数
// if(serial_state == SerialState::SEND){
// //自瞄
// datacontroler.sentData(fd,vision_data);
// }
// }
//}