Subversion Repositories seema-scanner

Rev

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

Rev 18 Rev 19
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
    //    // Configure DCAM video mode and frame rate
-
 
36
    //    FlyCapture2::VideoMode videoMode = FlyCapture2::VIDEOMODE_1280x960Y8;
-
 
37
    //    FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_7_5;
-
 
38
    //    error = cam.SetVideoModeAndFrameRate(videoMode, frameRate);
-
 
39
    //    if (error != FlyCapture2::PGRERROR_OK)
-
 
40
    //        PrintError(error);
-
 
41
 
-
 
42
        // Configure Format7 mode
-
 
43
        FlyCapture2::Format7ImageSettings format7Settings;
-
 
44
        format7Settings.mode = FlyCapture2::MODE_0;
-
 
45
        format7Settings.pixelFormat = FlyCapture2::PIXEL_FORMAT_RAW8;
-
 
46
        format7Settings.width = 1296;
-
 
47
        format7Settings.height = 964;
-
 
48
        format7Settings.offsetX = 0;
-
 
49
        format7Settings.offsetY = 0;
-
 
50
 
-
 
51
        // Validate and set mode
-
 
52
        FlyCapture2::Format7PacketInfo packetInfo;
-
 
53
        bool valid;
-
 
54
        cam.ValidateFormat7Settings(&format7Settings, &valid, &packetInfo);
-
 
55
        // packetsize indirectly configures frame rate
-
 
56
        error = cam.SetFormat7Configuration(&format7Settings, packetInfo.unitBytesPerPacket*3);
-
 
57
        if (error != FlyCapture2::PGRERROR_OK)
-
 
58
            PrintError(error);
-
 
59
 
-
 
60
        // Configure general
-
 
61
        FlyCapture2::FC2Config config;
-
 
62
        config.numBuffers = 5;
-
 
63
        config.grabTimeout = 1000; // retrieveBuffer() timeout in ms
-
 
64
        config.grabMode = FlyCapture2::DROP_FRAMES;
-
 
65
        config.isochBusSpeed = FlyCapture2::BUSSPEED_S_FASTEST;
-
 
66
        config.highPerformanceRetrieveBuffer = true;
-
 
67
        //config.asyncBusSpeed = FlyCapture2::BUSSPEED_S_FASTEST;
-
 
68
        error = cam.SetConfiguration(&config);
-
 
69
        if (error != FlyCapture2::PGRERROR_OK)
-
 
70
            PrintError(error);
-
 
71
 
35
        // Get the camera information
72
        // Get camera information
36
        FlyCapture2::CameraInfo camInfo;
73
        FlyCapture2::CameraInfo camInfo;
37
        error = cam.GetCameraInfo(&camInfo);
74
        error = cam.GetCameraInfo(&camInfo);
38
        if (error != FlyCapture2::PGRERROR_OK)
75
        if (error != FlyCapture2::PGRERROR_OK)
39
            PrintError( error );
76
            PrintError( error );
40
 
77
 
41
        CameraInfo camera;
78
        CameraInfo camera;
42
        camera.busID = camInfo.nodeNumber;
79
        camera.busID = camInfo.nodeNumber;
43
        camera.model = camInfo.modelName;
80
        camera.model = camInfo.modelName;
44
        camera.vendor = "Point Grey Research";
81
        camera.vendor = "Point Grey Research";
45
 
82
 
46
        ret.push_back(camera);
83
        ret.push_back(camera);
47
    }
84
    }
48
 
85
 
49
    return ret;
86
    return ret;
50
}
87
}
51
 
88
 
52
CameraPointGrey::CameraPointGrey(unsigned int camNum, CameraTriggerMode triggerMode) : Camera(triggerMode){
89
CameraPointGrey::CameraPointGrey(unsigned int camNum, CameraTriggerMode triggerMode) : Camera(triggerMode){
53
 
90
 
54
    FlyCapture2::Error error;
91
    FlyCapture2::Error error;
55
 
92
 
56
    // Connect to camera
93
    // Connect to camera
57
    FlyCapture2::BusManager busManager;
94
    FlyCapture2::BusManager busManager;
58
    FlyCapture2::PGRGuid camGuid;
95
    FlyCapture2::PGRGuid camGuid;
59
    busManager.GetCameraFromIndex(camNum, &camGuid);
96
    busManager.GetCameraFromIndex(camNum, &camGuid);
60
    error = cam.Connect(&camGuid);
97
    error = cam.Connect(&camGuid);
61
    if (error != FlyCapture2::PGRERROR_OK)
98
    if (error != FlyCapture2::PGRERROR_OK)
62
        PrintError(error);
99
        PrintError(error);
63
 
100
 
64
    // Configure video mode and frame rate
101
    // Configure video mode and frame rate
65
    FlyCapture2::VideoMode videoMode = FlyCapture2::VIDEOMODE_640x480Y16;
102
    FlyCapture2::VideoMode videoMode = FlyCapture2::VIDEOMODE_640x480Y16;
66
    FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_15;
103
    FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_15;
67
    cam.SetVideoModeAndFrameRate(videoMode, frameRate);
104
    cam.SetVideoModeAndFrameRate(videoMode, frameRate);
68
 
105
 
69
    // Get the camera information
106
    // Get the camera information
70
    FlyCapture2::CameraInfo camInfo;
107
    FlyCapture2::CameraInfo camInfo;
71
    error = cam.GetCameraInfo(&camInfo);
108
    error = cam.GetCameraInfo(&camInfo);
72
    if (error != FlyCapture2::PGRERROR_OK)
109
    if (error != FlyCapture2::PGRERROR_OK)
73
        PrintError(error);
110
        PrintError(error);
74
 
111
 
75
    std::cout << camInfo.vendorName << "  " << camInfo.modelName << "  " << camInfo.serialNumber << std::endl;
112
    std::cout << camInfo.vendorName << "  " << camInfo.modelName << "  " << camInfo.serialNumber << std::endl;
76
 
113
 
77
    // Set reasonable default settings
114
    // Set reasonable default settings
78
    CameraSettings settings;
115
    CameraSettings settings;
79
    //settings.shutter = 8.33;
116
    //settings.shutter = 8.33;
80
    settings.shutter = 33.33;
117
    settings.shutter = 33.33;
81
    settings.gain = 0.0;
118
    settings.gain = 0.0;
82
    this->setCameraSettings(settings);
119
    this->setCameraSettings(settings);
83
 
120
 
84
    // Start isochronous image transfer
121
    // Start isochronous image transfer
85
    error = cam.StartCapture();
122
    error = cam.StartCapture();
86
    if (error != FlyCapture2::PGRERROR_OK)
123
    if (error != FlyCapture2::PGRERROR_OK)
87
        PrintError(error);
124
        PrintError(error);
88
 
125
 
89
    return;
126
    return;
90
}
127
}
91
 
128
 
92
CameraSettings CameraPointGrey::getCameraSettings(){
129
CameraSettings CameraPointGrey::getCameraSettings(){
93
 
130
 
94
    FlyCapture2::Property property;
131
    FlyCapture2::Property property;
95
 
132
 
96
    // Get settings:
133
    // Get settings:
97
    CameraSettings settings;
134
    CameraSettings settings;
98
 
135
 
99
    property.type = FlyCapture2::SHUTTER;
136
    property.type = FlyCapture2::SHUTTER;
100
    cam.GetProperty(&property);
137
    cam.GetProperty(&property);
101
    settings.shutter = property.absValue;
138
    settings.shutter = property.absValue;
102
 
139
 
103
    property.type = FlyCapture2::GAIN;
140
    property.type = FlyCapture2::GAIN;
104
    cam.GetProperty(&property);
141
    cam.GetProperty(&property);
105
    settings.gain = property.absValue;
142
    settings.gain = property.absValue;
106
 
143
 
107
    return settings;
144
    return settings;
108
}
145
}
109
 
146
 
110
void CameraPointGrey::setCameraSettings(CameraSettings settings){
147
void CameraPointGrey::setCameraSettings(CameraSettings settings){
111
 
148
 
112
    FlyCapture2::Property property;
149
    FlyCapture2::Property property;
113
    property.onOff = true;
150
    property.onOff = true;
114
    property.absControl = true;
151
    property.absControl = true;
115
 
152
 
116
    property.type = FlyCapture2::SHUTTER;
153
    property.type = FlyCapture2::SHUTTER;
117
    property.absValue = settings.shutter;
154
    property.absValue = settings.shutter;
118
    cam.SetProperty(&property);
155
    cam.SetProperty(&property);
119
 
156
 
120
    property.type = FlyCapture2::GAIN;
157
    property.type = FlyCapture2::GAIN;
121
    property.absValue = settings.gain;
158
    property.absValue = settings.gain;
122
    cam.SetProperty(&property);
159
    cam.SetProperty(&property);
123
 
160
 
124
}
161
}
125
 
162
 
126
void CameraPointGrey::startCapture(){
163
void CameraPointGrey::startCapture(){
127
 
164
 
128
    FlyCapture2::Error error;\
165
    FlyCapture2::Error error;\
129
 
166
 
130
    CameraSettings settings = this->getCameraSettings();
167
    CameraSettings settings = this->getCameraSettings();
131
    std::cout << "\tShutter: " << settings.shutter << "ms" << std::endl;
168
    std::cout << "\tShutter: " << settings.shutter << "ms" << std::endl;
132
    std::cout << "\tGain: " << settings.gain << "dB" << std::endl;
169
    std::cout << "\tGain: " << settings.gain << "dB" << std::endl;
133
 
170
 
134
    if(triggerMode == triggerModeHardware){
171
    if(triggerMode == triggerModeHardware){
135
        // Configure for hardware trigger
172
        // Configure for hardware trigger
136
        FlyCapture2::TriggerMode triggerMode;
173
        FlyCapture2::TriggerMode triggerMode;
137
        triggerMode.onOff = true;
174
        triggerMode.onOff = true;
138
        triggerMode.polarity = 0;
175
        triggerMode.polarity = 0;
139
        triggerMode.source = 0;
176
        triggerMode.source = 0;
140
        triggerMode.mode = 14;
177
        triggerMode.mode = 14;
141
        error = cam.SetTriggerMode(&triggerMode);
178
        error = cam.SetTriggerMode(&triggerMode);
142
        if (error != FlyCapture2::PGRERROR_OK)
179
        if (error != FlyCapture2::PGRERROR_OK)
143
            PrintError(error);
180
            PrintError(error);
144
 
181
 
145
        error = cam.StartCapture();
182
        error = cam.StartCapture();
146
        if (error != FlyCapture2::PGRERROR_OK)
183
        if (error != FlyCapture2::PGRERROR_OK)
147
            PrintError(error);
184
            PrintError(error);
148
 
185
 
149
    } else if(triggerMode == triggerModeSoftware){
186
    } else if(triggerMode == triggerModeSoftware){
150
        // Configure software trigger
187
        // Configure software trigger
151
        FlyCapture2::TriggerMode triggerMode;
188
        FlyCapture2::TriggerMode triggerMode;
152
        triggerMode.onOff = true;
189
        triggerMode.onOff = true;
153
        triggerMode.polarity = 0;
190
        triggerMode.polarity = 0;
154
        triggerMode.source = 7; // software
191
        triggerMode.source = 7; // software
155
        triggerMode.mode = 0;
192
        triggerMode.mode = 0;
156
        error = cam.SetTriggerMode(&triggerMode);
193
        error = cam.SetTriggerMode(&triggerMode);
157
        if (error != FlyCapture2::PGRERROR_OK)
194
        if (error != FlyCapture2::PGRERROR_OK)
158
            PrintError(error);
195
            PrintError(error);
159
    }
196
    }
160
 
197
 
161
    // Set the trigger timeout to 1000 ms
198
    // Set the trigger timeout to 1000 ms
162
    FlyCapture2::FC2Config config;
199
    FlyCapture2::FC2Config config;
163
    config.grabTimeout = 1000;
200
    config.grabTimeout = 1000;
164
    error = cam.SetConfiguration(&config);
201
    error = cam.SetConfiguration(&config);
165
    if (error != FlyCapture2::PGRERROR_OK)
202
    if (error != FlyCapture2::PGRERROR_OK)
166
        PrintError(error);
203
        PrintError(error);
167
 
204
 
168
    capturing = true;
205
    capturing = true;
169
}
206
}
170
 
207
 
171
void CameraPointGrey::stopCapture(){
208
void CameraPointGrey::stopCapture(){
172
 
209
 
173
    FlyCapture2::Error error = cam.StopCapture();
210
    FlyCapture2::Error error = cam.StopCapture();
174
    if (error != FlyCapture2::PGRERROR_OK)
211
    if (error != FlyCapture2::PGRERROR_OK)
175
        PrintError(error);
212
        PrintError(error);
176
 
213
 
177
    capturing = false;
214
    capturing = false;
178
}
215
}
179
 
216
 
180
CameraFrame CameraPointGrey::getFrame(){
217
CameraFrame CameraPointGrey::getFrame(){
181
 
218
 
182
    FlyCapture2::Error error;
219
    FlyCapture2::Error error;
183
 
220
 
184
    if(triggerMode == triggerModeSoftware){
221
    if(triggerMode == triggerModeSoftware){
185
        // Fire software trigger
222
        // Fire software trigger
186
        // broadcasting not supported on some platforms
223
        // broadcasting not supported on some platforms
187
        cam.FireSoftwareTrigger(false);
224
        cam.FireSoftwareTrigger(false);
188
    }
225
    }
189
 
226
 
190
    // Retrieve the image
227
    // Retrieve the image
191
    FlyCapture2::Image rawImage;
228
    FlyCapture2::Image rawImage;
192
    error = cam.RetrieveBuffer(&rawImage);
229
    error = cam.RetrieveBuffer(&rawImage);
193
    if (error != FlyCapture2::PGRERROR_OK)
230
    if (error != FlyCapture2::PGRERROR_OK)
194
        PrintError(error);
231
        PrintError(error);
195
 
232
 
196
    CameraFrame frame;
233
    CameraFrame frame;
197
 
234
 
198
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
235
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
199
    frame.height = rawImage.GetRows();
236
    frame.height = rawImage.GetRows();
200
    frame.width = rawImage.GetCols();
237
    frame.width = rawImage.GetCols();
201
    frame.bitDepth = 16;
238
    frame.bitDepth = 16;
202
    frame.memory = (unsigned short*)rawImage.GetData();
239
    frame.memory = (unsigned short*)rawImage.GetData();
203
 
240
 
204
    return frame;
241
    return frame;
205
}
242
}
206
 
243
 
207
 
244
 
208
size_t CameraPointGrey::getFrameSizeBytes(){
245
size_t CameraPointGrey::getFrameSizeBytes(){
209
    
246
    
210
    return 0;
247
    return 0;
211
}
248
}
212
 
249
 
213
size_t CameraPointGrey::getFrameWidth(){
250
size_t CameraPointGrey::getFrameWidth(){
214
 
251
 
215
    // How do we poll this from the camera?
252
    // How do we poll this from the camera?
216
    return 640;
253
    return 640;
217
 
254
 
218
}
255
}
219
 
256
 
220
size_t CameraPointGrey::getFrameHeight(){
257
size_t CameraPointGrey::getFrameHeight(){
221
 
258
 
222
    // How do we poll this from the camera?
259
    // How do we poll this from the camera?
223
    return 480;
260
    return 480;
224
 
261
 
225
}
262
}
226
 
263
 
227
 
264
 
228
CameraPointGrey::~CameraPointGrey(){
265
CameraPointGrey::~CameraPointGrey(){
229
 
266
 
230
    if(capturing && triggerMode == triggerModeHardware){
267
    if(capturing && triggerMode == triggerModeHardware){
231
        // Stop camera transmission
268
        // Stop camera transmission
232
        cam.StopCapture();
269
        cam.StopCapture();
233
    }
270
    }
234
 
271
 
235
    // Gracefulle destruct the camera
272
    // Gracefulle destruct the camera
236
    cam.Disconnect();
273
    cam.Disconnect();
237
 
274
 
238
}
275
}
239
 
276
 
240
 
277
 
241
 
278
 
242
 
279