TriclopsCapture.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:  TriclopsCapture.cpp
00037 // Author:    Pedram Azad
00038 // Date:      2004
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include "TriclopsCapture.h"
00047 #include "Image/ByteImage.h"
00048 
00049 
00050 
00051 // ****************************************************************************
00052 // Constructor / Destructor
00053 // ****************************************************************************
00054 
00055 CTriclopsCapture::CTriclopsCapture(VideoMode mode) : m_mode(mode)
00056 {
00057         m_nImageWidth = -1;
00058         m_nImageHeight = -1;
00059 
00060         m_digiclopsContext = 0;
00061         m_triclopsContext = 0;
00062 }
00063 
00064 CTriclopsCapture::~CTriclopsCapture()
00065 {
00066         CloseCamera();
00067 }
00068 
00069 
00070 // ****************************************************************************
00071 // Methods
00072 // ****************************************************************************
00073 
00074 bool CTriclopsCapture::OpenCamera()
00075 {
00076         if (m_mode != e640x480 && m_mode != e320x240)
00077                 return false;
00078 
00079         digiclopsCreateContext(&m_digiclopsContext);
00080         digiclopsInitialize(m_digiclopsContext, 0);
00081 
00082         // get the camera module configuration
00083         digiclopsGetTriclopsContextFromCamera(m_digiclopsContext, &m_triclopsContext);
00084 
00085         // set the digiclops to deliver the left image and right image
00086         digiclopsSetImageTypes(m_digiclopsContext, LEFT_IMAGE | RIGHT_IMAGE);
00087 
00088         // set the Digiclops resolution
00089         switch (m_mode)
00090         {
00091                 case e640x480:
00092                         m_nImageWidth = 640;
00093                         m_nImageHeight = 480;
00094                         digiclopsSetImageResolution(m_digiclopsContext, DIGICLOPS_FULL);
00095                 break;
00096 
00097                 case e320x240:
00098                         m_nImageWidth = 320;
00099                         m_nImageHeight = 240;
00100                         digiclopsSetImageResolution(m_digiclopsContext, DIGICLOPS_HALF);
00101                 break;
00102         }
00103 
00104         //digiclopsSetCameraProperty(m_digiclopsContext, DIGICLOPS_HARDWARE_WHITEBALANCE, 117, 145, false);
00105         digiclopsSetCameraProperty(m_digiclopsContext, DIGICLOPS_WHITEBALANCE, 117, 145, false);
00106         digiclopsSetMaxFrameRate(m_digiclopsContext, DIGICLOPS_FRAMERATE_100);
00107 
00108         // start grabbing
00109         digiclopsStart(m_digiclopsContext);
00110    
00111         // set up some stereo parameters
00112         triclopsSetResolution(m_triclopsContext, m_nImageHeight, m_nImageWidth);
00113 
00114         return true;
00115 }
00116 
00117 void CTriclopsCapture::CloseCamera()
00118 {
00119         if (m_digiclopsContext)
00120         {
00121                 digiclopsDestroyContext(m_digiclopsContext);
00122                 m_digiclopsContext = 0;
00123         }
00124 
00125         if (m_triclopsContext)
00126         {
00127                 triclopsDestroyContext(m_triclopsContext);
00128                 m_triclopsContext = 0;
00129         }
00130 }
00131 
00132 bool CTriclopsCapture::CaptureImage(CByteImage **ppImages)
00133 {
00134         if (!ppImages || !ppImages[0] || !ppImages[1] ||
00135                 ppImages[0]->width != width || ppImages[0]->height != height ||
00136                 ppImages[1]->width != width || ppImages[1]->height != height ||
00137                 ppImages[0]->type != CByteImage::eRGB24 || ppImages[1]->type != CByteImage::eRGB24)
00138                 return false;
00139         
00140         // grab and extract left and right image
00141         if (digiclopsGrabImage(m_digiclopsContext) != 0)
00142                 return false;
00143 
00144         digiclopsExtractTriclopsInput(m_digiclopsContext, LEFT_IMAGE, &m_colorDataLeft);
00145         digiclopsExtractTriclopsInput(m_digiclopsContext, RIGHT_IMAGE, &m_colorDataRight);
00146 
00147         triclopsRectifyColorImage(m_triclopsContext, TriCam_LEFT, &m_colorDataLeft, &m_colorImageLeft);
00148         triclopsRectifyColorImage(m_triclopsContext, TriCam_RIGHT, &m_colorDataRight, &m_colorImageRight);
00149 
00150         ConvertImages(ppImages);
00151 
00152         return true;
00153 }
00154 
00155 void CTriclopsCapture::ConvertImages(CByteImage **ppImages)
00156 {
00157         unsigned char *pLeftData = ppImages[0]->pixels;
00158         unsigned char *pRightData = ppImages[1]->pixels;
00159         unsigned char *pLeftRed = (unsigned char *) m_colorImageLeft.red;
00160         unsigned char *pLeftGreen = (unsigned char *) m_colorImageLeft.green;
00161         unsigned char *pLeftBlue = (unsigned char *) m_colorImageLeft.blue;
00162         unsigned char *pRightRed = (unsigned char *) m_colorImageRight.red;
00163         unsigned char *pRightGreen = (unsigned char *) m_colorImageRight.green;
00164         unsigned char *pRightBlue = (unsigned char *) m_colorImageRight.blue;
00165         
00166         #ifdef __linux
00167         int offset = 0;
00168         #else
00169         int offset = 3 * (m_nImageWidth * m_nImageHeight - m_nImageWidth);
00170         #endif
00171 
00172         for (int y = 0; y < m_nImageHeight; y++)
00173         {
00174                 for (int x = 0; x < m_nImageWidth; x++, offset += 3)
00175                 {
00176                         pLeftData[offset] = pLeftRed[x];
00177                         pLeftData[offset + 1] = pLeftGreen[x];
00178                         pLeftData[offset + 2] = pLeftBlue[x];
00179                         pRightData[offset] = pRightRed[x];
00180                         pRightData[offset + 1] = pRightGreen[x];
00181                         pRightData[offset + 2] = pRightBlue[x];
00182                 }
00183                 
00184                 pLeftRed += m_colorImageLeft.rowinc;
00185                 pLeftGreen += m_colorImageLeft.rowinc;
00186                 pLeftBlue += m_colorImageLeft.rowinc;
00187 
00188                 pRightRed += m_colorImageLeft.rowinc;
00189                 pRightGreen += m_colorImageLeft.rowinc;
00190                 pRightBlue += m_colorImageLeft.rowinc;
00191 
00192                 #ifndef __linux
00193                 offset -= 6 * m_nImageWidth;
00194                 #endif
00195         }
00196 }


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:58