-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagingcamera.cpp
210 lines (186 loc) · 6.65 KB
/
imagingcamera.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
#include "imagingcamera.h"
imagingCamera::imagingCamera()
{
colorConversion = CV_GRAY2RGB;
}
imagingCamera::~imagingCamera()
{
}
bool imagingCamera::open(int id)
{
try
{
int nr_of_buffer = 8; // Number of memory buffer
int nBoard = 0; // Board Number
int MaxPics = 100; // Number of images to grab
int status = 0;
const char *dllName = "Acq_DualBaseAreaGray12";
int boardType = 0;
QList<QString> boardNames;
//emit selectSerialPort(boardNames,&nBoard);
nBoard = 0;
// Initialization of the microEnable frame grabber
if((fg = Fg_Init(dllName,nBoard)) == NULL)
{
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
return false;
}
// Setting the image size
int bitAlignment = FG_LEFT_ALIGNED;
if (Fg_setParameter(fg,FG_WIDTH,&width,nCamPort) < 0)
{
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
return false;
}
if (Fg_setParameter(fg,FG_HEIGHT,&height,nCamPort) < 0) {
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
return false;
}
if (Fg_setParameter(fg,FG_BITALIGNMENT,&bitAlignment,nCamPort) < 0)
{
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
return false;
}
// Memory allocation
int format;
Fg_getParameter(fg,FG_FORMAT,&format,nCamPort);
size_t bytesPerPixel = 2;
switch(format){
case FG_GRAY: bytesPerPixel = 1; break;
case FG_GRAY16: bytesPerPixel = 2; break;
case FG_COL24: bytesPerPixel = 3; break;
case FG_COL32: bytesPerPixel = 4; break;
case FG_COL30: bytesPerPixel = 5; break;
case FG_COL48: bytesPerPixel = 6; break;
}
size_t totalBufSize = width*height*nr_of_buffer*bytesPerPixel;
if((pMem0 = Fg_AllocMemEx(fg,totalBufSize,nr_of_buffer)) == NULL){
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
return false;
} else {
//fprintf(stdout,"%d framebuffer allocated for port %d ok\n",nr_of_buffer,nCamPort);
}
// check for advanced applets, which have a newly designed trigger, anyway set it to camptibility mode
bool isAdvancedApplets = false; //
if (strstr(dllName, "Acq_")){
isAdvancedApplets = true;
}
if (isAdvancedApplets){
// set advanced applet into compatibility mode to use current AcquisitionApplets in order to use the same
// trigger parameters. Otherwise check applet documentation in order to use the advanced trigger features
uint32_t on = FG_ON;
status = Fg_setParameterWithType(fg, FG_TRIGGER_LEGACY_MODE, &on, nCamPort, FG_PARAM_TYPE_UINT32_T);
if (status != FG_OK){
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
return false;
}
}
// Setting the trigger and grabber mode
int nTriggerMode = FREE_RUN;
if(Fg_setParameter(fg,FG_TRIGGERMODE,&nTriggerMode,nCamPort)<0)
{
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
return false;
}
if((Fg_AcquireEx(fg,nCamPort,GRAB_INFINITE,ACQ_STANDARD,pMem0)) < 0){
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
return false;
}
}
catch(Exception e)
{
throw e;
return false;
}
return true;
}
void imagingCamera::close()
{
Fg_stopAcquireEx(fg,nCamPort,pMem0,0);
Fg_FreeMemEx(fg, pMem0);
Fg_FreeGrabber(fg);
return;
}
bool imagingCamera::isOpen(){return true;}
bool imagingCamera::getNextFrame(cv::Mat *grab)
{
lastPicNr = Fg_getLastPicNumberBlockingEx(fg,lastPicNr+1,nCamPort,10,pMem0);
if(lastPicNr <0){
close();
throw Exception(QString::number(Fg_getLastErrorNumber(fg),10)+":"+QString(Fg_getLastErrorDescription(fg)));
}
grab->create(height,width,CV_8U);
grab->data =(uchar *)Fg_getImagePtrEx(fg,lastPicNr,0,pMem0);
return !grab->empty();
}
QSize imagingCamera::getImageSize(){return QSize(4096,3072);}
int imagingCamera::getBoardInfo(QList<QString> &list)
{
int boardType;
int i = 0;
int maxNrOfboards = 10;// use a constant no. of boards to query, when evaluations versions minor to RT 5.2
int nrOfBoardsFound = 0;
int maxBoardIndex = -1;
int iPortCount = 0;
int nrOfBoardsPresent = 0;
list.clear();
// detect all boards
nrOfBoardsPresent = getNrOfBoards();
if(!nrOfBoardsPresent)
return 0;
for(i = 0; i < maxNrOfboards; i++) {
int iPortNrOnBoard = 0;
const char * boardName;
bool skipIndex = false;
boardType = Fg_getBoardType(i);
switch(boardType) {
case PN_MICROENABLE4AS1CL:
boardName = "MicroEnable IV AS1-CL";
iPortNrOnBoard = 1;
break;
case PN_MICROENABLE4AD1CL:
boardName = "MicroEnable IV AD1-CL";
iPortNrOnBoard = 1;
break;
case PN_MICROENABLE4VD1CL:
boardName = "MicroEnable IV VD1-CL";
iPortNrOnBoard = 2;
break;
case PN_MICROENABLE4AD4CL:
boardName = "MicroEnable IV AD4-CL";
iPortNrOnBoard = 2;
break;
case PN_MICROENABLE4VD4CL:
boardName = "MicroEnable IV VD4-CL";
iPortNrOnBoard = 2;
break;
// ignore the non-cameralink boards
case PN_MICROENABLE3I:
case PN_MICROENABLE3IXXL:
case PN_MICROENABLE4AQ4GE:
case PN_MICROENABLE4VQ4GE:
default:
boardName = "Unknown / Unsupported Board";
skipIndex = true;
}
if (!skipIndex){
nrOfBoardsFound++;
maxBoardIndex = i;
if(iPortNrOnBoard > 0){
//if(i==0)
//printf("Following serial ports are available:\n");
for(int j = 0; j < iPortNrOnBoard; j++){
iPortCount++;
//printf("%d. Board_%u %s (%x) Port_%d\n", iPortCount-1, i, boardName, boardType, j);
list.append(QString::number(iPortCount-1,10)+"."+"Board_"+QString::number(i,10)+" "+QString(boardName)+" ("+QString::number(boardType,16)+") Port_"+QString::number(j,10));
}
}
}
else{
}
if (nrOfBoardsFound >= nrOfBoardsPresent){
break;// all boards are scanned
}
}
return iPortCount;
}