CMU1394Capture.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:  CMU1394Capture.cpp
00037 // Author:    Pedram Azad
00038 // Date:      2005
00039 // ****************************************************************************
00040 // Changes:   01.02.2006, Florian Hecht
00041 //            * Added support for multiple cameras
00042 //            14.06.2010, Kenn Sebesta
00043 //            * Added methods SetGain, SetShutter, and SetFeature
00044 // ****************************************************************************
00045 
00046 
00047 // ****************************************************************************
00048 // Includes
00049 // ****************************************************************************
00050 
00051 #include "Interfaces/VideoCaptureInterface.h"
00052 #include "Image/ByteImage.h"
00053 #include "CMU1394Capture.h"
00054 
00055 #include <windows.h>
00056 #include <1394Camera.h>
00057 
00058 #include <stdio.h>
00059 
00060 
00061 
00062 // ****************************************************************************
00063 // Constructor / Destructor
00064 // ****************************************************************************
00065 
00066 CCMU1394Capture::CCMU1394Capture(int nFormat, int nMode, int nRate, int nCameras)
00067 {
00068         m_nFormat = nFormat;
00069         m_nMode = nMode;
00070         m_nRate = nRate;
00071 
00072         width = height = -1;
00073 
00074         m_nNumberOfCameras = nCameras;
00075         m_ppCameras = NULL;
00076                 
00077         m_bOK = false;
00078 }
00079 
00080 CCMU1394Capture::~CCMU1394Capture()
00081 {
00082         CloseCamera();
00083 }
00084 
00085 
00086 // ****************************************************************************
00087 // Methods
00088 // ****************************************************************************
00089 
00090 bool CCMU1394Capture::OpenCamera()
00091 {
00092         unsigned long w,h;
00093         int i, number_of_cameras;
00094         C1394Camera *cam;
00095 
00096         CloseCamera();
00097 
00098 
00099         // create a first camera to see how many cameras we have
00100         cam = new C1394Camera();
00101 
00102         if (!cam->CheckLink())
00103         {
00104                 number_of_cameras = cam->GetNumberCameras();
00105 
00106                 if (m_nNumberOfCameras == -1 || number_of_cameras < m_nNumberOfCameras)
00107                         m_nNumberOfCameras = number_of_cameras;
00108         }
00109         else
00110         {
00111                 m_nNumberOfCameras = 0;
00112                 delete cam;
00113 
00114                 return false;
00115         }
00116 
00117         // create the rest of the cameras
00118         if (m_nNumberOfCameras != 0)
00119         {
00120                 int i;
00121 
00122                 m_ppCameras = new C1394Camera*[m_nNumberOfCameras];
00123 
00124                 m_ppCameras[0] = cam;
00125                 for (i = 1; i < m_nNumberOfCameras; i++)
00126                 {
00127                         m_ppCameras[i] = new C1394Camera();
00128                 }
00129         }
00130 
00131 
00132         // assume everything is going fine
00133         m_bOK = true;
00134 
00135         for (i = 0; i < m_nNumberOfCameras; i++)
00136         {
00137                 cam = m_ppCameras[i];
00138 
00139                 if (cam->CheckLink())
00140                 {
00141                         //printf("ERROR: camera %d CheckLink failed\n", i);
00142                         m_bOK = false;
00143                         continue;
00144                 }
00145 
00146                 // make this the i-th camera
00147                 cam->SelectCamera(i);
00148 
00149 #ifndef CMU1394_Version_645
00150                 cam->m_cameraInitialized = false;    // is private in new version
00151 #endif
00152                 cam->InitCamera();
00153 #ifndef CMU1394_Version_645
00154                 cam->InquireControlRegisters();      // method doesn't exist anymore
00155 #endif
00156                 //cam->StatusControlRegisters();
00157                 
00158                 int format = -1, mode = -1, rate = -1;
00159                 bool ok = false;
00160                 
00161                 if (m_nFormat == -1 || m_nMode == -1 || m_nRate == -1)
00162                 {
00163                         for (format = 0; format < 3; format++)
00164                         {
00165                                 for (mode = 0; mode < 8; mode++)
00166                                 {
00167                                         for (rate = 5; rate >= 0; rate--)
00168                                         {
00169 #ifdef CMU1394_Version_645
00170                                                 if (cam->HasVideoFrameRate(format, mode, rate))
00171 #else
00172                                                 if (cam->m_videoFlags[format][mode][rate])
00173 #endif
00174                                                 {
00175                                                         ok = true;
00176                                                         break;
00177                                                 }
00178                                         }
00179 
00180                                         if (ok)
00181                                                 break;
00182                                 }
00183 
00184                                 if (ok)
00185                                         break;
00186                         }
00187                 }
00188                 else
00189                 {
00190 #ifdef CMU1394_Version_645
00191                         if (cam->HasVideoFrameRate(m_nFormat, m_nMode, m_nRate))
00192 #else
00193                         if (cam->m_videoFlags[m_nFormat][m_nMode][m_nRate])
00194 #endif
00195                         {
00196                                 format = m_nFormat;
00197                                 mode = m_nMode;
00198                                 rate = m_nRate;
00199                                 ok = true;
00200                         }
00201                 }
00202                 
00203                 if (ok)
00204                 {
00205                         cam->SetVideoFormat(format);
00206                         cam->SetVideoMode(mode);
00207                         cam->SetVideoFrameRate(rate);
00208                         
00209                         if (cam->StartImageAcquisition() != CAM_SUCCESS)
00210                         {
00211                                 //printf("ERROR: couldn't start acquisition\n", format, mode, rate);
00212                                 m_bOK = false;
00213                         }
00214                         
00215 #ifdef CMU1394_Version_645
00216                         cam->GetVideoFrameDimensions(&w, &h);
00217                         width=(int)w;
00218                         height=(int)h;
00219 #else
00220                         width = cam->m_width;      // old version
00221                         height = cam->m_height;    // old version
00222 #endif
00223                 }
00224                 else
00225                 {
00226                         // could not find a valid mode
00227                         m_bOK = false;
00228                 }
00229         }
00230 
00231         return m_bOK;
00232 }
00233 
00234 int CCMU1394Capture::GetNumberOfCameras()
00235 {
00236         return m_nNumberOfCameras;
00237 }
00238 
00239 void CCMU1394Capture::CloseCamera()
00240 {
00241         int i;
00242 
00243         if (m_ppCameras != NULL)
00244         {
00245                 for (i = 0; i < m_nNumberOfCameras; i++)
00246                 {
00247                         m_ppCameras[i]->StopImageAcquisition();
00248                         delete m_ppCameras[i];
00249                 }
00250 
00251                 delete [] m_ppCameras;
00252         }
00253 
00254         m_bOK = false;
00255 }
00256 
00257 bool CCMU1394Capture::CaptureImage(CByteImage **ppImages)
00258 {
00259         if (!m_bOK)
00260                 return false;
00261         
00262         int i, num_dropped_frames = -1;
00263         bool all_ok = true;
00264         C1394Camera *cam;
00265 
00266         for (i = 0; i < m_nNumberOfCameras; i++)
00267         {
00268                 cam = m_ppCameras[i];
00269 
00270                 if (cam->AcquireImageEx(true, &num_dropped_frames) == CAM_SUCCESS)
00271                 {
00272                         cam->getRGB(ppImages[i]->pixels, height*width*3);
00273                 }
00274                 else
00275                 {
00276                         all_ok = false;
00277                 }
00278         }
00279         
00280         return all_ok;
00281 }
00282 
00283 #ifndef CMU1394_Version_645
00284 // Sets focus value in [units]. The [units] are not necessarily the same from one manufacturer to another.
00285 void CCMU1394Capture::SetFocus(int nFocus, int nCamera)
00286 {
00287         if (nCamera == -1)
00288         {
00289                 for (int i = 0; i < m_nNumberOfCameras; i++)
00290                         m_ppCameras[i]->SetFocus(nFocus);
00291         }
00292         else
00293         {
00294                 if (nCamera < 0 || nCamera >= m_nNumberOfCameras)
00295                         printf("error: parameter nCamera = %i is out of bounds (%i cameras available)\n", nCamera, m_nNumberOfCameras);
00296                 else
00297                         m_ppCameras[nCamera]->SetFocus(nFocus);
00298         }
00299 }
00300 #else
00301 // Sets gain value in [units]. The [units] are not necessarily the same from one manufacturer to another.
00302 void CCMU1394Capture::SetGain(int nGain, int nCamera)
00303 {
00304         if (nCamera == -1)
00305         {
00306                 for (int i = 0; i < m_nNumberOfCameras; i++)
00307                 {
00308                         C1394CameraControl *pFeature = m_ppCameras[i]->GetCameraControl(FEATURE_GAIN);
00309                         
00310                         if (pFeature)
00311                                 pFeature->SetValue(nGain);
00312                         else
00313                                 printf("error: feature 'gain' not available for camera %i in CCMU1394Capture::SetGain\n", i);
00314                 }
00315         }
00316         else
00317         {
00318                 if (nCamera < 0 || nCamera >= m_nNumberOfCameras)
00319                         printf("error: parameter nCamera = %i is out of bounds (%i cameras available) in CCMU1394Capture::SetGain\n", nCamera, m_nNumberOfCameras);
00320                 else
00321                 {
00322                         C1394CameraControl *pFeature = m_ppCameras[nCamera]->GetCameraControl(FEATURE_GAIN);
00323                         
00324                         if (pFeature)
00325                                 pFeature->SetValue(nGain);
00326                         else
00327                                 printf("error: feature 'gain' not available for camera %i in CCMU1394Capture::SetGain\n", nCamera);
00328                         
00329                 }
00330         }
00331 }
00332 
00333 // Sets shutter value in [units]. The [units] are not necessarily the same from one manufacturer to another.
00334 void CCMU1394Capture::SetShutter(int nShutter, int nCamera)
00335 {
00336         if (nCamera == -1)
00337         {
00338                 for (int i = 0; i < m_nNumberOfCameras; i++)
00339                 {
00340                         C1394CameraControl *pFeature = m_ppCameras[i]->GetCameraControl(FEATURE_GAIN);
00341                         
00342                         if (pFeature)
00343                                 pFeature->SetValue(nShutter);
00344                         else
00345                                 printf("error: feature 'shutter' not available for camera %i in CCMU1394Capture::SetShutter\n", i);
00346                 }
00347         }
00348         else
00349         {
00350                 if (nCamera < 0 || nCamera >= m_nNumberOfCameras)
00351                         printf("error: parameter nCamera = %i is out of bounds (%i cameras available) in CCMU1394Capture::SetShutter\n", nCamera, m_nNumberOfCameras);
00352                 else
00353                 {
00354                         C1394CameraControl *pFeature = m_ppCameras[nCamera]->GetCameraControl(FEATURE_SHUTTER);
00355                         
00356                         if (pFeature)
00357                                 pFeature->SetValue(nShutter);
00358                         else
00359                                 printf("error: feature 'shutter' not available for camera %i in CCMU1394Capture::SetShutter\n", nCamera);
00360                         
00361                 }
00362         }
00363 }
00364 
00365 // Sets arbitrary feature value in [units]. The [units] are not necessarily the same from one manufacturer to another.
00366 // This function is dangerous, as there is no error checking. ONLY TO BE USED IF YOU KNOW WHAT YOU ARE DOING.
00367 void CCMU1394Capture::SetFeature(int nFeature, int nValue, int nCamera)
00368 {
00369         if (nCamera == -1)
00370         {
00371                 for (int i = 0; i < m_nNumberOfCameras; i++)
00372                 {
00373                         C1394CameraControl *pFeature = m_ppCameras[i]->GetCameraControl((CAMERA_FEATURE) nFeature);
00374                         
00375                         if (pFeature)
00376                                 pFeature->SetValue(nValue);
00377                         else
00378                                 printf("error: feature %i not available for camera %i in CCMU1394Capture::SetFeature\n", nFeature, i);
00379                 }
00380         }
00381         else
00382         {
00383                 if (nCamera < 0 || nCamera >= m_nNumberOfCameras)
00384                         printf("error: parameter nCamera = %i is out of bounds (%i cameras available) in CCMU1394Capture::SetFeature\n", nCamera, m_nNumberOfCameras);
00385                 else
00386                 {
00387                         C1394CameraControl *pFeature = m_ppCameras[nCamera]->GetCameraControl((CAMERA_FEATURE) nFeature);
00388                         
00389                         if (pFeature)
00390                                 pFeature->SetValue(nValue);
00391                         else
00392                                 printf("error: feature %i not available for camera %i in CCMU1394Capture::SetFeature\n", nFeature, nCamera);
00393                         
00394                 }
00395         }
00396 }
00397 #endif


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