-
Notifications
You must be signed in to change notification settings - Fork 6
/
Displayspinmt.cpp
342 lines (252 loc) · 7.62 KB
/
Displayspinmt.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
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
#ifdef _WIN64
#include "stdafx.h"
#include "windows.h"
// anything before a precompiled header is ignored,
// so no endif here! add #endif to compile on __unix__ !
#endif
#ifdef _WIN64
//#include <qhyccd.h>
#endif
/*
* checking FPS, multithreaded
* for FLIR Point Grey camera
* instead of QHY camera
*
* ESC, x or X key quits
*
*
*
* Hari Nandakumar
* 22 Aug 2019 *
*
*
*/
//#define _WIN64
//#define __unix__
#include <stdio.h>
#include <stdlib.h>
#ifdef __unix__
#include <unistd.h>
//#include <libqhy/qhyccd.h>
#endif
#include <string.h>
#include <time.h>
#include <sys/stat.h>
// this is for mkdir
#include <opencv2/opencv.hpp>
// used the above include when imshow was being shown as not declared
// removing
// #include <opencv/cv.h>
// #include <opencv/highgui.h>
////////////////////////////
//Spinnaker API for FLIR Point Grey camera
#include "Spinnaker.h"
#include "SpinGenApi/SpinnakerGenApi.h"
#include <iostream>
#include <sstream>
#include <pthread.h>
using namespace Spinnaker;
using namespace Spinnaker::GenApi;
using namespace Spinnaker::GenICam;
using namespace std;
///////////////////////////
using namespace cv;
// have to make this global so that AcquireImages can see it
Mat m;
// modified from AcquisitionMultipleThread.cpp example
void* AcquireImages(void* arg)
{
CameraPtr pCam = *((CameraPtr*)arg);
//Mat m;
pCam->Init();
try
{
// Begin acquiring images
pCam->BeginAcquisition();
// Retrieve, convert, and save images for each camera
//
unsigned int imageCnt = 0;
ImagePtr pResultImage;
ImagePtr convertedImage;
while ( imageCnt < 1)
{
try
{
// Retrieve next received image and ensure image completion
pResultImage = pCam->GetNextImage();
if (pResultImage->IsIncomplete())
{
//cout << "[" << serialNumber << "] " << "Image incomplete with image status " << pResultImage->GetImageStatus() << "..." << endl << endl;
imageCnt = 0;
}
else
{
// Convert image to mono 8
convertedImage = pResultImage->Convert(PixelFormat_Mono8, HQ_LINEAR);
m = cv::Mat(960, 1280, CV_8UC1, convertedImage->GetData(), convertedImage->GetStride());
imageCnt = 1;
}
//cout << endl;
} // end of try
catch (Spinnaker::Exception &e)
{
//cout << "[" << serialNumber << "] " << "Error: " << e.what() << endl;
}
// Release image
pResultImage->Release();
} // end of while not incomplete
// End acquisition
pCam->EndAcquisition();
// Deinitialize camera
pCam->DeInit();
return (void*)1;
}
catch (Spinnaker::Exception &e)
{
cout << "Error: " << e.what() << endl;
return (void*)0;
}
}
int main(int argc, char *argv[])
{
int num = 0;
//qhyccd_handle *camhandle = NULL;
int ret;
int w = 1280;
int h = 960;
int fps, key, doneflag;
int t_start, t_end;
Mat mraw;
//ret = InitQHYCCDResource();
SystemPtr system = System::GetInstance();
CameraList camList = system->GetCameras();
num = camList.GetSize();
int result;
/*
if (ret != QHYCCD_SUCCESS)
{
printf("Init SDK not successful!\n");
}
num = ScanQHYCCD();*/
if (num > 0)
{
//printf("Found camera,the num is %d \n", num);
}
else
{
printf("camera not found, please check the cable and power.\n");
// Clear camera list before releasing system
camList.Clear();
// Release system
system->ReleaseInstance();
//goto failure;
}
CameraPtr pCam = nullptr;
pCam = camList.GetByIndex(0); // open first camera
pthread_t* grabThreads = new pthread_t[1];
doneflag = 0;
t_start = time(NULL);
fps = 0;
try
{
// Retrieve TL device nodemap and print device information
INodeMap & nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
//result = PrintDeviceInfo(nodeMapTLDevice);
// Initialize camera
pCam->Init();
// Retrieve GenICam nodemap
INodeMap & nodeMap = pCam->GetNodeMap();
// Acquire images
//result = result | AcquireImages(pCam, nodeMap, nodeMapTLDevice);
// Deinitialize camera
//put this here,
CEnumerationPtr ptrAcquisitionMode = nodeMap.GetNode("AcquisitionMode");
if (!IsAvailable(ptrAcquisitionMode) || !IsWritable(ptrAcquisitionMode))
{
cout << "Unable to set continuous acquisition mode as ptr is not writable ..." << endl << endl;
return -1;
}
// Retrieve entry node from enumeration node
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName("Continuous");
if (!IsAvailable(ptrAcquisitionModeContinuous) || !IsReadable(ptrAcquisitionModeContinuous))
{
cout << "Unable to set continuous acquisition mode as entry is not readable..." << endl << endl;
return -1;
}
// Retrieve integer value from entry node
const int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
// Set integer value from entry node as new value of enumeration node
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
ImagePtr pResultImage;
ImagePtr convertedImage;
while (1) //camera frames acquisition loop, which is inside the try
{
//ret = GetQHYCCDLiveFrame(camhandle, &w, &h, &bpp, &channels, mraw.data);
ret = 0;
// trying multithreaded, to see if it will improve fps
int err = pthread_create(&(grabThreads[0]), nullptr, &AcquireImages, &pCam);
//assert(err == 0);
void* exitcode;
ret = pthread_join(grabThreads[0], &exitcode);
mraw = pthread_join(grabThreads[0], &exitcode);
if (ret == 1)
{
m.copyTo(mraw);
imshow("show", mraw);
fps++;
t_end = time(NULL);
if (t_end - t_start >= 5)
{
printf("fps = %d\n", fps / 5);
/*
opm.copyTo(opmvector);
opmvector.reshape(0, 1); //make it into a row array
minMaxLoc(opmvector, &minVal, &maxVal);
sprintf(textbuffer, "fps = %d Max intensity = %d", fps / 5, int(floor(maxVal)));
firstrowofstatusimg = Mat::zeros(cv::Size(600, 50), CV_64F);
putText(statusimg, textbuffer, Point(0, 30), FONT_HERSHEY_SIMPLEX, 1, Scalar(255, 255, 255), 3, 1);
sprintf(textbuffer, "%03d images acq.", indextemp);
secrowofstatusimgRHS = Mat::zeros(cv::Size(300, 50), CV_64F);
putText(statusimg, textbuffer, Point(300, 80), FONT_HERSHEY_SIMPLEX, 1, Scalar(255, 255, 255), 3, 1);
imshow("Status", statusimg);
if (ROIreport)
printMinMaxAscan(bscandb, ascanat, numdisplaypoints, statusimg); */
fps = 0;
t_start = time(NULL);
}
////////////////////////////////////////////
key = waitKey(3); // wait 30 milliseconds for keypress
// max frame rate at 1280x960 is 30 fps => 33 milliseconds
switch (key)
{
case 27: //ESC key
case 'x':
case 'X':
doneflag = 1;
break;
default:
break;
}
if (doneflag == 1)
{
break;
}
} // if ret success end
} // inner while loop end
//pResultImage->Release();
pCam->DeInit();
// Clear camera list before releasing system
camList.Clear();
// Release system
system->ReleaseInstance();
} // end of try
catch (Spinnaker::Exception &e)
{
cout << "Error: " << e.what() << endl;
result = -1;
}
return 0;
failure:
printf("Fatal error !! \n");
return 1;
}