-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraTest.cpp
More file actions
executable file
·103 lines (85 loc) · 3.31 KB
/
CameraTest.cpp
File metadata and controls
executable file
·103 lines (85 loc) · 3.31 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
#include <pylon/PylonIncludes.h>
#include <pylon/ImagePersistence.h>
#include <unistd.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
// Namespace for using pylon objects.
using namespace Pylon;
// Namespace for using cout.
using namespace std;
int main(int argc, char* argv[])
{
// The exit code of the sample application.
int exitCode = 0;
// Before using any pylon methods, the pylon runtime must be initialized.
PylonInitialize();
try
{
// Get the transport layer factory.
CTlFactory& tlFactory = CTlFactory::GetInstance();
// Get all attached devices and exit application if
// two cameras aren't found
DeviceInfoList_t devices;
if ( tlFactory.EnumerateDevices(devices) != 2 )
{
cout << "Found " << devices.size() << " cameras." << endl;
throw RUNTIME_EXCEPTION( "Did not find exactly two cameras.");
}
CInstantCamera upper, lower;
upper.Attach(tlFactory.CreateDevice( devices[0] ) ); upper.Open();
lower.Attach(tlFactory.CreateDevice( devices[1] ) ); lower.Open();
CGrabResultPtr ptrGrabResult;
char filename[100]; int n;
CImageFormatConverter fc;
fc.OutputPixelFormat = PixelType_BGR8packed;
CPylonImage image;
upper.StartGrabbing(3); n=0;
usleep(1000000);
lower.StartGrabbing(3);
while ( upper.IsGrabbing() ) {
upper.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);
if ( ptrGrabResult->GrabSucceeded()) {
snprintf(filename, 100, "images/Upper%03d.png", n++);
cout << "Writing image to " << filename << endl;
// Convert to OpenCV Mat
fc.Convert(image, ptrGrabResult);
Mat cimg(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(),
CV_8UC3, (uint8_t *)image.GetBuffer());
imwrite(filename, cimg);
//CImagePersistence::Save( ImageFileFormat_Png, filename, ptrGrabResult);
} else {
cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
}
}
n=0;
while ( lower.IsGrabbing() ) {
lower.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);
if ( ptrGrabResult->GrabSucceeded()) {
snprintf(filename, 100, "images/Lower%03d.png", n++);
cout << "Writing image to " << filename << endl;
// Convert to OpenCV Mat
fc.Convert(image, ptrGrabResult);
Mat cimg(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(),
CV_8UC3, (uint8_t *)image.GetBuffer());
imwrite(filename, cimg);
//CImagePersistence::Save( ImageFileFormat_Png, filename, ptrGrabResult);
} else {
cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
}
}
upper.Close();
lower.Close();
}
catch (const GenericException &e)
{
// Error handling.
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
// Releases all pylon resources.
PylonTerminate();
return exitCode;
}