DragonFlyCapture.cpp
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 // ****************************************************************************
00036 // Filename:  DragonFlyCapture.cpp
00037 // Author:    Pedram Azad
00038 // Date:      2004
00039 // ****************************************************************************
00040 // Changes:   13.06.2008, Miguel Bernal Marin
00041 //            * Added methods GetSerialFromCamera and SwapCameras
00042 //            * Added constructor detecting the number of cameras
00043 // ****************************************************************************
00044 
00045 
00046 // ****************************************************************************
00047 // Includes
00048 // ****************************************************************************
00049 
00050 #include "DragonFlyCapture.h"
00051 
00052 #include "Image/ByteImage.h"
00053 #include "Image/ImageProcessor.h"
00054 
00055 
00056 
00057 // ****************************************************************************
00058 // Constructors / Destructor
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 // Constructor that detects the numer of cameras
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 // Methods
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         /*if (m_nCameras == 1)
00143         {
00144                 if (m_ulSerialNumber == -1 && !ChooseCamera())
00145                         return false;
00146 
00147                 ret = ::flycaptureInitializeFromSerialNumber(m_flyCaptureContext[0], m_ulSerialNumber);
00148                 if (ret != FLYCAPTURE_OK)
00149                         return false;
00150         }*/
00151 
00152         // create a context for and initialize every camera on the bus.
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                 //ret = ::flycaptureStart(m_flyCaptureContext[i], FLYCAPTURE_VIDEOMODE_640x480Y8, FLYCAPTURE_FRAMERATE_30);
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                         // stop all cameras from grabbing and destroy their contexts.
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         // first grab
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         // then get images
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                         //ret = ::flycaptureStippledToBGR24(m_flyCaptureContext[i], m_ppInternalImages[i], m_ppOriginalImages[i]->pixels);
00245                         //if (ret != FLYCAPTURE_OK) return 0;
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                         //ret = ::flycaptureStippledToBGR24(m_flyCaptureContext[i], m_ppInternalImages[i], ppImages[i]->pixels);
00260                         //if (ret != FLYCAPTURE_OK) return false;
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 /*bool CDragonFlyCapture::ChooseCamera()
00309 {
00310         CameraGUIError guiError;
00311         CameraGUIContext m_guicontext;
00312         int nDialogStatus;
00313 
00314 
00315         guiError = ::pgrcamguiCreateContext(&m_guicontext);
00316         if (guiError != PGRCAMGUI_OK)
00317                 return false;
00318 
00319         guiError = ::pgrcamguiShowCameraSelectionModal(m_guicontext, m_flyCaptureContext, &m_ulSerialNumber, &nDialogStatus);
00320         if(guiError != PGRCAMGUI_OK)
00321                 return false;
00322 
00323         WriteCameraID();
00324 
00325         return true;
00326 }*/


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:57