Download PUMA2-- Short User Guide
Transcript
2.3 Using the grabber library
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
5
using namespace std;
// grab a maximum of 15 frames per second
static const float FPS = 15.0;
static const int NUM_FRAMES = 50;
int main(int argc, char **argv)
{
// get instance of GrabbingDeviceManager
GrabbingDeviceManager* myManager =GrabbingDeviceManager:: getGrabbingDeviceManager();
// check if supported devices are present
if ( ! myManager->getNumDevices())
{
cerr << "no supported devices found, sorry" << endl;
return EXIT_FAILURE;
}
// list all supported devices
myManager->printDeviceList();
unsigned int devNum = myManager->getNumDevices() +1 ;
while ( devNum >= myManager->getNumDevices() )
{
cout << "please enter device number" << endl;
cin >> devNum;
}
GrabbingDevice *myCam;
// connect to GrabbingDevice
bool camFound = myManager->connectGrabbingDevice( &myCam, devNum );
if ( !camFound ) return EXIT_FAILURE;
myCam->printFormatsList();
// choose first camera format which could be converted to rgb
myCam->setFormat2("width=* height=* in=* out=RGB");
// start capture process
myCam->startCapture();
// puma2 rgb image
ColorImageRGB8 image;
string filename;
// capture
for( int i
{
//
//
if
{
NUM_FRAMES frames
= 0; i < NUM_FRAMES; i++ )
usleep( (int) (1000000.0 / FPS) ); // should be "minus grabtime"
try to grab image and write it to disk
( myCam->grabImage( image ))
cout << "\b\b" << toString(i) << flush;
filename = "frame_" + toString( i ) + ".jpg";
// WARNING: writing png to disk is SLOW!
ImageWriter::writeImage(image, filename.c_str());
}
}
// stop capturing process
myCam->stopCapture();
delete myCam;
return EXIT_SUCCESS;