Subversion Repositories seema-scanner

Rev

Rev 17 | Rev 19 | 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
 
35
        // Get the camera information
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
 
4 jakw 64
    // Configure video mode and frame rate
18 jakw 65
    FlyCapture2::VideoMode videoMode = FlyCapture2::VIDEOMODE_640x480Y16;
66
    FlyCapture2::FrameRate frameRate = FlyCapture2::FRAMERATE_15;
4 jakw 67
    cam.SetVideoModeAndFrameRate(videoMode, frameRate);
68
 
1 jakw 69
    // Get the camera information
70
    FlyCapture2::CameraInfo camInfo;
71
    error = cam.GetCameraInfo(&camInfo);
72
    if (error != FlyCapture2::PGRERROR_OK)
73
        PrintError(error);
74
 
4 jakw 75
    std::cout << camInfo.vendorName << "  " << camInfo.modelName << "  " << camInfo.serialNumber << std::endl;
1 jakw 76
 
77
    // Set reasonable default settings
78
    CameraSettings settings;
18 jakw 79
    //settings.shutter = 8.33;
4 jakw 80
    settings.shutter = 33.33;
1 jakw 81
    settings.gain = 0.0;
82
    this->setCameraSettings(settings);
83
 
84
    // Start isochronous image transfer
85
    error = cam.StartCapture();
86
    if (error != FlyCapture2::PGRERROR_OK)
87
        PrintError(error);
88
 
89
    return;
90
}
18 jakw 91
 
92
CameraSettings CameraPointGrey::getCameraSettings(){
93
 
94
    FlyCapture2::Property property;
95
 
96
    // Get settings:
97
    CameraSettings settings;
98
 
99
    property.type = FlyCapture2::SHUTTER;
100
    cam.GetProperty(&property);
101
    settings.shutter = property.absValue;
102
 
103
    property.type = FlyCapture2::GAIN;
104
    cam.GetProperty(&property);
105
    settings.gain = property.absValue;
106
 
107
    return settings;
108
}
109
 
110
void CameraPointGrey::setCameraSettings(CameraSettings settings){
111
 
112
    FlyCapture2::Property property;
113
    property.onOff = true;
114
    property.absControl = true;
115
 
116
    property.type = FlyCapture2::SHUTTER;
117
    property.absValue = settings.shutter;
118
    cam.SetProperty(&property);
119
 
120
    property.type = FlyCapture2::GAIN;
121
    property.absValue = settings.gain;
122
    cam.SetProperty(&property);
123
 
124
}
125
 
1 jakw 126
void CameraPointGrey::startCapture(){
127
 
18 jakw 128
    FlyCapture2::Error error;\
1 jakw 129
 
18 jakw 130
    CameraSettings settings = this->getCameraSettings();
131
    std::cout << "\tShutter: " << settings.shutter << "ms" << std::endl;
132
    std::cout << "\tGain: " << settings.gain << "dB" << std::endl;
1 jakw 133
 
18 jakw 134
    if(triggerMode == triggerModeHardware){
135
        // Configure for hardware trigger
136
        FlyCapture2::TriggerMode triggerMode;
137
        triggerMode.onOff = true;
138
        triggerMode.polarity = 0;
139
        triggerMode.source = 0;
140
        triggerMode.mode = 14;
141
        error = cam.SetTriggerMode(&triggerMode);
142
        if (error != FlyCapture2::PGRERROR_OK)
143
            PrintError(error);
1 jakw 144
 
18 jakw 145
        error = cam.StartCapture();
146
        if (error != FlyCapture2::PGRERROR_OK)
147
            PrintError(error);
148
 
149
    } else if(triggerMode == triggerModeSoftware){
150
        // Configure software trigger
151
        FlyCapture2::TriggerMode triggerMode;
152
        triggerMode.onOff = true;
153
        triggerMode.polarity = 0;
154
        triggerMode.source = 7; // software
155
        triggerMode.mode = 0;
156
        error = cam.SetTriggerMode(&triggerMode);
157
        if (error != FlyCapture2::PGRERROR_OK)
158
            PrintError(error);
159
    }
160
 
1 jakw 161
    // Set the trigger timeout to 1000 ms
162
    FlyCapture2::FC2Config config;
163
    config.grabTimeout = 1000;
164
    error = cam.SetConfiguration(&config);
165
    if (error != FlyCapture2::PGRERROR_OK)
166
        PrintError(error);
167
 
168
    capturing = true;
169
}
170
 
171
void CameraPointGrey::stopCapture(){
172
 
18 jakw 173
    FlyCapture2::Error error = cam.StopCapture();
1 jakw 174
    if (error != FlyCapture2::PGRERROR_OK)
175
        PrintError(error);
176
 
18 jakw 177
    capturing = false;
1 jakw 178
}
179
 
18 jakw 180
CameraFrame CameraPointGrey::getFrame(){
1 jakw 181
 
182
    FlyCapture2::Error error;
183
 
18 jakw 184
    if(triggerMode == triggerModeSoftware){
185
        // Fire software trigger
186
        // broadcasting not supported on some platforms
187
        cam.FireSoftwareTrigger(false);
188
    }
1 jakw 189
 
190
    // Retrieve the image
191
    FlyCapture2::Image rawImage;
192
    error = cam.RetrieveBuffer(&rawImage);
193
    if (error != FlyCapture2::PGRERROR_OK)
194
        PrintError(error);
195
 
196
    CameraFrame frame;
197
 
198
    frame.timeStamp = rawImage.GetTimeStamp().cycleCount;
199
    frame.height = rawImage.GetRows();
200
    frame.width = rawImage.GetCols();
18 jakw 201
    frame.bitDepth = 16;
202
    frame.memory = (unsigned short*)rawImage.GetData();
1 jakw 203
 
204
    return frame;
205
}
206
 
207
 
208
size_t CameraPointGrey::getFrameSizeBytes(){
209
 
210
    return 0;
211
}
212
 
18 jakw 213
size_t CameraPointGrey::getFrameWidth(){
214
 
1 jakw 215
    // How do we poll this from the camera?
18 jakw 216
    return 640;
1 jakw 217
 
218
}
219
 
18 jakw 220
size_t CameraPointGrey::getFrameHeight(){
1 jakw 221
 
18 jakw 222
    // How do we poll this from the camera?
223
    return 480;
1 jakw 224
 
225
}
226
 
227
 
228
CameraPointGrey::~CameraPointGrey(){
229
 
18 jakw 230
    if(capturing && triggerMode == triggerModeHardware){
231
        // Stop camera transmission
232
        cam.StopCapture();
233
    }
1 jakw 234
 
235
    // Gracefulle destruct the camera
18 jakw 236
    cam.Disconnect();
1 jakw 237
 
238
}
239
 
240
 
241