-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaimooeOperator.cpp
More file actions
343 lines (312 loc) · 9.94 KB
/
aimooeOperator.cpp
File metadata and controls
343 lines (312 loc) · 9.94 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#include "aimooeOperator.h"
aimooeOperator::aimooeOperator(QObject* parent) :QThread(parent) {}
void aimooeOperator::openAimooe() {
int rt = 1;
Aim_API_Initial(aimHandle);
EI = I_USB; oldEI = I_USB;
useUSBorEthernetorWIFI = 0;
switch (useUSBorEthernetorWIFI)
{
case 0: {EI = I_USB; oldEI = I_USB; }break;
case 1: {EI = I_ETHERNET; oldEI = I_ETHERNET; }break;
case 2: {EI = I_WIFI; oldEI = I_WIFI; }break;
default: {std::cout << "输入有误!" << endl; }break;
}
std::cout << "AR demo启动" << std::endl;
string strversion;
int number;
//char * path = "C:\\AimTools\\";
char** toolarr = NULL;
if (EI == I_ETHERNET)
{
//App-100
//Aim_SetEthernetConnectIP(192, 168,1,10);
//App-200
Aim_SetEthernetConnectIP(aimHandle, 192, 168, 31, 10);
}
E_ReturnValue rlt = Aim_ConnectDevice(aimHandle, EI, mPosDataPara);
/*int graywidth = mPosDataPara.dualimg.width;
int grayheight = mPosDataPara.dualimg.height;
ImageLeft = new char[graywidth * grayheight];
ImageRight = new char[graywidth * grayheight];*/
#if GET_DATA_FROM_HARDWARE
Aim_SetAcquireData(aimHandle, EI, DT_NONE);
#else
Aim_SetAcquireData(aimHandle, EI, DT_INFO);
#endif
if (rlt == AIMOOE_OK)
{
//Aim_SetMarkerParameters(aimHandle, EI, 75,1000,80);
std::cout << "连接成功!" << endl;
oldEI = EI;
toolidarr.push_back("pin");
toolidarr.push_back("base");
char* c = const_cast<char*>(patht);
rlt = Aim_SetToolInfoFilePath(aimHandle, c);
int rlt1;
#if GET_DATA_FROM_HARDWARE
Aim_SetAcquireData(aimHandle, EI, DT_NONE);
#else
rlt1 = Aim_SetAcquireData(aimHandle, EI, DT_INFO);
#endif
if (rlt1 == AIMOOE_OK && rlt == AIMOOE_OK) {
emit flage(true);
isStarted = true;
}
}
}
void aimooeOperator::captureGrayFrame() {
int rlt;
int graywidth = mPosDataPara.dualimg.width;
int grayheight = mPosDataPara.dualimg.height;
iL = new char[graywidth * grayheight];
iR = new char[graywidth * grayheight];
rlt = Aim_SetAcquireData(aimHandle, EI, DT_IMGDUAL);
rlt = Aim_GetGreyImageDual(aimHandle, EI, iL, iR);
emit ImageLeft(iL);
emit ImageRight(iR);
}
void aimooeOperator::captureColorFrame() {
int rlt;
int colorwidth = mPosDataPara.colorimg.width;
int colorheight = mPosDataPara.colorimg.height;
iC = new char[colorwidth * colorheight * 2];
rlt = Aim_SetAcquireData(aimHandle, EI, DT_INFO_IMGCOLOR);
rlt = Aim_GetColorImageMiddle(aimHandle, EI, iC);
emit ImageColor(iC);
}
void aimooeOperator::loopGetTool() {
while (1) {
#if GET_DATA_FROM_HARDWARE
rlt = Aim_GetMarkerAndStatusFromHardware(aimHandle, EI, markerSt, statusSt);
#else
rlt = Aim_GetMarkerInfo(aimHandle, EI, markerSt);
#endif
if (rlt != AIMOOE_OK)
continue;
T_AimToolDataResult* mtoolsrlt = new T_AimToolDataResult;
mtoolsrlt->next = NULL;
rlt = Aim_FindSpecificToolInfo(aimHandle, markerSt, this->toolidarr, mtoolsrlt, 3);
T_AimToolDataResult* prlt = mtoolsrlt;
if (rlt == AIMOOE_OK)
{
do
{
if (prlt->validflag)
{
float PI = 3.141592;
QString add_text = QString::number(prlt->OriginCoor[0]);
add_text += " ";
add_text += QString::number(prlt->OriginCoor[1]);
add_text += " ";
add_text += QString::number(prlt->OriginCoor[2]);
add_text += " ";
add_text += QString::number(prlt->rotationvector[0] * 180 / PI);
add_text += " ";
add_text += QString::number(prlt->rotationvector[1] * 180 / PI);
add_text += " ";
add_text += QString::number(prlt->rotationvector[2] * 180 / PI);
add_text += "\n";
emit RTSignal(add_text);
/*for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
RT[i][j] = prlt->Rto[i][j];
}
RT[i][3] = prlt->OriginCoor[i];
}
RT[3][3] = 1;
*/
}
T_AimToolDataResult* pnext = prlt->next;
delete prlt;
prlt = pnext;
} while (prlt != NULL);
}
else
{
delete prlt;
}
}
}
void aimooeOperator::GetToolInfo(std::vector<toolPosition> &toolList) {
#if GET_DATA_FROM_HARDWARE
rlt = Aim_GetMarkerAndStatusFromHardware(aimHandle, EI, markerSt, statusSt);
#else
rlt = Aim_GetMarkerInfo(aimHandle, EI, markerSt);
#endif
if (rlt != AIMOOE_OK)
return;
T_AimToolDataResult* mtoolsrlt = new T_AimToolDataResult;
mtoolsrlt->next = NULL;
rlt = Aim_FindSpecificToolInfo(aimHandle, markerSt, this->toolidarr, mtoolsrlt, 3);
T_AimToolDataResult* prlt = mtoolsrlt;
if (rlt == AIMOOE_OK)
{
do
{
if (prlt->validflag)
{
float PI = 3.141592;
toolPosition tP;
tP.name = prlt->toolname;
tP.qR[0] = prlt->Qoxyz[0];
tP.qR[1] = prlt->Qoxyz[1];
tP.qR[2] = prlt->Qoxyz[2];
tP.qR[3] = prlt->Qoxyz[3];//未作硬件设备映射
tP.vR[0] = prlt->rotationvector[0] - PI / 2;
tP.vR[1] = prlt->rotationvector[1];
tP.vR[2] = prlt->rotationvector[2] - PI / 2;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
tP.Rto[i][j] = prlt->Rto[i][j];
tP.Tto[0] = prlt->Tto[0];
tP.Tto[1] = prlt->Tto[1];
tP.Tto[2] = prlt->Tto[2];
toolList.push_back(tP);
}
T_AimToolDataResult* pnext = prlt->next;
delete prlt;
prlt = pnext;
} while (prlt != NULL);
}
else
{
delete prlt;
}
}
void aimooeOperator::GetMarkerInfo() {
int rlt;
#if GET_DATA_FROM_HARDWARE
rlt = Aim_GetMarkerAndStatusFromHardware(aimHandle, EI, markerSt, statusSt);
#else
rlt = Aim_GetMarkerInfo(aimHandle, EI, markerSt);
#endif
if (rlt == AIMOOE_OK)
{
int markerNum = markerSt.MarkerNumber;
std::cout << "开机后第" << markerSt.ID << "次采集" << endl;
std::cout << "标记点背景光(1:正常,0:不正常):" << (markerSt.MarkerBGLightStatus == BG_LIGHT_OK) << endl;
std::cout << "检测到标记点数量:" << markerNum << endl;
Eigen::Vector3d massPoint;
Eigen::Vector3d normalPlan;
Eigen::Vector3d rotationD;
for (int i = 0; i < markerNum; i++)
{
std::cout << i << ":(" << markerSt.MarkerCoordinate[i * 3 + 0] << ", " << markerSt.MarkerCoordinate[i * 3 + 1] << ", " << markerSt.MarkerCoordinate[i * 3 + 2] << ")" << endl;
}
}
}
void aimooeOperator::write_bmpheader(unsigned char* bitmap, int offset, int bytes, int value)
{
int i;
for (i = 0; i < bytes; i++)
bitmap[offset + i] = (value >> (i << 3)) & 0xFF;
}
unsigned char* aimooeOperator::convertGrayTo24bitBmp(unsigned char* inputImg, int width, int height, int* ouputSize)
{
/*create a bmp format file*/
int bitmap_x = (int)ceil((double)width * 3 / 4) * 4;
unsigned char* bitmap = (unsigned char*)malloc(sizeof(unsigned char) * height * bitmap_x + 54);
bitmap[0] = 'B';
bitmap[1] = 'M';
write_bmpheader(bitmap, 2, 4, height * bitmap_x + 54); //whole file size
write_bmpheader(bitmap, 0xA, 4, 54); //offset before bitmap raw data
write_bmpheader(bitmap, 0xE, 4, 40); //length of bitmap info header
write_bmpheader(bitmap, 0x12, 4, width); //width
write_bmpheader(bitmap, 0x16, 4, height); //height
write_bmpheader(bitmap, 0x1A, 2, 1);
write_bmpheader(bitmap, 0x1C, 2, 24); //bit per pixel
write_bmpheader(bitmap, 0x1E, 4, 0); //compression
write_bmpheader(bitmap, 0x22, 4, height * bitmap_x); //size of bitmap raw data
for (int i = 0x26; i < 0x36; i++)
bitmap[i] = 0;
int k = 54;
for (int i = height - 1; i >= 0; i--) //bmp图像存储从最后一行开始
{
int j;
for (j = 0; j < width; j++)
{
int index = i * width + j;
bitmap[k++] = inputImg[index];
bitmap[k++] = inputImg[index];
bitmap[k++] = inputImg[index];
}
j *= 3;
while (j < bitmap_x) {
bitmap[k++] = 0;
j++;
}
}
*ouputSize = k;
return bitmap;
}
unsigned char* aimooeOperator::convertColor16To24bitBmp(unsigned char* inputImg, int width, int height, int* ouputSize)
{
/*create a bmp format file*/
int bitmap_x = (int)ceil((double)width * 3 / 4) * 4;
unsigned char* bitmap = (unsigned char*)malloc(sizeof(unsigned char) * height * bitmap_x + 54);
bitmap[0] = 'B';
bitmap[1] = 'M';
write_bmpheader(bitmap, 2, 4, height * bitmap_x + 54); //whole file size
write_bmpheader(bitmap, 0xA, 4, 54); //offset before bitmap raw data
write_bmpheader(bitmap, 0xE, 4, 40); //length of bitmap info header
write_bmpheader(bitmap, 0x12, 4, width); //width
write_bmpheader(bitmap, 0x16, 4, height); //height
write_bmpheader(bitmap, 0x1A, 2, 1);
write_bmpheader(bitmap, 0x1C, 2, 24); //bit per pixel
write_bmpheader(bitmap, 0x1E, 4, 0); //compression
write_bmpheader(bitmap, 0x22, 4, height * bitmap_x); //size of bitmap raw data
for (int i = 0x26; i < 0x36; i++)
bitmap[i] = 0;
int k = 54;
for (int i = height - 1; i >= 0; i--) //bmp图像存储从最后一行开始
{
int j;
for (j = 0; j < width; j++)
{
int index = (i * width + j) * 2;
bitmap[k++] = (inputImg[index] << 3);//blue
bitmap[k++] = ((inputImg[index + 1] << 5) | (inputImg[index] >> 3)) & 0xFC;//green
bitmap[k++] = inputImg[index + 1] & 0xF8;//red
}
j *= 3;
while (j < bitmap_x) {
bitmap[k++] = 0;
j++;
}
}
*ouputSize = k;
return bitmap;
}
bool aimooeOperator::saveToBmp(unsigned char* inputImg, int width, int height, char* outputFileName, E_BMPBIT bmpBit)
{
int size;
unsigned char* bmp;
if (bmpBit == BMP8BIT)
bmp = convertGrayTo24bitBmp(inputImg, width, height, &size);
else
bmp = convertColor16To24bitBmp(inputImg, width, height, &size);
FILE* fp = fopen(outputFileName, "wb+");
if (fp == NULL) {
return false;
}
fwrite(bmp, 1, size, fp);
fclose(fp);
free(bmp);
return true;
}
void aimooeOperator::Ipl2VTK(cv::Mat& src, vtkImageData* dst)
{
cv::flip(src, src, 0);
vtkImageImport* importer = vtkImageImport::New();
importer->SetOutput(dst);
importer->SetDataSpacing(1, 1, 1);
importer->SetDataOrigin(0, 0, 0);
importer->SetWholeExtent(0, src.size().width - 1, 0, src.size().height - 1, 0, 0);
importer->SetDataExtentToWholeExtent();
importer->SetDataScalarTypeToUnsignedChar();
importer->SetNumberOfScalarComponents(src.channels());
importer->SetImportVoidPointer(src.data);
importer->Update();
return;
}