BitmapSequenceCapture.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:  BitmapSequenceCapture.cpp
00037 // Author:    Pedram Azad
00038 // Date:      2005
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include <new> // for explicitly using correct new/delete operators on VC DSPs
00047 
00048 #include "BitmapSequenceCapture.h"
00049 #include "Image/ImageProcessor.h"
00050 #include "Image/ByteImage.h"
00051 
00052 #include <stdio.h>
00053 #include <stdlib.h>
00054 
00055 
00056 
00057 // ****************************************************************************
00058 // Constructor / Destructor
00059 // ****************************************************************************
00060 
00061 CBitmapSequenceCapture::CBitmapSequenceCapture(const char *pFirstFilePathLeft, const char *pFirstFilePathBaseRight)
00062 {
00063         m_sFilePathBaseLeft = "";
00064         m_sFilePathBaseRight = "";
00065         m_sFirstFilePathLeft = "";
00066         m_sFirstFilePathRight = "";
00067 
00068         m_sFirstFilePathLeft += pFirstFilePathLeft;
00069         m_pLeftImage = new CByteImage();
00070 
00071         if (pFirstFilePathBaseRight)
00072         {
00073                 m_sFirstFilePathRight += pFirstFilePathBaseRight;
00074                 m_pRightImage = new CByteImage();
00075                 m_bStereo = true;
00076         }
00077         else
00078         {
00079                 m_pRightImage = 0;
00080                 m_bStereo = false;
00081         }
00082 
00083         m_bOK = false;
00084         n = 0;
00085         m_nFiguresLeft = 0;
00086         m_nFiguresRight = 0;
00087 
00088         m_sFileExtention = "";
00089         nFirstImage = 0;
00090 }
00091 
00092 CBitmapSequenceCapture::~CBitmapSequenceCapture()
00093 {
00094         if (m_pLeftImage)
00095                 delete m_pLeftImage;
00096 
00097         if (m_pRightImage)
00098                 delete m_pRightImage;
00099 }
00100 
00101 
00102 // ****************************************************************************
00103 // Methods
00104 // ****************************************************************************
00105 
00106 int CBitmapSequenceCapture::GetWidth()
00107 {
00108         return m_bOK ? m_pLeftImage->width : -1;
00109 }
00110 
00111 int CBitmapSequenceCapture::GetHeight()
00112 {
00113         return m_bOK ? m_pLeftImage->height : -1;
00114 }
00115 
00116 CByteImage::ImageType CBitmapSequenceCapture::GetType()
00117 {
00118         return m_bOK ? m_pLeftImage->type : (CByteImage::ImageType) -1;
00119 }
00120 
00121 
00122 bool CBitmapSequenceCapture::OpenCamera()
00123 {
00124         m_bOK = false;
00125         m_nFiguresLeft = 0;
00126         m_nFiguresRight = 0;
00127         n = 0;
00128         nFirstImage = 0;
00129 
00130         const char *pFirstFilePathLeft = m_sFirstFilePathLeft.c_str();
00131         bool bLookForFigures = false;
00132         
00133         const int nLengthMinusOne = int(m_sFirstFilePathLeft.length()) - 1;
00134         for (int i = nLengthMinusOne; i >= 0; i--)
00135         {
00136                 if (pFirstFilePathLeft[i] == '.')
00137                 {
00138                         bLookForFigures = true;
00139                         m_sFileExtention = "";
00140                         m_sFileExtention += m_sFirstFilePathLeft.substr(i + 1, 3);
00141                 }
00142                 else if (bLookForFigures)
00143                 {
00144                         if (pFirstFilePathLeft[i] < '0' || pFirstFilePathLeft[i] > '9')
00145                         {
00146                                 m_sFilePathBaseLeft = "";
00147                                 m_sFilePathBaseLeft += pFirstFilePathLeft;
00148                                 m_sFilePathBaseLeft[i + 1] = '\0';
00149                                 n = atoi(pFirstFilePathLeft + i + 1);
00150                                 nFirstImage = n;
00151                                 break;
00152                         }
00153                         else
00154                                 m_nFiguresLeft++;
00155                 }
00156         }
00157 
00158         if (!m_pLeftImage->LoadFromFile(m_sFirstFilePathLeft.c_str()))
00159                 return false;
00160 
00161         if (m_bStereo)
00162         {
00163                 const char *pFirstFilePathRight = m_sFirstFilePathRight.c_str();
00164                 bool bLookForFigures = false;
00165 
00166                 const int nLengthMinusOne = int(m_sFirstFilePathRight.length()) - 1;
00167                 for (int i = nLengthMinusOne; i >= 0; i--)
00168                 {
00169                         if (pFirstFilePathRight[i] == '.')
00170                                 bLookForFigures = true;
00171                         else if (bLookForFigures)
00172                         {
00173                                 if (pFirstFilePathRight[i] < '0' || pFirstFilePathRight[i] > '9')
00174                                 {
00175                                         m_sFilePathBaseRight = "";
00176                                         m_sFilePathBaseRight += pFirstFilePathRight;
00177                                         m_sFilePathBaseRight[i + 1] = '\0';
00178                                         if (n != atoi(pFirstFilePathRight + i + 1))
00179                                                 return false;
00180                                         break;
00181                                 }
00182                                 else
00183                                         m_nFiguresRight++;
00184                         }
00185                 }
00186         
00187                 if (!m_pRightImage->LoadFromFile(m_sFirstFilePathRight.c_str()))
00188                         return false;
00189                         
00190                 if (m_nFiguresLeft != m_nFiguresRight || m_pLeftImage->width != m_pRightImage->width || m_pLeftImage->height != m_pRightImage->height)
00191                         return false;
00192         }
00193         
00194         m_bOK = true;
00195     
00196         return true;
00197 }
00198 
00199 void CBitmapSequenceCapture::CloseCamera()
00200 {
00201 }
00202 
00203 bool CBitmapSequenceCapture::CaptureImage(CByteImage **ppImages)
00204 {
00205         if (!m_bOK)
00206                 return false;
00207         
00208         char szTemp[100];
00209         char szTemp2[1000];
00210         
00211         sprintf(szTemp, "%%s%%.%ii.%s", m_nFiguresLeft, m_sFileExtention.c_str());
00212         sprintf(szTemp2, szTemp, m_sFilePathBaseLeft.c_str(), n);
00213 
00214         if (!m_pLeftImage->LoadFromFile(szTemp2))
00215                 return false;
00216         
00217         if (!m_pLeftImage->IsCompatible(ppImages[0]))
00218         {
00219                 printf("error: read image is not compatible in CBitmapSequenceCapture::CaptureImage\n");
00220                 return false;
00221         }
00222         
00223         ImageProcessor::CopyImage(m_pLeftImage, ppImages[0]);
00224         
00225         if (m_bStereo)
00226         {
00227                 sprintf(szTemp2, szTemp, m_sFilePathBaseRight.c_str(), n);
00228                 if (!m_pRightImage->LoadFromFile(szTemp2))
00229                         return false;
00230                 
00231                 if (!m_pRightImage->IsCompatible(ppImages[1]))
00232                 {
00233                         printf("error: read image is not compatible in CBitmapSequenceCapture::CaptureImage (right image)\n");
00234                         return false;
00235                 }
00236                 
00237                 ImageProcessor::CopyImage(m_pRightImage, ppImages[1]);
00238         }
00239         
00240         n++;
00241         
00242         return true;
00243 }
00244 
00245 void CBitmapSequenceCapture::Rewind()
00246 {
00247         n = nFirstImage;
00248 }


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