Subversion Repositories seema-scanner

Rev

Rev 19 | Rev 23 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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