00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include "DragonFlyCapture.h"
00051
00052 #include "Image/ByteImage.h"
00053 #include "Image/ImageProcessor.h"
00054
00055
00056
00057
00058
00059
00060
00061 CDragonFlyCapture::CDragonFlyCapture(int nCameras, VideoMode mode, ColorMode colorMode, ImageProcessor::BayerPatternType bayerPatternType) :
00062 m_nCameras(nCameras), m_mode(mode), m_colorMode(colorMode), m_bayerPatternType(bayerPatternType)
00063 {
00064 width = -1;
00065 height = -1;
00066
00067 for (int i = 0; i < DRAGONFLY_MAX_CAMERAS; i++)
00068 {
00069 m_ppImages[i] = 0;
00070 m_ppOriginalImages[i] = 0;
00071 m_ppInternalImages[i] = 0;
00072
00073 m_flyCaptureContext[i] = 0;
00074 }
00075 }
00076
00077
00078 CDragonFlyCapture::CDragonFlyCapture(VideoMode mode, ColorMode colorMode, ImageProcessor::BayerPatternType bayerPatternType)
00079 : m_mode(mode), m_colorMode(colorMode), m_bayerPatternType(bayerPatternType)
00080 {
00081 width = -1;
00082 height = -1;
00083
00084 unsigned int nCameras = DRAGONFLY_MAX_CAMERAS;
00085
00086 FlyCaptureError ret = ::flycaptureBusCameraCount(&nCameras);
00087 if (ret != FLYCAPTURE_OK)
00088 m_nCameras = 0;
00089
00090 m_nCameras = (int) nCameras;
00091
00092 for (int i = 0; i < DRAGONFLY_MAX_CAMERAS; i++)
00093 {
00094 m_ppImages[i] = 0;
00095 m_ppOriginalImages[i] = 0;
00096 m_ppInternalImages[i] = 0;
00097 m_flyCaptureContext[i] = 0;
00098 }
00099 }
00100
00101 CDragonFlyCapture::~CDragonFlyCapture()
00102 {
00103 CloseCamera();
00104 }
00105
00106
00107
00108
00109
00110
00111 CByteImage::ImageType CDragonFlyCapture::GetType()
00112 {
00113 return m_colorMode == eGrayScale ? CByteImage::eGrayScale : CByteImage::eRGB24;
00114 }
00115
00116 bool CDragonFlyCapture::OpenCamera()
00117 {
00118 if (m_nCameras <= 0)
00119 return false;
00120
00121 CloseCamera();
00122
00123 switch (m_mode)
00124 {
00125 case e320x240:
00126 width = 320;
00127 height = 240;
00128 break;
00129
00130 case e640x480:
00131 width = 640;
00132 height = 480;
00133 break;
00134
00135 default:
00136 return false;
00137 }
00138
00139
00140 FlyCaptureError ret;
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 for (int i = 0; i < m_nCameras; i++)
00154 {
00155 ret = ::flycaptureCreateContext(&m_flyCaptureContext[i]);
00156 if (ret != FLYCAPTURE_OK)
00157 return false;
00158
00159 ret = ::flycaptureInitialize(m_flyCaptureContext[i], i);
00160 if (ret != FLYCAPTURE_OK)
00161 return false;
00162
00163
00164 if (m_colorMode == eGrayScale)
00165 ret = ::flycaptureStartCustomImage(m_flyCaptureContext[i], 0, 4, 4, 640, 480, 100.0, FLYCAPTURE_MONO8);
00166 else
00167 ret = ::flycaptureStartCustomImage(m_flyCaptureContext[i], 0, 4, 4, 640, 480, 100.0, FLYCAPTURE_RAW8);
00168
00169 if (ret != FLYCAPTURE_OK)
00170 return false;
00171
00172 m_ppInternalImages[i] = new FlyCaptureImage();
00173
00174 if (m_colorMode == eRGB24)
00175 m_ppImages[i] = new CByteImage(width, height, CByteImage::eRGB24);
00176 else
00177 m_ppImages[i] = new CByteImage(width, height, CByteImage::eGrayScale);
00178
00179 if (m_mode == e320x240)
00180 m_ppOriginalImages[i] = new CByteImage(640, 480, CByteImage::eRGB24);
00181 }
00182
00183 return true;
00184 }
00185
00186 void CDragonFlyCapture::CloseCamera()
00187 {
00188 for (int i = 0; i < m_nCameras; i++)
00189 {
00190 if (m_flyCaptureContext[i])
00191 {
00192
00193 ::flycaptureStop(m_flyCaptureContext[i]);
00194 ::flycaptureDestroyContext(m_flyCaptureContext[i]);
00195 m_flyCaptureContext[i] = 0;
00196 }
00197
00198 if (m_ppImages[i])
00199 {
00200 delete m_ppImages[i];
00201 m_ppImages[i] = 0;
00202 }
00203
00204 if (m_ppInternalImages[i])
00205 {
00206 delete m_ppInternalImages[i];
00207 m_ppInternalImages[i] = 0;
00208 }
00209
00210 if (m_ppOriginalImages[i])
00211 {
00212 delete m_ppOriginalImages[i];
00213 m_ppOriginalImages[i] = 0;
00214 }
00215 }
00216 }
00217
00218 bool CDragonFlyCapture::CaptureImage(CByteImage **ppImages)
00219 {
00220 int i;
00221
00222 FlyCaptureError ret;
00223
00224 if (!m_flyCaptureContext)
00225 return false;
00226
00227
00228 for (i = 0; i < m_nCameras; i++)
00229 {
00230 ret = ::flycaptureGrabImage2(m_flyCaptureContext[i], m_ppInternalImages[i]);
00231 if (ret != FLYCAPTURE_OK)
00232 return false;
00233 }
00234
00235 CByteImage image_header(640, 480, CByteImage::eGrayScale, true);
00236
00237
00238 for (i = 0; i < m_nCameras; i++)
00239 {
00240 image_header.pixels = m_ppInternalImages[i]->pData;
00241
00242 if (m_mode == e320x240)
00243 {
00244
00245
00246
00247 if (m_colorMode == eGrayScale)
00248 {
00249 ImageProcessor::Resize(&image_header, ppImages[i]);
00250 }
00251 else
00252 {
00253 ImageProcessor::ConvertBayerPattern(&image_header, m_ppOriginalImages[i], m_bayerPatternType);
00254 ImageProcessor::Resize(m_ppOriginalImages[i], ppImages[i]);
00255 }
00256 }
00257 else if (m_mode == e640x480)
00258 {
00259
00260
00261
00262 if (m_colorMode == eGrayScale)
00263 {
00264 ImageProcessor::CopyImage(&image_header, ppImages[i]);
00265 }
00266 else
00267 {
00268 ImageProcessor::ConvertBayerPattern(&image_header, ppImages[i], m_bayerPatternType);
00269 }
00270 }
00271 }
00272
00273 m_sec = m_ppInternalImages[0]->timeStamp.ulSeconds;
00274 m_usec = m_ppInternalImages[0]->timeStamp.ulMicroSeconds;
00275
00276 return true;
00277 }
00278
00279
00280 void CDragonFlyCapture::GetCurrentTimestamp(unsigned int &sec, unsigned int &usec)
00281 {
00282 sec = m_sec;
00283 usec = m_usec;
00284 }
00285
00286 unsigned int CDragonFlyCapture::GetSerialFromCamera(int nCamera)
00287 {
00288 if (m_flyCaptureContext[nCamera])
00289 {
00290 if (::flycaptureGetCameraInfo(m_flyCaptureContext[nCamera], &m_flyCaptureInfoEx) == FLYCAPTURE_OK)
00291 return m_flyCaptureInfoEx.SerialNumber;
00292 }
00293
00294 return 0;
00295 }
00296
00297 void CDragonFlyCapture::SwapCameras(int nCamera1, int nCamera2)
00298 {
00299 if (m_flyCaptureContext[nCamera1] && m_flyCaptureContext[nCamera2])
00300 {
00301 FlyCaptureContext fCC_tmp = m_flyCaptureContext[nCamera1];
00302 m_flyCaptureContext[nCamera1] = m_flyCaptureContext[nCamera2];
00303 m_flyCaptureContext[nCamera2] = fCC_tmp;
00304 }
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326