Subversion Repositories seema-scanner

Rev

Rev 4 | Rev 18 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 17
1
#include "CameraPointGrey.h"
1
#include "CameraPointGrey.h"
2
#include <cstring>
2
#include <cstring>
3
 
3
 
4
void PrintError(FlyCapture2::Error error){
4
void PrintError(FlyCapture2::Error error){
5
    error.PrintErrorTrace();
5
    error.PrintErrorTrace();
6
}
6
}
7
 
7
 
8
vector<CameraInfo> CameraPointGrey::getCameraList(){
8
vector<CameraInfo> CameraPointGrey::getCameraList(){
9
    
9
    
10
    FlyCapture2::Error error;
10
    FlyCapture2::Error error;
11
 
11
 
12
    FlyCapture2::BusManager busManager;
12
    FlyCapture2::BusManager busManager;
13
    unsigned int numCameras;
13
    unsigned int numCameras;
14
    error = busManager.GetNumOfCameras(&numCameras);
14
    error = busManager.GetNumOfCameras(&numCameras);
15
 
15
 
16
    vector<CameraInfo> ret;
16
    vector<CameraInfo> ret;
17
 
17
 
18
    if (error != FlyCapture2::PGRERROR_OK){
18
    if (error != FlyCapture2::PGRERROR_OK){
19
        PrintError(error);
19
        PrintError(error);
20
        return ret;
20
        return ret;
21
    }
21
    }
22
 
22
 
23
    for (unsigned int i=0; i < numCameras; i++){
23
    for (unsigned int i=0; i < numCameras; i++){
24
        FlyCapture2::PGRGuid guid;
24
        FlyCapture2::PGRGuid guid;
25
        error = busManager.GetCameraFromIndex(i, &guid);
25
        error = busManager.GetCameraFromIndex(i, &guid);
26
        if (error != FlyCapture2::PGRERROR_OK)
26
        if (error != FlyCapture2::PGRERROR_OK)
27
            PrintError(error);
27
            PrintError(error);
28
 
28
 
29
        // Connect to camera
29
        // Connect to camera
30
        FlyCapture2::Camera cam;
30
        FlyCapture2::Camera cam;
31
        error = cam.Connect(&guid);
31
        error = cam.Connect(&guid);
32
        if (error != FlyCapture2::PGRERROR_OK)
32
        if (error != FlyCapture2::PGRERROR_OK)
33
            PrintError( error );
33
            PrintError( error );
34
 
34
 
35
        // Get the camera information
35
        // Get the camera information
36
        FlyCapture2::CameraInfo camInfo;
36
        FlyCapture2::CameraInfo camInfo;
37
        error = cam.GetCameraInfo(&camInfo);
37
        error = cam.GetCameraInfo(&camInfo);
38
        if (error != FlyCapture2::PGRERROR_OK)
38
        if (error != FlyCapture2::PGRERROR_OK)
39
            PrintError( error );
39
            PrintError( error );
40
 
40
 
41
        CameraInfo camera;
41
        CameraInfo camera;
42
        camera.busID = camInfo.nodeNumber;
42
        camera.busID = camInfo.nodeNumber;
43
        camera.model = camInfo.modelName;
43
        camera.model = camInfo.modelName;
44
        camera.vendor = "Point Grey Research";
44
        camera.vendor = "Point Grey Research";
45
 
45
 
46
        ret.push_back(camera);
46
        ret.push_back(camera);
47
    }
47
    }
48
 
48
 
49
    return ret;
49
    return ret;
50
}
50
}
51
 
51
 
52
CameraPointGrey::CameraPointGrey(unsigned int camID){
52
CameraPointGrey::CameraPointGrey(unsigned int camID){
53
 
53
 
54
    FlyCapture2::Error error;
54
    FlyCapture2::Error error;
55
 
55
 
56
    // Connect to camera
56
    // Connect to camera
57
    FlyCapture2::BusManager busManager;
57
    FlyCapture2::BusManager busManager;
58
    FlyCapture2::PGRGuid camGuid;
58
    FlyCapture2::PGRGuid camGuid;
59
    busManager.GetCameraFromIndex(camID, &camGuid);
59
    busManager.GetCameraFromIndex(camID, &camGuid);
60
    error = cam.Connect(&camGuid);
60
    error = cam.Connect(&camGuid);
61
    if (error != FlyCapture2::PGRERROR_OK)
61
    if (error != FlyCapture2::PGRERROR_OK)
62
        PrintError(error);
62
        PrintError(error);
63
 
63
 
64
    // Configure software trigger
64
    // Configure software trigger
65
    FlyCapture2::TriggerMode triggerMode;
65
    FlyCapture2::TriggerMode triggerMode;
66
    triggerMode.onOff = true;
66
    triggerMode.onOff = true;
67
    triggerMode.polarity = 0;
67
    triggerMode.polarity = 0;
68
    triggerMode.source = 7; // software
68
    triggerMode.source = 7; // software
69
    triggerMode.mode = 0;
69
    triggerMode.mode = 0;
70
    error = cam.SetTriggerMode(&triggerMode);
70
    error = cam.SetTriggerMode(&triggerMode);
71
    if (error != FlyCapture2::PGRERROR_OK)
71
    if (error != FlyCapture2::PGRERROR_OK)
72
        PrintError(error);
72
        PrintError(error);
73
 
73
 
74
    // Configure video mode and frame rate
74
    // Configure video mode and frame rate
75
    FlyCapture2::VideoMode videoMode = FlyCapture2::VIDEOMODE_640x480Y8;
75
    FlyCapture2::VideoMode videoMode = FlyCapture2::VIDEOMODE_800x600Y8;
76
    FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_15;
76
    FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_30;
77
    cam.SetVideoModeAndFrameRate(videoMode, frameRate);
77
    cam.SetVideoModeAndFrameRate(videoMode, frameRate);
78
 
78
 
79
    // Get the camera information
79
    // Get the camera information
80
    FlyCapture2::CameraInfo camInfo;
80
    FlyCapture2::CameraInfo camInfo;
81
    error = cam.GetCameraInfo(&camInfo);
81
    error = cam.GetCameraInfo(&camInfo);
82
    if (error != FlyCapture2::PGRERROR_OK)
82
    if (error != FlyCapture2::PGRERROR_OK)
83
        PrintError(error);
83
        PrintError(error);
84
 
84
 
85
    std::cout << camInfo.vendorName << "  " << camInfo.modelName << "  " << camInfo.serialNumber << std::endl;
85
    std::cout << camInfo.vendorName << "  " << camInfo.modelName << "  " << camInfo.serialNumber << std::endl;
86
 
86
 
87
    // Set reasonable default settings
87
    // Set reasonable default settings
88
    CameraSettings settings;
88
    CameraSettings settings;
89
    settings.shutter = 33.33;
89
    settings.shutter = 33.33;
90
    settings.gain = 0.0;
90
    settings.gain = 0.0;
91
    this->setCameraSettings(settings);
91
    this->setCameraSettings(settings);
92
 
92
 
93
    settings = this->getCameraSettings();
93
    settings = this->getCameraSettings();
94
    std::cout << "\tShutter: " << settings.shutter << "ms" << std::endl;
94
    std::cout << "\tShutter: " << settings.shutter << "ms" << std::endl;
95
    std::cout << "\tGain: " << settings.gain << "dB" << std::endl;
95
    std::cout << "\tGain: " << settings.gain << "dB" << std::endl;
96
 
96
 
97
    // Start isochronous image transfer
97
    // Start isochronous image transfer
98
    error = cam.StartCapture();
98
    error = cam.StartCapture();
99
    if (error != FlyCapture2::PGRERROR_OK)
99
    if (error != FlyCapture2::PGRERROR_OK)
100
        PrintError(error);
100
        PrintError(error);
101
 
101
 
102
    return;
102
    return;
103
}
103
}
104
    
104
    
105
void CameraPointGrey::startCapture(){
105
void CameraPointGrey::startCapture(){
106
 
106
 
107
    FlyCapture2::Error error;
107
    FlyCapture2::Error error;
108
 
108
 
109
    error = cam.StopCapture();
109
    error = cam.StopCapture();
110
    if (error != FlyCapture2::PGRERROR_OK)
110
    if (error != FlyCapture2::PGRERROR_OK)
111
        PrintError(error);
111
        PrintError(error);
112
 
112
 
113
    // Configure for hardware trigger
113
    // Configure for hardware trigger
114
    FlyCapture2::TriggerMode triggerMode;
114
    FlyCapture2::TriggerMode triggerMode;
115
    triggerMode.onOff = true;
115
    triggerMode.onOff = true;
116
    triggerMode.polarity = 0;
116
    triggerMode.polarity = 0;
117
    triggerMode.source = 0;
117
    triggerMode.source = 0;
118
    triggerMode.mode = 14;
118
    triggerMode.mode = 14;
119
    error = cam.SetTriggerMode(&triggerMode);
119
    error = cam.SetTriggerMode(&triggerMode);
120
    if (error != FlyCapture2::PGRERROR_OK)
120
    if (error != FlyCapture2::PGRERROR_OK)
121
        PrintError(error);
121
        PrintError(error);
122
 
122
 
123
    // Set the trigger timeout to 1000 ms
123
    // Set the trigger timeout to 1000 ms
124
    FlyCapture2::FC2Config config;
124
    FlyCapture2::FC2Config config;
125
    config.grabTimeout = 1000;
125
    config.grabTimeout = 1000;
126
    error = cam.SetConfiguration(&config);
126
    error = cam.SetConfiguration(&config);
127
    if (error != FlyCapture2::PGRERROR_OK)
127
    if (error != FlyCapture2::PGRERROR_OK)
128
        PrintError(error);
128
        PrintError(error);
129
 
129
 
130
//    error = cam.StartCapture();
130
//    error = cam.StartCapture();
131
//    if (error != FlyCapture2::PGRERROR_OK)
131
//    if (error != FlyCapture2::PGRERROR_OK)
132
//        PrintError(error);
132
//        PrintError(error);
133
 
133
 
134
    capturing = true;
134
    capturing = true;
135
}
135
}
136
 
136
 
137
void CameraPointGrey::stopCapture(){
137
void CameraPointGrey::stopCapture(){
138
 
138
 
139
    capturing = false;
139
    capturing = false;
140
}
140
}
141
 
141
 
142
CameraFrame CameraPointGrey::lockFrame(){
142
CameraFrame CameraPointGrey::lockFrame(){
143
 
143
 
144
    FlyCapture2::Error error;
144
    FlyCapture2::Error error;
145
 
145
 
146
    // Retrieve image
146
    // Retrieve image
147
    FlyCapture2::Image rawImage;
147
    FlyCapture2::Image rawImage;
148
    error = cam.RetrieveBuffer( &rawImage );
148
    error = cam.RetrieveBuffer( &rawImage );
149
    if (error != FlyCapture2::PGRERROR_OK)
149
    if (error != FlyCapture2::PGRERROR_OK)
150
        PrintError(error);
150
        PrintError(error);
151
 
151
 
152
    CameraFrame frame;
152
    CameraFrame frame;
153
 
153
 
154
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
154
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
155
    frame.height = rawImage.GetCols();
155
    frame.height = rawImage.GetCols();
156
    frame.width = rawImage.GetRows();
156
    frame.width = rawImage.GetRows();
157
    frame.memory = rawImage.GetData();
157
    frame.memory = rawImage.GetData();
158
 
158
 
159
    return frame;
159
    return frame;
160
}
160
}
161
 
161
 
162
void CameraPointGrey::unlockFrame(){
162
void CameraPointGrey::unlockFrame(){
163
 
163
 
164
}
164
}
165
 
165
 
166
 
166
 
167
CameraFrame CameraPointGrey::getSingleFrame(){
167
CameraFrame CameraPointGrey::getSingleFrame(){
168
 
168
 
169
    FlyCapture2::Error error;
169
    FlyCapture2::Error error;
170
 
170
 
171
    // Fire software trigger
171
    // Fire software trigger
172
    // broadcasting not supported on some platforms
172
    // broadcasting not supported on some platforms
173
    cam.FireSoftwareTrigger(false);
173
    cam.FireSoftwareTrigger(false);
174
 
174
 
175
    // Retrieve the image
175
    // Retrieve the image
176
    FlyCapture2::Image rawImage;
176
    FlyCapture2::Image rawImage;
177
    error = cam.RetrieveBuffer(&rawImage);
177
    error = cam.RetrieveBuffer(&rawImage);
178
    if (error != FlyCapture2::PGRERROR_OK)
178
    if (error != FlyCapture2::PGRERROR_OK)
179
        PrintError(error);
179
        PrintError(error);
180
 
180
 
181
    CameraFrame frame;
181
    CameraFrame frame;
182
 
182
 
183
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
183
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
184
    frame.height = rawImage.GetRows();
184
    frame.height = rawImage.GetRows();
185
    frame.width = rawImage.GetCols();
185
    frame.width = rawImage.GetCols();
186
    frame.memory = rawImage.GetData();
186
    frame.memory = rawImage.GetData();
187
 
187
 
188
    return frame;
188
    return frame;
189
}
189
}
190
 
190
 
191
 
191
 
192
size_t CameraPointGrey::getFrameSizeBytes(){
192
size_t CameraPointGrey::getFrameSizeBytes(){
193
 
193
 
194
    
194
    
195
    return 0;
195
    return 0;
196
}
196
}
197
 
197
 
198
void CameraPointGrey::getFrameWidthHeight(unsigned int *width, unsigned int *height){
198
void CameraPointGrey::getFrameWidthHeight(unsigned int *width, unsigned int *height){
199
    // How do we poll this from the camera?
199
    // How do we poll this from the camera?
200
    *width = 640;
200
    *width = 640;
201
    *height = 480;
201
    *height = 480;
202
 
202
 
203
}
203
}
204
 
204
 
205
 
205
 
206
void CameraPointGrey::setCameraSettings(CameraSettings settings){
206
void CameraPointGrey::setCameraSettings(CameraSettings settings){
207
 
207
 
208
    FlyCapture2::Property property;
208
    FlyCapture2::Property property;
209
    property.onOff = true;
209
    property.onOff = true;
210
    property.absControl = true;
210
    property.absControl = true;
211
 
211
 
212
    property.type = FlyCapture2::SHUTTER;
212
    property.type = FlyCapture2::SHUTTER;
213
    property.absValue = settings.shutter;
213
    property.absValue = settings.shutter;
214
    cam.SetProperty(&property);
214
    cam.SetProperty(&property);
215
 
215
 
216
    property.type = FlyCapture2::GAIN;
216
    property.type = FlyCapture2::GAIN;
217
    property.absValue = settings.gain;
217
    property.absValue = settings.gain;
218
    cam.SetProperty(&property);
218
    cam.SetProperty(&property);
219
 
219
 
220
}
220
}
221
 
221
 
222
CameraSettings CameraPointGrey::getCameraSettings(){
222
CameraSettings CameraPointGrey::getCameraSettings(){
223
    
223
    
224
    FlyCapture2::Property property;
224
    FlyCapture2::Property property;
225
 
225
 
226
	// Get settings:
226
	// Get settings:
227
    CameraSettings settings;
227
    CameraSettings settings;
228
 
228
 
229
    property.type = FlyCapture2::SHUTTER;
229
    property.type = FlyCapture2::SHUTTER;
230
    cam.GetProperty(&property);
230
    cam.GetProperty(&property);
231
    settings.shutter = property.absValue;
231
    settings.shutter = property.absValue;
232
 
232
 
233
    property.type = FlyCapture2::GAIN;
233
    property.type = FlyCapture2::GAIN;
234
    cam.GetProperty(&property);
234
    cam.GetProperty(&property);
235
    settings.gain = property.absValue;
235
    settings.gain = property.absValue;
236
 
236
 
237
    return settings;
237
    return settings;
238
}
238
}
239
 
239
 
240
CameraPointGrey::~CameraPointGrey(){
240
CameraPointGrey::~CameraPointGrey(){
241
    std::cout << "Deleting Point Grey Camera 1" << std::endl << std::flush;
241
    std::cout << "Deleting Point Grey Camera 1" << std::endl << std::flush;
242
 
242
 
243
    // Stop camera transmission
243
    // Stop camera transmission
244
   // cam.StopCapture();
244
   // cam.StopCapture();
245
 
245
 
246
    std::cout << "Deleting Point Grey Camera 2" << std::endl << std::flush;
246
    std::cout << "Deleting Point Grey Camera 2" << std::endl << std::flush;
247
 
247
 
248
    // Gracefulle destruct the camera
248
    // Gracefulle destruct the camera
249
   // cam.Disconnect();
249
   // cam.Disconnect();
250
 
250
 
251
    std::cout << "Deleting Point Grey Camera 3" << std::endl << std::flush;
251
    std::cout << "Deleting Point Grey Camera 3" << std::endl << std::flush;
252
}
252
}
253
 
253
 
254
 
254
 
255
 
255
 
256
 
256